Skip to content
AITermsLab
–points–day streak

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

HTML
HTML is the code that says what's on a web page: this is a heading, this is a paragraph, this is a button, this is a picture.
CSS
CSS is the code that controls how a web page looks: colours, fonts, spacing and layout.

Side by side

HTML compared with CSS
HTMLCSS
Its jobSays what's on the pageSays how it looks
What the code looks likeTags in angle brackets, like <h1>Welcome</h1>Style rules, like color: navy;
Without itThere's no page at allThe page still works but looks plain: default font, blue links, everything stacked
Stands forHyperText Markup LanguageCascading Style Sheets
In a houseThe frame and the roomsThe paint, wallpaper and how the furniture is arranged
On a phoneUsually stays the sameRearranges 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.

Screen size

Switches

This lesson
rosas-bakery.example
Rosa's Bakery
Basket (0)

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.