Explain it simply
Explain it simply
CSS does not give the browser step-by-step drawing instructions. You simply describe the result you want: paragraphs should be red, the heading should be 32px. The browser does the rest of the work, such as which pixels to colour and where each line of text should wrap.
The workflow is "select, then style": first you pick elements with a selector, then you set their look with properties and values. The HTML itself does not change; the page's content and meaning stay the same and only its appearance moves.
Problem → Why → Solution
The problem: picking tags for their looks breaks the page's meaning
Before they know CSS, beginners often pick whichever tag looks right. They use <h1> because they want a big promotion line, make a <div> that looks like a button, and stack <br> tags for space. For a mouse user the page seems fine.
But a screen-reader user who opens the list of headings hears "Free shipping" as the page title. A keyboard user pressing Tab can never reach "Buy now", because a <div> cannot receive focus.
<!-- tags chosen for their look, not their meaning -->
<h1>Free shipping on orders over $50</h1> <!-- not the page title -->
<div class="btn" onclick="buy()">Buy now</div> <!-- no keyboard access -->
<br><br><br> <!-- used only for spacing -->Why does this happen?
A tag states meaning, not appearance, and browsers, screen readers and search engines trust that meaning. Because CSS can make any element look any way you like, you never need to pick a tag for its look: choose the tag that is semantically right (<p>, <button>) and hand the appearance over to CSS.
Core concept: declarative rules, inheritance and modules
CSS is a declarative language: you describe the result and leave the method to the browser. Writing p { color: #b91c1c; } involves no loop and no searching or counting of paragraphs. Even a paragraph that appears later is styled automatically, because the rule describes "anything that is a paragraph", not "the paragraphs that exist right now".
Some properties are inherited from parent to child. Text-related properties (color, font-family, line-height) inherit, so setting them once on body styles the text of the whole page. Box-related properties (border, padding, background-color) do not inherit; otherwise a border on body would appear around every element. A rule that targets the child itself always beats a value it would inherit. When you are unsure whether a property inherits, look it up on MDN: every property page has an "Inherited: yes" or "Inherited: no" line in its formal definition, and DevTools shows inherited values under an "Inherited from body" heading.
CSS has no single version number. After CSS level 1 (1996) and CSS 2 (1998), the specification was split into modules such as Selectors, Color, Flexbox and Grid, and each module advances at its own pace with its own level. "CSS3" is just a name for that modular era, not a release, and there is no official "CSS4". So instead of asking about a version number, check whether browsers support a feature in MDN's compatibility table.
A browser skips any declaration it does not understand, without an error. That behaviour lets you write fallbacks: first a value every browser knows, then the modern one. A modern browser uses the later line and an older browser keeps the first one (progressive enhancement).
- HTML states what content means
- CSS rules describe the desired look
- The browser merges defaults and rules
- Children inherit text styles
To change the look, edit CSS; change a tag only when the meaning changes.
General pattern: a rule with a fallback
selector {
property: safe-value; /* every browser understands this */
property: modern-value; /* newer browsers use this instead */
}When the same property appears twice, the browser uses the last line it understands. A browser that does not know the modern value skips that line and keeps the safe value.
Example: two rules and inheritance
This page has only two rules, one for body and one for p. Before opening it, predict: what colour is the h1, and what colour and font does the word "winter" inside strong get?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Shop news</title>
<style>
/* select body, then style it */
body {
color: #374151;
font-family: Georgia, serif;
}
/* select every p, then style it */
p {
color: #b91c1c;
font-size: 18px;
}
</style>
</head>
<body>
<h1>Shop news</h1>
<p>Free shipping on orders over $50.</p>
<p>The new <strong>winter</strong> collection is in.</p>
</body>
</html>Code breakdown
- body rule
font-family: Georgia, serif;font-family is an inherited property. It is written once on body, yet the h1, the paragraphs and strong all get Georgia; a machine without Georgia falls back to some serif font.
- Inherited colour
color: #374151;No rule sets a colour on the h1 itself, so it inherits this dark grey from body. The browser's default stylesheet gives h1 its size and boldness, but not a colour.
- p selector
p {The type selector p selects every <p> element on the page, whether there are two or a hundred. That is what declarative means here: you never point at the paragraphs one by one.
- Own rule beats inheritance
color: #b91c1c;The paragraphs could inherit grey from body, but a rule that selects them directly wins, so they are red. strong then inherits that red from its paragraph.
Both paragraphs are 18px, dark red (#b91c1c) and in Georgia. "winter" inherits the paragraph's red, 18px and Georgia, and is bold from the browser default. The h1 inherits body's dark grey (#374151) and Georgia, and keeps the browser's default 32px bold size.Writing a real fallback
oklch() is a modern colour function that describes colour closer to how human eyes perceive it. Current major browsers support it, but older ones may not, so write a hex value first. A browser that does not understand the second line skips it and keeps the hex blue. The order matters: if the oklch() line came first, the hex line after it would always win in every browser, and the modern colour would never be used.
.banner {
background-color: #1e3a8a; /* understood everywhere */
background-color: oklch(38% 0.15 265); /* used where supported */
color: white;
}In real projects
Where this shows up in real projects
Because HTML and CSS are separate, teams can restyle an entire site without touching its content. Dark mode is the best example: the same HTML shows a light and a dark theme just by switching rules in the stylesheet. News sites also show the same article HTML through a separate print stylesheet that hides ads and menus.
Keeping HTML semantic also matters legally and commercially. Many countries require government and large-company websites to meet accessibility standards such as WCAG, and real buttons and headings help search engines understand a page too. In code reviews, "this should be a <button>" is a more common comment than "make this prettier".
The fallback habit also pays off on sites with many visitors on older phones, such as banking or government services. In a browser that lacks a modern feature, the page should look slightly plainer, never broken.
Common mistakes
Common mistakes
1. Styling a <div> to look like a button
CSS can make a <div> look like a button, but it cannot give it keyboard focus, activation with Enter or Space, or the "button" role a screen reader announces. Use <button> and restyle its default look with CSS.
2. Expecting box properties to inherit
After seeing color on body reach every element, learners expect padding or border on a container to reach its children too. Those properties do not inherit; select the element that needs them directly.
3. Judging support by "CSS3" labels
Old articles call things "CSS3 properties", but that label says nothing about browser support. Check each feature in MDN's Browser compatibility table and add a fallback value when you need one.
Best practices
Best practices
- Write each new page without CSS first; if it reads well unstyled, the HTML structure is sound.
- Set text styles (font-family, color, line-height) once on body and override only the elements that should differ.
- Whenever you use a modern value, check MDN for support and put a plain fallback on the line before it if needed.
- Tab through the page with only a keyboard; every clickable thing should be reachable.
Mini challenge
Mini challenge: create hierarchy without touching the HTML
The article HTML in the starter is already semantic. Without changing a single tag, write rules in the <style> block so the headline, the date and the body text are clearly different.
- Set font-family, color and line-height once on body and rely on inheritance
- Make the h2 larger than body text, with its own colour
- Make the <time> element smaller and grey (still readable on white)
- Give links (a) their own colour, but keep the underline
<!-- TODO: wrap this in the usual <!DOCTYPE html>, <head> and <body> -->
<style>
/* TODO: body - font-family, color, line-height (inherited by everything) */
/* TODO: h2 - bigger size and its own colour */
/* TODO: time - smaller and a readable grey */
/* TODO: a - its own colour, underline kept */
</style>
<!-- do not change anything below this line -->
<article>
<h2>Rainy season gardening</h2>
<time datetime="2026-06-01">1 June 2026</time>
<p>Raised beds drain faster. <a href="#tips">Read the tips</a>.</p>
</article>Expected: All text takes the body's font and colour; the headline is large and blue, the date small and grey, and the link dark green with its underline.
Show hint
You can select <time> with the type selector time. If you leave text-decoration alone on links, the browser's default underline stays.
Show solution
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Article</title>
<style>
body {
font-family: system-ui, sans-serif;
color: #1f2937;
line-height: 1.6;
}
h2 {
font-size: 2rem;
color: #1d4ed8;
}
time {
font-size: 0.875rem;
color: #6b7280;
}
a {
color: #166534;
}
</style>
</head>
<body>
<article>
<h2>Rainy season gardening</h2>
<time datetime="2026-06-01">1 June 2026</time>
<p>Raised beds drain faster. <a href="#tips">Read the tips</a>.</p>
</article>
</body>
</html>Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- CSS is declarative: you describe the result and the browser does the drawing.
- "Select, then style": pick elements with a selector, then set their look with property: value.
- Text properties such as color and font inherit; box properties such as border and padding do not.
- Choose HTML tags for meaning and change their looks with CSS.
- CSS evolves in modules, so check feature support on MDN and write fallbacks.
CSS Snapshot 2025 — W3C