+ 3

How to use css and JavaScript in html together

how can i together css js in html code Anyone explain me.?

7th Aug 2017, 2:23 PM
Rakesh@RH
Rakesh@RH - avatar
4 Respuestas
+ 1
Usually they are embedded in the HTML head tag. but you can even embed it in HTML tags as: [HTML code] <html> <head> <title>CSS AND JS</title> <style> <!---your CSS code goes here--> body{background : #eeeeee;} </style> <script> <!--javascript code goes here-> </script> </head> <body> <p style="color:green"> <!-- I don't recommend this inline CSS --> Green text. example of inline CSS.</p> <!--using js in body. this is better for js--> <button onclick="alert('hi')">Click me</button> <h1>This code can be copied and pasted directly into the code editor</h1> </body> </html>
7th Aug 2017, 2:45 PM
Core i9
Core i9 - avatar
+ 4
CSS and JS can both be embedded / linked to your HTML. As for me explaining you, I'd say you're learning and decided to ask before you decided to just read. Read through HTML, JS, and CSS, and it'll make perfect sense how they work together.
7th Aug 2017, 2:29 PM
AgentSmith
7th Aug 2017, 2:33 PM
Manual
Manual - avatar
+ 4
Since it's being mentioned, it's horrible practice to directly dump your styling and scripts into your HTML file. Will it work? Yes. However, it's sloppy and takes away from the readability. Not even to mention how much more difficult it is to search around all of your code instead of being able to change it in its centralized spot. As well, limits how easily you can use modular code between your projects when it isn't in its own file. Also, make sure you aren't calling your JS scripts prior to the page elements even loading. EXAMPLE: <head> <link rel="stylesheet" type="text/css" href="Styles/myStyles.css"> </head> <script src="Scripts/myScript.js"></script>
7th Aug 2017, 2:53 PM
AgentSmith