CSS stands for Cascading Style Sheets. It's the language that controls how web pages look. HTML builds the structure, such as headings, paragraphs and buttons, and CSS decides their colours, sizes, fonts, spacing and position on the screen.
The same HTML with different CSS can look like a completely different website. That's what makes CSS so powerful: you can redesign a site without touching its content, and every page that uses the stylesheet updates at once.
In this lesson you'll see what CSS code looks like, why it's kept separate from HTML, and what the word "cascading" actually means.
What CSS code looks like
h1 {
color: purple;
font-size: 40px;
}In plain English: "Find every h1 and make its text purple and 40 pixels tall."
h1is the selector: which elements to style.colorandfont-sizeare properties: what to change.purpleand40pxare values: what to change it to.
Together, a selector and its block of properties form a rule. A stylesheet is simply a list of rules. You'll look at every part in detail in CSS Syntax.
Why CSS is a separate language
In the early days of the web, styling was written straight into HTML with tags like <font color="red">. Every page repeated the same styling, and changing the design meant editing hundreds of files by hand.
CSS separates content (HTML) from presentation (CSS). One stylesheet can style a thousand pages. Change the brand colour once, and the whole site updates. The separation also keeps HTML clean and meaningful, which helps screen readers and search engines.
What "cascading" means
Several rules can target the same element. The cascade is the set of rules the browser follows to decide which one wins. Usually the more specific rule wins, and when two rules are equally specific, the one written later wins. You'll learn the details in Specificity & the Cascade.
Some properties are also inherited. If you set a font on the <body>, every paragraph and heading inside it uses that font unless another rule says otherwise. That's why a few lines of CSS can change the feel of a whole page.
What you can do with CSS
CSS covers far more than colours and fonts. With it you can:
- control spacing around and inside every element
- build page layouts with columns, rows and grids
- adapt a design to phones, tablets and large screens
- add hover effects, transitions and animations
- support dark mode and print-friendly versions of a page
This course covers each of these step by step, starting with the basics.
CSS Syntax
A CSS rule
selector {
property: value;
}CSS Summary
- CSS stands for Cascading Style Sheets and controls how HTML looks.
- A rule has a selector, followed by properties and values in curly braces.
- Keeping CSS separate from HTML lets one stylesheet style a whole site.
- The cascade decides which rule wins when several target the same element.
- Some properties, like fonts and text colour, are inherited by child elements.
CSS Examples
Each example runs in the page. Edit the code and press Run to see what changes.
Your first styles
The HTML is in the first tab, the CSS in the second. Change purple to tomato and press Run.
<h1>Hello, CSS!</h1>
<p>This paragraph is about to get stylish.</p>h1 {
color: purple;
font-size: 40px;
}
p {
color: #555;
font-family: Georgia, serif;
}Line-by-line explanation
- Line 1Select every
<h1>on the page. - Line 2Make its text purple.
- Line 3Make it 40 pixels tall.
- Lines 6 to 9A second rule for paragraphs: grey text in a serif font.
Same HTML, two different looks
The HTML is the same simple card. The CSS turns it into something that looks designed. Try deleting the CSS completely and run it again. That's what HTML looks like on its own.
<div class="card">
<h2>Night Owl Café</h2>
<p>Open until 2am. Free refills for coders.</p>
<a href="#">See menu</a>
</div>.card {
max-width: 280px;
padding: 20px;
background: #1e1b4b;
color: white;
border-radius: 16px;
font-family: system-ui, sans-serif;
}
.card a {
color: #fde047;
font-weight: bold;
}Line-by-line explanation
- Line 1
.cardtargets the element withclass="card". - Lines 2 to 3Limit its width and add space inside it.
- Lines 4 to 5A dark indigo background with white text.
- Line 6Rounded corners.
- Lines 10 to 13Style only the links inside the card.
Common CSS Mistakes
Writing CSS inside the HTML text
<p>color: red; This should be red</p><p class="warning">This should be red</p>
<style>
.warning { color: red; }
</style>CSS is its own language. It goes in a <style> element, a .css file or a style attribute, never in the page text. See How to Add CSS.
Using = instead of :
h1 {
color = blue;
}h1 {
color: blue;
}CSS uses a colon between property and value, and a semicolon at the end.
CSS in Real Projects
Every site's personality is CSS
Open two websites built with similar HTML, such as a bank and a game studio. The difference you see is CSS: brand colours, fonts, spacing, dark mode and animations. Browser DevTools (F12) let you edit any site's CSS live. Try changing a heading colour on your favourite site; only you will see it.
CSS Exercises
Answer each one and check it instantly. If you get stuck, open the hint before the answer.
Make every paragraph's text green.
{
: green;
}
p selects paragraphs and color sets the text colour.What does CSS stand for?
In h1 { color: red; }, what is h1?
The heading should be orange and 32px, but the CSS has two syntax errors. Fix them.
<h1>Pumpkin Spice Season</h1>h1 {
color = orange;
font-size: 32px
font-family: sans-serif;
}- The heading is orange
- The heading is 32px
- The font is sans-serif
: between property and value, and end every declaration with ;. A missing semicolon breaks the next line too.CSS Quiz
3 questions to check what you learned.
Which language controls how a web page looks?
- CSS
- HTML
- JavaScript
- SQL
Which symbol separates a property from its value?
- =
- ;
- :
- -
Why is CSS kept separate from HTML?
- Browsers can't read them together
- CSS is faster than HTML
- So one stylesheet can style many pages, and design changes happen in one place
- It's required by law
CSS Challenge
Style a sticky note
Using CSS only (don't change the HTML):
- Give
.notea yellow background (#fff1c2or any yellow) - Add
paddingof16px - Make the
h3inside it red
<div class="note">
<h3>Remember!</h3>
<p>Buy cat food 🐱</p>
</div>/* Write your CSS here */
.notehas a yellow-ish background.notehas 16px padding- The h3 is red
.note, one for .note h3.