External CSS
~10 mins
External Stylesheet
- An external CSS stylesheet can be applied to any number of HTML documents by placing a
<link>element in each
HTML document.
<link rel="stylesheet" type="text/css" href="style.css">
- The attribute rel of the
<link>tag has to be set to "stylesheet" - The
hrefattribute to the relative or absolute path to the stylesheet. - While using relative URL paths is generally considered good practice, absolute paths can be used, too.
- In HTML5 the
typeattribute can be omitted.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>
style.css
h1 {
color: green;
}
- Reference: CSSNotesForProfessionals.pdf - Section 1.1