Thuta Learning
CSS
BasicWeb DevelopmentBeginner

CSS HOME

CSSLesson 120 min

What you'll walk away with

  • Separate the jobs of HTML (content and meaning) and CSS (presentation)
  • Explain why headings are big and bold even on a page with no CSS: the browser's default stylesheet
  • Write an HTML file with a <style> block and open it in a browser
  • Find an element's final value in the DevTools Styles and Computed panes
  • Know the course's five chapters and the shape of every lesson

Explain it simply

Explain it simply

HTML says what is on a page: this is a heading, this is a paragraph, this is a button. CSS (Cascading Style Sheets) says how those things look: colours, fonts, spacing, sizes and where each piece sits on the screen. If a page were a house, HTML would be the walls and rooms, and CSS would be the paint, the furniture layout and the lighting.

You write CSS as rules. A rule says "select these elements and make them look like this". For example, h1 { color: navy; } turns every top-level heading navy. Change one rule and every element it selects changes at once.

Problem → Why → Solution

The problem: looks mixed into the HTML have to be fixed on every page

Old websites and some beginner projects write colours and fonts directly inside the HTML tags. It seems fine for the first five pages. Then the client says "make the headings green instead of blue", and you have to hunt down every heading on every page. Miss one and the site ends up with two heading colours.

Tags such as <font> and <center> have also been removed from the HTML standard (they are obsolete), so new code should not use them.

about.html
<!-- the look is repeated inside the content, on every page -->
<h1><font color="blue" face="Arial">About us</font></h1>
<center>
  <p><font size="2">We sell handmade notebooks.</font></p>
</center>
<!-- contact.html, shop.html, faq.html... all repeat color="blue" -->

Why does this happen?

Content (what you want to say) and presentation (how to show it) are mixed in one place. CSS separates them: the HTML just says h1, and one rule in a stylesheet decides how every h1 on the whole site looks. Changing the colour becomes a one-line edit.

Core concept: how the browser combines HTML and CSS

When you open a page, the browser reads the HTML and builds a tree of elements (the DOM): html contains body, body contains h1 and p, and so on. It then reads the CSS rules and checks which elements in that tree each rule's selector matches. For every matched element it settles the final value of each property (color, font-size, margin...), and only then does it place the boxes (layout) and draw them on the screen (paint).

Even a page with no CSS at all is styled. Every browser ships a default stylesheet (the user-agent stylesheet), which is why an h1 is 32px and bold and why paragraphs have space between them. The rules you write are layered on top of those defaults.

That is what "cascading" refers to: many rules can touch the same element, and the browser uses precise rules to pick a winning value for each property. You will learn those rules (specificity and source order) in detail in the Selectors lesson.

LanguageJobExample
HTMLContent and meaning<h1>About us</h1>
CSSPresentation and layouth1 { color: navy; }
JavaScriptBehaviourOpen a menu on click

To see what the browser decided, right-click an element and choose Inspect (or press F12). The Styles pane lists every rule that matches that element and shows losing declarations with a line through them; the Computed pane shows the final value of each property. These two panes are the best CSS teacher you will ever have. You can also click a value in the Styles pane and edit it live; the page updates instantly, but the edit disappears on refresh, so copy the value you like back into your file.

Mental model: from HTML tree to pixels
  1. HTML builds the element tree
  2. Selectors pick elements from the tree
  3. Declarations set property values
  4. The browser lays out and paints

Your rules sit on top of the browser's default stylesheet; you never start from a blank slate.

General pattern: one CSS rule

styles.css
selector {
  property: value;
  another-property: value;
}

The selector chooses which elements to style, and each declaration inside the curly braces { } says what to change and how, in the form property: value;. You will meet this one shape throughout the whole course.

Example: your first styled page

Save this as first-page.html and double-click the file to open it in a browser; no server or install is needed. Then temporarily delete the <style> block and compare with the browser's default look to see how much three rules change.

first-page.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>My first styled page</title>
  <style>
    body {
      font-family: system-ui, sans-serif;
      max-width: 40rem;
      margin: 2rem auto;
      padding: 0 1rem;
      line-height: 1.6;
      color: #1f2937;
      background-color: #f9fafb;
    }
    h1 {
      color: #1d4ed8;
    }
    .note {
      padding: 1rem;
      border-left: 4px solid #1d4ed8;
      background-color: #e0e7ff;
    }
  </style>
</head>
<body>
  <h1>Learning CSS</h1>
  <p>HTML gave this page its content. CSS is giving it a look.</p>
  <p class="note">Change one value in the style block and refresh.</p>
</body>
</html>

Code breakdown

  1. <style> block<style>

    The <style> element inside <head> holds the CSS rules for this page. It keeps a first experiment to a single file; the How To Add CSS lesson compares all three ways of adding CSS.

  2. body rulemax-width: 40rem;

    Very long lines are hard to read on a wide screen. max-width stops the body from growing past 40rem, and margin: 2rem auto; splits the leftover space equally on both sides, which centres the column.

  3. Inherited text stylesfont-family: system-ui, sans-serif;

    Font and colour are set only on body, yet the h1 and paragraphs inherit them, so you do not repeat the font on every element. system-ui uses your operating system's interface font, with sans-serif as the fallback.

  4. h1 rulecolor: #1d4ed8;

    The heading's own rule replaces the grey it would inherit from body with blue. The h1's 32px size and bold weight come from the browser's default stylesheet; you did not write them.

  5. Class selector.note {

    A selector starting with a dot (.) selects only elements with class="note". That is why the first paragraph stays plain while the second one gets the background, border and padding.

You should see
The text appears in a sans-serif font, in a centred column at most 40rem (640px) wide. Text is dark grey (#1f2937) on a very light grey background (#f9fafb), and the heading is blue (#1d4ed8). The "note" paragraph has a pale indigo background, a 4px blue border on its left and 16px of padding all round.

How this course is organised

ChapterLessonsWhat you learn
Basic9What CSS is, syntax, adding CSS, selectors, colours, backgrounds, text, fonts
Intermediate7Box model, border, padding, margin, display, position, z-index
Advanced12Flexbox, Grid, pseudo-classes and elements, variables, transitions, animations, responsive design, media queries
Projects3Common mistakes, a mini project, a final summary
Exercises2Selector and box model practice, a grid, position and responsive challenge

Every lesson follows the same order: a plain-language explanation, a real problem, the concept, an example you open in a browser, common mistakes, a mini challenge and three quiz questions. Type each example yourself and change one value at a time. Predict what will change before you refresh, then check your guess in DevTools.

In real projects

Where this shows up in real projects

Every website and web app uses CSS, from an online shop's product cards to a banking app's forms to the code blocks on this tutorial site. Companies define colours, fonts and spacing once, as a design system in their stylesheets, and hundreds of pages share it. When the brand colour changes, they edit the stylesheet and leave the HTML files alone.

Even when a team uses a framework such as Tailwind CSS or Bootstrap, or writes styles inside React components, the browser still ends up reading plain CSS. So the cascade, box model, Flexbox and Grid you learn here stay useful whatever tool you pick later. Front-end developers open DevTools every day to answer questions like "why is this button so wide?" by inspecting the element.

Common mistakes

Common mistakes

1. Choosing HTML tags for their looks

Using <h1> because you want big text, or stacking <br><br> for space, tells screen-reader users and search engines the wrong structure. Pick the tag that matches the meaning, then change size and spacing with CSS.

2. Forgetting to save and refresh, or opening the wrong file

If you edit CSS and nothing changes, first check that you saved the file and that the browser shows the same file you are editing (look at the address bar). The browser may also be holding an old cached stylesheet, so try a hard refresh with Ctrl+Shift+R (Cmd+Shift+R on a Mac).

3. Guessing instead of inspecting

When a style does not work, inspecting the element is faster than changing values at random. If the rule is missing from the Styles pane, its selector does not match the element; if it is crossed out, another rule is winning.

Best practices

Best practices

  • Keep one folder for the course and one HTML file per lesson, such as 05-selectors.html.
  • Start every HTML file with <!DOCTYPE html>; without it the browser renders in quirks mode and some CSS behaves strangely.
  • Write CSS in an editor such as VS Code: property auto-complete and error highlighting catch many typos.

Mini challenge

Mini challenge: your own profile card

Without changing the HTML in the starter file, write rules in the <style> block that turn three plain lines of text into something that looks like a profile card.

  • Give body a sans-serif font, a text colour and a background colour
  • Limit the content of .card to 20rem wide and give it padding, a border and a white background
  • Give the h2 inside the card a colour different from the body text
  • Make the .role paragraph smaller and grey (a grey that is still readable on white)
profile.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Profile card</title>
  <style>
    /* TODO: body - font-family, color, background-color */

    /* TODO: .card - max-width, padding, border, background-color */

    /* TODO: .card h2 - a colour of its own */

    /* TODO: .role - smaller font-size, readable grey colour */
  </style>
</head>
<body>
  <div class="card">
    <h2>Aye Aye</h2>
    <p class="role">Front-end learner</p>
    <p>Learning CSS one lesson a day.</p>
  </div>
</body>
</html>

Expected: A white card sits on a light grey background; its text area is at most 20rem (320px) wide, and the Box Model lesson explains why padding and border are added outside that. The name has its own colour, and "Front-end learner" is smaller and grey compared with the rest of the text.

Show hint

To select only the h2 inside the card, write .card h2 with a space. On white, a grey such as #6b7280 stays readable, while something as pale as #aaaaaa is hard to read.

Show solution
profile.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Profile card</title>
  <style>
    body {
      font-family: system-ui, sans-serif;
      color: #1f2937;
      background-color: #f3f4f6;
    }
    .card {
      max-width: 20rem;
      padding: 1.5rem;
      border: 1px solid #d1d5db;
      border-radius: 8px;
      background-color: white;
    }
    .card h2 {
      margin-top: 0;
      color: #1d4ed8;
    }
    .role {
      font-size: 0.875rem;
      color: #6b7280;
    }
  </style>
</head>
<body>
  <div class="card">
    <h2>Aye Aye</h2>
    <p class="role">Front-end learner</p>
    <p>Learning CSS one lesson a day.</p>
  </div>
</body>
</html>

Quick quiz 1 / 3

A page has no CSS at all, yet its <h1> is large and bold. Why?

Quick quiz 2 / 3

You want every button on the site to have rounded corners. What is the best approach?

Quick quiz 3 / 3

Where in DevTools do you most directly see the final colour value the browser used for an element after all rules competed?

What to remember

  • HTML describes content and meaning; CSS describes presentation and layout.
  • A CSS rule is a selector plus { property: value; } declarations.
  • The browser layers your rules over its default stylesheet and picks one winning value per property.
  • The DevTools Styles and Computed panes show why a style does or does not apply.
  • The course has 33 lessons in five chapters: Basic, Intermediate, Advanced, Projects and Exercises.

CSS Snapshot 2025 — W3C

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

CSS HOME | Thuta Learning