Log inSign up free
Mastering Modern CSS: From Zero to Pro
  1. Getting started

    1. CSS Lesson 1: What Is CSS?
    2. CSS Lesson 2: Selectors and Rules
    3. CSS Lesson 3: How CSS Works: The Cascade
    4. CSS Lesson 4: Colour and Backgrounds
    5. CSS Lesson 5: Typography and Text
    6. CSS Lesson 6: The Box Model
    7. CSS Lesson 7: Units and Sizing
    8. CSS Lesson 8: Display and Positioning
    9. CSS Lesson 9: Flexbox
    10. CSS Lesson 10: Grid
    11. CSS Lesson 11: Responsive Design
    12. CSS Lesson 12: Final Project
Mastering Modern CSS: From Zero to Pro

Getting started · Lesson 1 of 12 · 7 min read · By Jack

CSS Lesson 1: What Is CSS?

CSS stands for Cascading Style Sheets. In the HTML course, you built pages with headings, lists, tables and forms. Without CSS, they look plain: black text on white, in Times-style type, stacked from top to bottom.

Downloads for this lesson

Sign up free (or log in) to download these files.

Estimated time: 15 minutes reading, plus about 25 minutes of practice.

Downloads :

  • css_lesson1_cheat_sheet.pdf is a 2–3 page summary of the lesson: rule anatomy, the three methods, common properties and a troubleshooting table.
  • css_lesson1_glossary.csv has 19 terms with category, definition and example. You can import it into flashcard apps or a spreadsheet.
  • css_lesson1_practice_tracker.csv is a checklist of the lesson's tasks. Open it in Excel or Google Sheets and tick off each one.

Learning goals: By the end, you'll be able to:

  • explain what CSS is and why it's separate from HTML
  • read and write a CSS rule
  • add CSS in three ways and know which one to use
  • link an external stylesheet
  • use comments and browser DevTools to test and debug styles

Part 1: What is CSS? (3 min)

CSS stands for Cascading Style Sheets. In the HTML course, you built pages with headings, lists, tables and forms. Without CSS, they look plain: black text on white, in Times-style type, stacked from top to bottom. That's the browser's default styling.

CSS lets you change that. It controls:

  • colour and backgrounds
  • fonts and text
  • spacing and borders
  • layout (where things sit on the page)
  • responsiveness (how pages adapt to phones and tablets)

Why is it separate from HTML?

HTMLCSS
What the content isHow the content looks
<h1>, <p>, <ul>color, font-size, margin
One structureMany possible designs

Separation brings real benefits:

  • One change, whole site. Edit one CSS file and every page updates.
  • Cleaner HTML. Your markup stays readable.
  • Different looks, same content. The same HTML can look completely different on a phone, a desktop or in print.

Think of a house again. HTML is the walls and rooms. CSS is the paint, furniture and curtains. You can redecorate without rebuilding.

What does "cascading" mean?
Several rules can target the same element, and the browser must choose between them. "Cascade" is the system that decides who wins. Lesson 3 covers it in depth. For now, remember that later rules usually override earlier ones when they conflict.


Part 2: Three ways to add CSS (4 min)

Method 1: Inline CSS

Written inside an element's style attribute.

<p style="color: red; font-size: 20px;">This text is red.</p>
  • It only affects that one element.
  • It's quick for tests, but messy and hard to maintain.
  • It's also hard to override later.

Method 2: Internal CSS

Written in a <style> element in the <head>.

<!DOCTYPE html>  
<html lang="en">  
<head>  
  <meta charset="UTF-8">  
  <title>Internal CSS</title>  
  <style>  
    h1 {  
      color: darkgreen;  
    }  
    p {  
      font-size: 18px;  
    }  
  </style>  
</head>  
<body>  
  <h1>Hello</h1>  
  <p>This page is styled with internal CSS.</p>  
</body>  
</html>
  • It affects the whole page.
  • It's fine for a single-page demo, but it can't be shared between pages.

Method 3: External CSS (best practice)

Written in a separate .css file and linked from the HTML.

index.html

<!DOCTYPE html>  
<html lang="en">  
<head>  
  <meta charset="UTF-8">  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">  
  <title>External CSS</title>  
  <link rel="stylesheet" href="styles.css">  
</head>  
<body>  
  <h1>Hello</h1>  
  <p>This page is styled with an external stylesheet.</p>  
</body>  
</html>

styles.css

h1 {  
  color: darkgreen;  
}  
  
p {  
  font-size: 18px;  
}

Notes on the <link> element:

  • rel="stylesheet" says what kind of file it is.
  • href is the path to the file, using the same path rules as links and images.
  • It belongs in <head>.
  • Don't put <style> tags inside the .css file. It holds CSS only.

Which should you use?

MethodReusable?Easy to maintain?Use it for
InlineNoNoQuick tests
InternalOne pageMediumSingle-page demos
ExternalYes, many pagesYesReal websites

From here on, we'll use external CSS.


Part 3: Anatomy of a CSS rule (4 min)

p {  
  color: darkblue;  
  font-size: 18px;  
}
PartExampleMeaning
SelectorpWhich elements to style
Declaration block{ ... }Everything inside the braces
Declarationcolor: darkblue;One property and value pair
PropertycolorWhat to change
ValuedarkblueWhat to change it to

Syntax rules to remember:

  • A colon : separates property and value.
  • A semicolon ; ends each declaration.
  • Curly braces { } wrap the declarations.
  • CSS ignores extra spaces and line breaks, but indent two spaces for readability.

Styling several elements
Separate selectors with commas to apply one rule to all of them.

h1, h2, h3 {  
  color: navy;  
}

Your first useful properties

body {  
  font-family: Arial, sans-serif;  
  background-color: #f9fafb;  
  color: #1f2937;  
}  
  
h1 {  
  text-align: center;  
  color: #1d4ed8;  
}  
  
p {  
  font-size: 18px;  
}  
  
img {  
  border: 2px solid black;  
}
PropertyWhat it doesExample values
colorText colourred, #ff0000, rgb(255,0,0)
background-colorBackground colourlightyellow, #eef
font-familyTypefaceArial, sans-serif
font-sizeText size16px, 1.2rem
text-alignHorizontal alignmentleft, center, right
borderBorder (width, style, colour)2px solid black

We'll cover colour in Lesson 4, typography in Lesson 5 and sizing units in Lesson 6. For now, just try values and see what happens.

Inheritance: a small preview
Some properties pass from parent to child. If you set color on body, headings and paragraphs inside it inherit that colour unless you override it. That's why the body rule above changes the whole page.

Comments

/* Page-wide styles */  
body {  
  font-family: Arial, sans-serif;  
}  
  
/* Heading styles  
h1 {  
  color: navy;  
}

Comments use /* ... */ and can span several lines. The second comment above is missing its closing */, which would break the rule below it.


Part 4: Common mistakes and how to spot them (2 min)

MistakeExampleEffect
Missing semicoloncolor: red then font-size: 20px;The next line may stop working
Using = instead of :color = red;Declaration ignored
Misspelt propertycolour: red;Ignored (CSS uses US spelling, color)
Missing closing bracep { color: red;Later rules break
Wrong href pathhref="style.css" when the file is styles.cssNo styles load
<link> in <body>Placed far down the pageWorks inconsistently and may flash unstyled content
Forgetting pxfont-size: 18;Ignored (units are needed except for 0)

CSS is forgiving. When something is wrong, it ignores the broken line and carries on, so mistakes can be silent.


Part 5: Debugging with browser DevTools (2 min)

Every browser has built-in tools to inspect and edit CSS live.

  1. Right-click any element and choose Inspect.
  2. The Elements panel shows the HTML, and the Styles panel shows the CSS rules that apply.
  3. Untick a declaration to switch it off temporarily.
  4. Click a value and type a new one to test changes instantly.
  5. A struck-through declaration means it was overridden or invalid.

Changes in DevTools are temporary. Refresh and they're gone, so copy good changes into your .css file.


Key takeaways

  • CSS controls appearance, while HTML controls structure.
  • A rule is a selector plus declarations, each a property: value; pair.
  • There are three ways to add CSS. Use external stylesheets for real sites.
  • Link the stylesheet in <head> with <link rel="stylesheet" href="...">.
  • CSS silently ignores mistakes, so check spelling, colons, semicolons and braces first.
  • DevTools lets you test and debug styles live.

Exercises (25 min)

1. Identify (2 min). In this rule, name the selector, property and value.

h2 {  
  color: tomato;  
}

Answer: selector h2, property color, value tomato.

2. Fix the errors (5 min).

p {  
  color = blue  
  font-size: 18  
}  
  
h1  
  text-align: center;  
}  
  
body {  
  background-colour: lightgrey;  
}

Hints: replace = with :, add semicolons, add px to the size, add the missing { after h1, and use background-color.

3. Build it: three methods (8 min).

  1. Create a folder called css-course with index.html (use the standard skeleton from the HTML course).
  2. Add a heading and two paragraphs.
  3. Style one paragraph with inline CSS.
  4. Add an internal <style> block that styles the <h1>.
  5. Create styles.css, link it and move all styles into it. Delete the inline and internal versions.

4. Mini project: a styled profile (8 min). Using your index.html, add an <h1> with your name, a short intro paragraph, a list of three hobbies and an image. In styles.css:

  • set a font-family and background-color on body
  • centre the <h1> and give it a colour
  • set a font-size for paragraphs
  • add a border to the image
  • add a comment above each rule

5. Challenge (2 min). Open your page, right-click the heading, choose Inspect and change its colour in the Styles panel. Then untick text-align to see it switch off. Refresh the page to see everything reset.


Lesson 1 checkpoint

  • I can explain what CSS does and why it's separate from HTML.
  • I can name the parts of a CSS rule.
  • I know the three ways to add CSS and why external is best.
  • I can link a stylesheet from <head>.
  • I can find and fix simple syntax errors.
  • I can inspect an element with DevTools.

Keep track of your learning

This lesson comes with 3 downloads. Create a free account to unlock them and track your progress.

  • Track your progress through every course
  • Take the quizzes and see your score
  • Download the worksheets and resources
  • Get a certificate when you finish

Related reading on our blog

Rather have it done for you?

We build websites for small businesses

Everything in this course is what we do every day for local businesses: fast, mobile-friendly sites that are built to be found on Google. See our web design services or our website packages.