How to add CSS

How to add CSS

When a browser reads a style sheet, it will format the HTML document according to the information in the style sheet.

Three Ways to Insert CSS

1. Inline CSS

2. Internal CSS

3. External CSS

1.) Inline CSS

Inline CSS is used to apply CSS on a single line or element.


<p style="color:blue">Hello CSS</p>

2.) Internal CSS

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



3.) External CSS

External CSS is used to apply CSS on multiple pages or all pages. Here, we write all the CSS code in a css file. Its extension must be .css for example style.css.



You need to link this style.css file to your html pages like this:

<link rel="stylesheet" type="text/css" href="style.css">

Note: The link tag must be used inside head section of html.