External CSS
An external .css file linked from each page lets one edit restyle a whole site, and the browser caches it for later pages.
Reuse one stylesheet across pages and follow the link that loads it.
Harbour Café's site now has a home page, a menu page, a contact page and the festival page, and the owner wants the same fonts and colours everywhere. The answer is one stylesheet file that every page links to.
The rule
One file, linked from every page, changed once.
An external stylesheet is a plain text file ending in .css that holds only CSS rules, with no <style> tags and no HTML:
/* styles.css */
body {
font-family: Georgia, serif;
}
.price {
color: green;
}Each page connects to it with a link element in its head:
<head>
<title>Harbour Café</title>
<link rel="stylesheet" href="styles.css">
</head>rel="stylesheet"tells the browser what the linked file is for.hrefis the file's address. A relative path such asstyles.cssis looked up relative to the page's own location.
Why this is the default choice:
- One edit restyles the whole site.
- Caching: the browser downloads
styles.cssonce and reuses it on every page, so later pages load faster. - Clean HTML: pages hold content and meaning; the look lives in its own file.
A page can link several stylesheets, for example a shared base.css and a page-specific festival.css. They are read in the order the link elements appear.