TopicsCheat sheetLessons
Lurndo › HTML & CSS › Semantic blocks

Learn HTML and CSS: Semantic blocks

Blocks with meaning

Hilary's nephew says Google "doesn't get" the site. To a browser it's one big heap of text: where's the menu, where's the address? Time to divide the page into blocks that say what they are.

The parts of a page

Almost every site has the same parts, and HTML has an element for each. <header> is the top of the page, with the logo and the name. <nav> holds the menu: the links to the other pages. <main> is the main content, which appears only once. <footer> is the bottom, with the address and contact details.

Elements like these are called semantic: their name says what's in them. On their own they look no different from an ordinary box. Here the shelter's CSS colours the header and the footer.

You notice the difference when you're not looking: a screen reader jumps straight to the menu or the main content, and Google knows what's content and what's just the edges.

index.html
1<!DOCTYPE html>2<html lang="en">3  <head>4    <title>The Cosy Basket animal shelter</title>5    <link rel="stylesheet" href="basis.css">6    <link rel="stylesheet" href="style.css">7  </head>8  <body>9    <header>10      <img src="mandje.svg" alt="" width="48" height="48">11      <h1>The Cosy Basket</h1>12      <p class="slogan">Animal shelter in Rochdale</p>13      <nav>14        <ul>15          <li><a href="index.html">Home</a></li>16          <li><a href="dogs.html">Dogs</a></li>17          <li><a href="cats.html">Cats</a></li>18          <li><a href="adopt.html">Adopt</a></li>19        </ul>20      </nav>21    </header>22    <main>23      <section id="animals">24        <h2>Looking for a home</h2>25        <article class="card">26          <img src="hond.svg" alt="Rex, a brown Labrador" width="64" height="64">27          <h3>Rex</h3>28          <p>Calm <span class="breed">Labrador</span>, 8 years old.</p>29        </article>30        <article class="card">31          <img src="kat.svg" alt="Misty, a grey cat" width="64" height="64">32          <h3>Misty</h3>33          <p>Playful <span class="breed">British shorthair</span>, 2 years old.</p>34        </article>35      </section>36      <section id="opening-hours">37        <h2>Opening hours</h2>38        <table>39          <tr>40            <th>Day</th>41            <th>Hours</th>42          </tr>43          <tr>44            <td>Wednesday</td>45            <td>1 pm to 5 pm</td>46          </tr>47          <tr>48            <td>Saturday</td>49            <td>10 am to 4 pm</td>50          </tr>51        </table>52        <p>On Sundays we're <span class="closed">closed</span>.</p>53      </section>54      <section id="adopt">55        <h2>How to adopt</h2>56        <ol>57          <li>Fill in the adoption form.</li>58          <li>Come and meet your animal.</li>59          <li>Take your new housemate home.</li>60        </ol>61      </section>62    </main>63    <footer>64      <p>3 Wicker Lane, Rochdale</p>65    </footer>66  </body>67</html>
asiel.example

Section and article

Inside <main> you divide the content further. A <section> is a chapter of the page, with its own heading: the animals, the opening hours, how to adopt.

An <article> is a piece that stands on its own. You could share it separately, like a news item or the card of one animal.

A section often holds articles: the chapter Looking for a home has a card for each animal.

index.html
1<main>2  <section>3    <h2>Looking for a home</h2>4    <article class="card">5      <h3>Rex</h3>6      <p>Calm Labrador, 8 years old.</p>7    </article>8    <article class="card">9      <h3>Misty</h3>10      <p>Playful cat, 2 years old.</p>11    </article>12  </section>13</main>
asiel.example

Try it yourself

Divide the page into blocks: the name in a <header>, the heading and the paragraph about the animals in <main>, and the address in a <footer>.

1<h1>The Cosy Basket</h1>2<h2>Looking for a home</h2>3<p>Rex, Bella and Misty are waiting for a cosy basket.</p>4<p>3 Wicker Lane, Rochdale</p>
1body {2  margin: 0;3  font-family: system-ui, sans-serif;4  background: #fffaf3;5  color: #3d2b1f;6}7header {8  padding: 20px 16px 14px;9  background: #f6c88f;10}11header h1 {12  margin: 4px 0 0;13}14.slogan {15  margin: 4px 0 10px;16}17nav ul {18  display: flex;19  flex-wrap: wrap;20  gap: 4px 18px;21  margin: 0;22  padding: 0;23  list-style: none;24}25nav a {26  color: #7a3e12;27  font-weight: bold;28}29main {30  padding: 8px 16px 24px;31}32table {33  border-collapse: collapse;34}35th,36td {37  padding: 6px 12px;38  border: 1px solid #e3c9a8;39  text-align: left;40}41th {42  background: #fbe3c4;43}44.card {45  margin: 12px 0;46  padding: 12px 16px;47  border-radius: 16px;48  background: #ffffff;49}50.card h3 {51  margin: 4px 0;52}53.box {54  padding: 4px 16px;55  border-radius: 16px;56  background: #fde9d4;57}58.breed {59  color: #b5541c;60}61.closed {62  color: #b42318;63  font-weight: bold;64}65footer {66  padding: 12px 16px;67  background: #f6c88f;68}
asiel.example

Ready for more?

The full lesson has 5 exercises, from easy to challenging, with hints, points and a streak you can build.

Start the lesson
← PreviousTablesNext →Div and span

SQL

  • Topics
  • All lessons
  • Cheat sheet

Excel

  • Topics
  • All lessons
  • Shortcuts

HTML & CSS

  • Topics
  • All lessons
  • Cheat sheet

Touch typing

  • About the course
  • All lessons

Lurndo

  • Dashboard
  • Leaderboard
  • Premium
  • Account
  • Contact & support
  • Privacy
Nederlands