How To Insert CSS

There are three ways of inserting a style sheet on a web page

External Style Sheet

An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file.
Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the head section:

<html>
<head>
<link rel="stylesheet" type="text/css" href="example.css" />
</head>
<body>
<p>This is paragraph text</p>
<hr />
</body>
</html>

Click to see output

An external style sheet can be written in any text editor, and file should be saved with a .css extension.

hr {color:green}
p {margin-left:10px}

Internal Style Sheet

An internal style sheet is used when a single document has a unique style. You define internal styles in the head section of an HTML page, by using the <style> tag, like this:

<html>
<head>
<style type="text/css">
hr {color:green}
p {margin-left:20px}
</style>
</head>
<body>
<p>This is paragraph text</p>
<hr />
</body>
</html>

Click to see output

Note: There should be no white space between colon(:) and unit [Example- margin-left:  20px is bad practice.]

Inline Styles

An inline style loses many of the advantages of style sheets by mixing content with presentation.

<p style="color:green;margin-left:20px">This is a paragraph with left margin 20px.</p>
<p style="color:green;margin-left:10px">This is a paragraph with left margin 10px.</p>
<p style="color:green;margin-left:5px">This is a paragraph with left margin 5px.</p>

Click to see output