Skip to the workspace
Pebellslearn by building
CSS Basics  ›  Lesson

External CSS

External CSS 12 minAn external .css file linked from each page lets one edit restyle a whole site, and the browser caches it for later pages.

css / External CSS

Explore each scene at your own pace.

01 · The rule

The rule

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.
  • href is the file's address. A relative path such as styles.css is 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.css once 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.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.