How to add CSS to HTML elements | how to use external CSS file in HTML

You can add CSS to HTML elements with three methods: Inline, Internal, and External.

how to add css to html

use inline style in HTML elements

we can apply a CSS style directly in the HTML elements, the benefit of this method is it allows us to put all the code both HTML and CSS in one file, but this method make the code less readable especially if you work with other web developers.

Example :

With this method, we add the style directly within the HTML tags by using the style attribute.

using internal CSS style in HTML

by using the internal CSS style sheet, we can only apply the styles for one single HTML page.

Example :

how to use external css in html

with this method, we can change the look of all the HTML pages, and we need to change just one single external CSS file.

to apply an external CSS style sheet, put the external link within the HEAD section.

Example :