HTML vs CSS: what's the difference?
HTML is the code that says what's on a web page: headings, text, pictures and buttons. CSS is the code that controls how those things look: colours, fonts, spacing and layout.
Last updated
What each one means
Side by side
| HTML | CSS | |
|---|---|---|
| Its job | Says what's on the page | Says how it looks |
| What the code looks like | Tags in angle brackets, like <h1>Welcome</h1> | Style rules, like color: navy; |
| Without it | There's no page at all | The page still works but looks plain: default font, blue links, everything stacked |
| Stands for | HyperText Markup Language | Cascading Style Sheets |
| In a house | The frame and the rooms | The paint, wallpaper and how the furniture is arranged |
| On a phone | Usually stays the same | Rearranges the layout to fit the screen |
An example: a shop's product card
On an online shop, HTML says each product card has a picture, a name, a price and an Add to basket button. CSS rounds the card's corners, puts three cards side by side on a laptop and stacks them on a phone. Change the CSS and every card restyles, while the HTML stays the same.
See it: switch CSS off
The toy bakery page shows both at work. Switch CSS off and the page falls back to plain HTML: a Times-style font, blue underlined links and everything stacked. Open the code panel to see the HTML and CSS behind it.
Switches
Fresh bread, baked at 6am
Order by 10am, collect after lunch.
Sourdough loaf
£4.00
Cinnamon bun
£2.50
Lemon cake
£3.00
The code behind it (simplified)
HTML: what's on the page
<h1>Fresh bread, baked at 6am</h1>
<p>Order by 10am, collect after lunch.</p>
<li class="card">
<img src="sourdough.svg" alt="Sourdough loaf">
<h2>Sourdough loaf</h2>
<p>£4.00</p>
<button>Add to basket</button>
</li>CSS: how it looks
.card {
border: 2px solid navy;
border-radius: 20px;
}
button {
background: yellow;
font-weight: bold;
}JavaScript: how it reacts
button.onclick = () => {
basket = basket + 1;
showBasketCount(basket);
};Switch CSS off to see how much of the look comes from it.
Common questions
Should I learn HTML before CSS?
Usually, yes. CSS styles HTML elements, so it helps to know what a heading or a button is first. Most people learn the two side by side.
Can a web page work without CSS?
Yes. All the content is still there and the links still work. It just looks plain, the way browsers show a page with no styling at all.
Are HTML and CSS programming languages?
Not really. HTML is a markup language that labels content, and CSS is a style sheet language. Neither makes decisions or repeats steps the way JavaScript does.