HTML — The Structure CSS Styles
CSS reaches elements only through hooks the HTML provides: element names, classes, ids and their position in the document tree.
Inspect the element names, attributes and relationships that selectors can reach.
Imagine being asked to "make the prices green" on a café's website. Before you can write a single line of CSS, you need to know where the prices are, what they are called, and what they sit inside. CSS never invents elements. It dresses the ones HTML already built.
The rule
CSS can only style what the HTML has already named.
Every CSS rule starts by pointing at elements. It can point using three kinds of hook that live in the HTML:
- the element name, such as
h2orp - a class, such as
class="price" - an id, such as
id="menu"
It can also use position in the tree: an element's parent, its children and its siblings. So the HTML is not just content; it is the map CSS reads.
Here is the page we will style for the whole course, the home page of a small café:
<body>
<header id="top">
<h1>Harbour Café</h1>
<nav class="site-nav">
<a href="#menu">Menu</a>
<a href="#visit">Visit</a>
</nav>
</header>
<main>
<section id="menu">
<h2>Today's menu</h2>
<article class="dish">
<h3>Masala omelette</h3>
<p class="price">₹180</p>
<p>Three eggs, green chilli and coriander.</p>
</article>
<article class="dish special">
<h3>Mango lassi</h3>
<p class="price">₹120</p>
<p>Thick, cold and only in summer.</p>
</article>
</section>
<section id="visit">
<h2>Visit us</h2>
<p>Open 8 am to 6 pm, every day.</p>
</section>
</main>
<footer>
<p>Harbour Café, Marine Drive</p>
</footer>
</body>Read it as a family tree. body has three children: header, main and footer. Each article is a child of section#menu and the parent of an h3 and two paragraphs.

