DEV Community

Cover image for How To Link HTML CSS And JavaScript?
Edward Marciniak
Edward Marciniak

Posted on

How To Link HTML CSS And JavaScript?

HTML is the framework of a website, which is then enhanced with CSS and JavaScript.

CSS styles HTML with color, formatting, and layout design.

JavaScript adds interactivity to a website.

HTML, CSS, and JavaScript must be linked together in order to work together.

To link an HTML file to a CSS file and a JavaScript file use the following code:

Image of HTML Boilerplate with CSS and JavaScript links.

In this code, assuming you have a file called 'style.css', the link element with a rel attribute of "stylesheet" tells the browser that the linked document is a stylesheet and provides the means to apply the styles defined in the stylesheet to a web page. The script element with a src attribute specifies the location of a script file that should be loaded and executed by the browser.

You can also include the CSS and JavaScript code directly in the HTML file using style and script elements, respectively, instead of linking to external files.

Image of HTML Boilerplate with Comments of where to insert HTML, CSS and JavaScript content.

Top comments (2)

Collapse
 
prsaya profile image
Prasad Saya

Yes, you can also specify CSS for a HTML element using the style attribute. For example, <h1 style="color: red">Hello</h1>.

Collapse
 
edkmarciniak profile image
Edward Marciniak

Thank you Prasad.