JavaScript Tutorial

How to add CSS

CSS can be added to HTML pages to format the document according to the information in the style sheet. There are three ways to insert CSS into HTML documents.

Inline CSS

This type of style is used to apply unique style rules to an element by putting the CSS rules directly into the tag attribute. It can be attached to an element using the style attribute.

The style attribute includes a series of CSS properties and value pairs. Each "property: value" pair is separated by a semicolon (;), just as we would write into an embedded or external style sheet. However, it needs to be on a single line with no line breaks after the semicolon, as shown here:

Internal CSS

This type of style is used to apply CSS to a single document or page. It can affect all elements of the page. It is written inside the style tag within the head section of the HTML document.

 

External CSS

This type of style is used to apply CSS to multiple pages or all pages. Here, we write all the CSS code in a separate CSS file with a .css extension.

Index.html:-

 

Go back to Previous Course