External Stylesheets

The last and most commonly used way to write CSS code is by writing styles in a separate CSS file. This is advantageous for clarity and also allows you to use the same styles in multiple HTML files by referencing the same CSS file.

To let our HTML document know that we want to use a separate style file, we need to link it using the link element as follows:

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

Then, we can write code in the CSS file we linked to in the same way as we wrote in internal styles:

p {
	background-color: purple;
	text-align: right;
}

Instructions

Delete the style element along with its content from the head element.

Now, add a link element inside the head element that references the style.css file.

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

4/5

External Stylesheets | Start Coder