edubun
English
1 / 12

1 / 9 · Basic

What CSS does

One CSS file can restyle every page of a site at once. That was the main argument for CSS when the W3C, the group that sets web standards, published CSS level 1 in December 1996.

Jump to the 10 practice questions

You will learn

  • Know what happens to a declaration the browser does not understand

1Explore

Structure in HTML, looks in CSS

HTML says what each part of a page is: a heading, a list, a form. CSS, short for Cascading Style Sheets, says how those parts should look: their colours, fonts, sizes, spacing and position on the screen. Here is a small example. In HTML, <h1>Corner Bakery</h1> says this is the main heading. A CSS rule saying that h1 should be blue changes how that heading looks, and the HTML stays the same.

The HTML below the style element never changes; only the two rules do.

Tap a choice: the code and the preview change together.

h1 colour
p size
<style>
  h1 { color: black; }
  p { font-size: 14px; }
</style>
<h1>Corner Bakery</h1>
<p>Fresh bread every morning.</p>
Preview

2Explain

The shape of a rule

A stylesheet is a list of rules. Each rule starts with a selector, which says which elements it applies to, followed by a declaration block in curly braces. Inside the block, each declaration is a property, a colon, a value and a semicolon. In the rule above, h1 selects every level one heading, and the two declarations make those headings blue and set their font size to 32 pixels.

1 selector, 2 property, 3 value, 4 declaration block. Each property: value pair is one declaration and ends with a semicolon.

3Problem

What color is

In p { color: red; }, what is color?

Hint

It comes before the colon.

Solution

Answer: a property

The word before the colon names the feature being set, so color is the property. The selector p chooses elements, while red supplies the value.

4Problem

The end of a declaration

What ends each declaration?

Hint

Look at what separates color: red from the next declaration.

Solution

Answer: A semicolon

A missing semicolon merges two declarations into one invalid one.

5Explain

One mistake skips one declaration

When the browser meets a declaration it does not understand, such as a misspelled property or a value that makes no sense, it skips that one declaration and carries on with the next. This is deliberate: it lets new CSS features be added without breaking older browsers. The flip side is that a single missing semicolon can silently swallow the declaration that follows it, because the two run together into one invalid declaration.

Fix the spelling of font-sise and watch the text grow.

Your code
<style>
  p { color: green; font-sise: 30px; background: #fff4d6; }
</style>
<p>The misspelled property is skipped; the others still apply.</p>
Preview

6Problem

A declaration the browser does not know

The browser meets a declaration it does not understand. What happens?

Hint

The rest of the rule is not thrown away.

Solution

Answer: It skips that declaration and continues

Skipping unknown declarations lets new features coexist with old browsers.

7Explain

Three ways to add CSS

An external stylesheet, linked from the <head> with <link rel="stylesheet">, is the usual choice for a real site: every page shares it, and the browser downloads it once and keeps it in its cache. A <style> element holds rules for one page, which is what the exercises in this course use. The style attribute applies declarations to a single element; it is handy for a quick test but hard to maintain, because the same look has to be repeated on every element.

<!-- 1. External stylesheet: one file for the whole site -->
<link rel="stylesheet" href="styles.css">

<!-- 2. Internal stylesheet: rules for this page only -->
<style>
  p { line-height: 1.5; }
</style>

<!-- 3. Inline style: one element only -->
<p style="color: green;">Fresh today</p>

The link and style elements normally go in the head.

8Problem

Blue links without CSS

Even a page with no CSS has some style: headings are big and bold, links are blue and underlined, lists are indented. These come from the browser's default stylesheet, called the user agent stylesheet. Your rules are applied on top of it. That is why the bakery page from the HTML course was readable before it had any CSS, and why a good stylesheet changes only what it needs to.

Why are links blue on a page with no CSS?

Hint

Some styles come with the browser.

Solution

Answer: The browser default stylesheet

The browser applies its user agent stylesheet even when the author supplies no CSS. Those default rules give links their familiar colour and underline.

9Practice

Your first two rules

Write two rules: make the h1 colour #1a5fb4, and make every p 18px in size.

Checks
  • h1 colour
  • p font size
Your code
<style>
  /* write your rules here */
</style>

<h1>Corner Bakery</h1>
<p>Fresh bread every morning from 7 am.</p>
Preview
Hint

Two rules, each with one declaration: h1 { color: … } and p { font-size: … }.

A solution
<style>
  h1 { color: #1a5fb4; }
  p { font-size: 18px; }
</style>

<h1>Corner Bakery</h1>
<p>Fresh bread every morning from 7 am.</p>

10Practice

Find the missing character

This rule does nothing because of one missing character. Fix it so the paragraph is green and 20px.

Checks
  • green text
  • 20px
Your code
<style>
  p { color: green font-size: 20px; }
</style>

<p>This text should be green and 20 pixels.</p>
Preview
Hint

Every declaration ends with a semicolon.

A solution
<style>
  p { color: green; font-size: 20px; }
</style>

<p>This text should be green and 20 pixels.</p>

11Explain

Common mistakes

Mistake
<style>
  p { color: green font-size: 20px; }
</style>
<p>Fresh bread</p>
Fixed
<style>
  p { color: green; font-size: 20px; }
</style>
<p>Fresh bread</p>

Without the semicolon the browser reads one long, invalid value for color and skips both declarations.

12

Summary

  • HTML gives structure; CSS gives looks.
  • Rule = selector { property: value; }.
  • External stylesheet for a site, style element for a page, style attribute for one element.
  • Unknown declarations are skipped, so check semicolons when a style does not apply.

Next unitSelectors and the cascade
Full text · The whole lesson as one text

Structure in HTML, looks in CSS

HTML says what each part of a page is: a heading, a list, a form. CSS, short for Cascading Style Sheets, says how those parts should look: their colours, fonts, sizes, spacing and position on the screen. Here is a small example. In HTML, <h1>Corner Bakery</h1> says this is the main heading. A CSS rule saying that h1 should be blue changes how that heading looks, and the HTML stays the same. A stylesheet is a file of such rules.

Keeping the two apart has practical benefits. You can change the look of a whole site by editing one stylesheet. The same HTML can look different on a phone, a large monitor and on paper. Readers can apply their own styles, such as larger text, without breaking the page.

The shape of a rule

1 selector, 2 property, 3 value, 4 declaration block. Each property: value pair is one declaration and ends with a semicolon.

A stylesheet is a list of rules. Each rule starts with a selector, which says which elements it applies to, followed by a declaration block in curly braces. Inside the block, each declaration is a property, a colon, a value and a semicolon. In the rule above, h1 selects every level one heading, and the two declarations make those headings blue and set their font size to 32 pixels. The full height of a heading also depends on its font and line spacing. Spaces and line breaks inside a rule do not matter, so most people put each declaration on its own line to keep it readable.

When the browser meets a declaration it does not understand, such as a misspelled property or a value that makes no sense, it skips that one declaration and carries on with the next. This is deliberate: it lets new CSS features be added without breaking older browsers. The flip side is that a single missing semicolon can silently swallow the declaration that follows it, because the two run together into one invalid declaration. If a style does not apply, check the punctuation first. Comments are written /* like this */.

Three ways to add CSS

<!-- 1. External stylesheet: one file for the whole site -->
<link rel="stylesheet" href="styles.css">

<!-- 2. Internal stylesheet: rules for this page only -->
<style>
  p { line-height: 1.5; }
</style>

<!-- 3. Inline style: one element only -->
<p style="color: green;">Fresh today</p>
The link and style elements normally go in the head.

An external stylesheet, linked from the <head> with <link rel="stylesheet">, is the usual choice for a real site: every page shares it, and the browser downloads it once and keeps it in its cache. A <style> element holds rules for one page, which is what the exercises in this course use. The style attribute applies declarations to a single element; it is handy for a quick test but hard to maintain, because the same look has to be repeated on every element.

The browser already has styles

Even a page with no CSS has some style: headings are big and bold, links are blue and underlined, lists are indented. These come from the browser's default stylesheet, called the user agent stylesheet. Your rules are applied on top of it. That is why the bakery page from the HTML course was readable before it had any CSS, and why a good stylesheet changes only what it needs to.

A little history

Håkon Wium Lie started work on CSS at CERN in October 1994, and Bert Bos joined the work in 1995. The W3C, the group that sets web standards, published CSS level 1 as a Recommendation on 17 December 1996. CSS 2 followed in May 1998. Since then CSS has been split into modules, such as Color, Selectors, Flexbox and Grid, each developed at its own pace by the W3C CSS Working Group. There is no single CSS4. The working group publishes a snapshot that lists which modules are stable.

Key points
  • HTML gives structure; CSS gives looks.
  • Rule = selector { property: value; }.
  • External stylesheet for a site, style element for a page, style attribute for one element.
  • Unknown declarations are skipped, so check semicolons when a style does not apply.

Practice questions from What CSS does on edubun

Embed this quiz

Free to embed. Please keep the credit line.

Sources for this course (5)
  • W3C CSS Working Group specifications: CSS Snapshot 2025, Selectors Level 4, CSS Cascading and Inheritance Level 5, CSS Color Level 4, CSS Values and Units Level 4, CSS Box Model Level 3, CSS Box Sizing Level 3, CSS Fonts Level 4, CSS Flexible Box Layout Level 1, CSS Grid Layout Level 2, Media Queries Level 4 and Level 5 (w3.org/TR/, checked 2026-10-17)
  • MDN Web Docs, Learn web development: CSS styling basics and CSS layout, and the CSS reference (developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics, .../Core/CSS_layout, developer.mozilla.org/en-US/docs/Web/CSS, checked 2026-10-17)
  • W3C, CSS history and CSS1 Recommendation of 17 December 1996 (w3.org/Style/CSS20/history.html, w3.org/press-releases/1996/css1-rec, checked 2026-10-17)
  • W3C WCAG 2.2, success criteria 1.4.3 Contrast (Minimum)
  • 1.4.8 Visual Presentation, 1.4.10 Reflow, 1.4.12 Text Spacing (w3.org/TR/WCAG22/, checked 2026-10-17).

Checked: 2026-10-17