Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
CSS Basics  ›  Lesson

Internal CSS

Internal CSS 12 minA style element in the head holds full CSS rules that style every matching element on that one page only.

Internal CSS

The café is putting up a one-off page for its monsoon festival. It has its own look and will never be reused. Instead of creating a separate file, you can keep the CSS on the page itself, in a style element.

The rule

A style element styles one whole page, from one place.

Internal CSS sits inside a <style> element in the page's <head>. Its contents are ordinary CSS rules, not HTML attributes:

<head>
  <title>Monsoon Festival — Harbour Café</title>
  <style>
    h1 {
      color: teal;
    }
    .price {
      color: green;
      font-weight: bold;
    }
  </style>
</head>

Compared with inline CSS, this is a big step up. One rule for .price now styles every price on the page, and you can use every kind of selector and media query. The looks are gathered in one block instead of scattered through the tags.

Its limit is the page boundary. A style element affects only the document it is in. If the café's five pages each carry the same block, they are five separate copies, and a new brand colour means five edits.

There is also a small cost in download: the CSS travels inside every page, so a browser cannot keep one copy and reuse it the way it can with a separate file.

The shortcut

Ask "How many pages need this?" Exactly one page → internal is fine. More than one → it belongs in an external file (next lesson).

Styling the festival pageStep 1 of 4
  1. Count the pages

    The festival page is a single page with its own colours. One page.

A common slip is putting HTML inside the style element, such as <p style="...">. The browser reads the contents as CSS, so HTML there is just broken CSS.

Drills

Answer fast — trust the rule.

quick drill

Where should the style element normally go?

quick drill

The festival page has twelve prices and one internal rule .price { color: green; }. How many prices turn green?

quick drill

The café's five pages each contain an identical style block. The brand colour changes. How many places must you edit?

quick drill

What does the browser expect between <style> and </style>?

Remember

  • A style element in the head styles one whole page with full CSS rules.
  • Ask "how many pages?": one is fine, more means an external file.
  • Trap: copying the same block into several pages.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainOne page or many?

Explain when a style element is a good home for CSS and when it is not, using the café's festival page and its other pages as examples.