Web development

Top 5 Fan Site

Build a fan page for your five favourite animals, with a header, a menu and cards laid out side by side.

Day 3 50 to 60 minutes 6 steps Key Stage 3
Start step 1
top-5-fan-site/index.html

Real websites have a header, a menu, content laid out in a grid and a footer. Today you will build one: a fan site for your top five animals, each on its own card, side by side.

You will learn

  • Plan a page with <header>, <main> and <footer>
  • Make links that jump to a part of the page
  • Lay out cards side by side with flexbox
  • Add shadows and a hover effect

You will need

  • A computer with a web browser
  • The Web Studio, or Notepad
  • Days 1 and 2, for HTML and CSS

Words to know

layout
How the parts of a page are arranged.
flexbox
A CSS layout that puts things in a row and wraps them onto new lines.
id
A unique name for one element, such as id="top5", which a link can jump to.
hover
Pointing at something with the mouse. :hover styles only apply then.

Step by step

  1. Step 1: Plan the page

    In the Web Studio, choose Day 3: Top 5 Fan Site. The page has three parts: a <header> at the top, the <main> content, and a <footer> at the bottom. The cards will go in the empty <div> called cards.

    index.htmlHTML
    <!DOCTYPE html><html>  <head>    <meta charset="utf-8">    <title>My Top 5 Animals</title>    <link rel="stylesheet" href="style.css">  </head>  <body>    <header>      <h1>My Top 5 Animals</h1>      <p>The five best animals on the planet, in my opinion.</p>    </header>    <main>      <h2 id="top5">The top 5</h2>      <div class="cards">       </div>    </main>    <footer>Made by Sam for Coding Club</footer>  </body></html>
    style.cssCSS
    body {  font-family: Arial, sans-serif;  margin: 0;  background: #f4f7fb;}
    top-5-fan-site/index.html
    A heading, a line about the page and a footer.
  2. Step 2: Five cards

    Each animal gets a <div class="card">: a box holding an emoji, a name and a fact. Fill in all five. They stack one under another for now.

    New: lines 16 to 40.

    index.htmlHTML
    <!DOCTYPE html><html>  <head>    <meta charset="utf-8">    <title>My Top 5 Animals</title>    <link rel="stylesheet" href="style.css">  </head>  <body>    <header>      <h1>My Top 5 Animals</h1>      <p>The five best animals on the planet, in my opinion.</p>    </header>    <main>      <h2 id="top5">The top 5</h2>      <div class="cards">        <div class="card">          <div class="emoji">&#129418;</div>          <h3>Fox</h3>          <p>A fox's bushy tail is called a brush, and it wraps it round itself to keep warm.</p>        </div>        <div class="card">          <div class="emoji">&#128025;</div>          <h3>Octopus</h3>          <p>An octopus has three hearts and blue blood.</p>        </div>        <div class="card">          <div class="emoji">&#129446;</div>          <h3>Sea otter</h3>          <p>Sea otters sometimes hold hands while they sleep, so they do not drift apart.</p>        </div>        <div class="card">          <div class="emoji">&#128039;</div>          <h3>Emperor penguin</h3>          <p>Emperor penguins can dive more than 500 metres deep.</p>        </div>        <div class="card">          <div class="emoji">&#129417;</div>          <h3>Owl</h3>          <p>An owl cannot move its eyes, so it turns its whole head instead.</p>        </div>      </div>    </main>    <footer>Made by Sam for Coding Club</footer>  </body></html>
    top-5-fan-site/index.html
    Five animals, one under another.
  3. Step 3: A header and a menu

    Colour the header, and add a <nav> menu with two links. href="#top5" jumps to the element with id="top5". Add a section at the bottom for the second link to jump to.

    New: lines 12 to 15, 46 and 47.

    index.htmlHTML
    <!DOCTYPE html><html>  <head>    <meta charset="utf-8">    <title>My Top 5 Animals</title>    <link rel="stylesheet" href="style.css">  </head>  <body>    <header>      <h1>My Top 5 Animals</h1>      <p>The five best animals on the planet, in my opinion.</p>      <nav>        <a href="#top5">Top 5</a>        <a href="#vote">Vote</a>      </nav>    </header>    <main>      <h2 id="top5">The top 5</h2>      <div class="cards">        <div class="card">          <div class="emoji">&#129418;</div>          <h3>Fox</h3>          <p>A fox's bushy tail is called a brush, and it wraps it round itself to keep warm.</p>        </div>        <div class="card">          <div class="emoji">&#128025;</div>          <h3>Octopus</h3>          <p>An octopus has three hearts and blue blood.</p>        </div>        <div class="card">          <div class="emoji">&#129446;</div>          <h3>Sea otter</h3>          <p>Sea otters sometimes hold hands while they sleep, so they do not drift apart.</p>        </div>        <div class="card">          <div class="emoji">&#128039;</div>          <h3>Emperor penguin</h3>          <p>Emperor penguins can dive more than 500 metres deep.</p>        </div>        <div class="card">          <div class="emoji">&#129417;</div>          <h3>Owl</h3>          <p>An owl cannot move its eyes, so it turns its whole head instead.</p>        </div>      </div>      <h2 id="vote">Which is your favourite?</h2>      <p>Tell me at Coding Club, and I might change my list!</p>    </main>    <footer>Made by Sam for Coding Club</footer>  </body></html>

    New: lines 6 to 18.

    style.cssCSS
    body {  font-family: Arial, sans-serif;  margin: 0;  background: #f4f7fb;} header {  background: #1e5fa8;  color: white;  text-align: center;  padding: 24px;} nav a {  color: white;  margin: 0 12px;  font-weight: bold;}
    top-5-fan-site/index.html
    A blue header with a menu.
  4. Step 4: Side by side

    Flexbox lays things out in a row. display: flex on the cards box puts the cards side by side, flex-wrap: wrap lets them move onto the next line when there is no room, and gap spaces them out.

    New: lines 19 to 32.

    style.cssCSS
    body {  font-family: Arial, sans-serif;  margin: 0;  background: #f4f7fb;} header {  background: #1e5fa8;  color: white;  text-align: center;  padding: 24px;} nav a {  color: white;  margin: 0 12px;  font-weight: bold;} main {  padding: 20px;} .cards {  display: flex;  flex-wrap: wrap;  gap: 16px;} .card {  width: 170px;}
    top-5-fan-site/index.html
    The cards sit side by side and wrap onto a new line.
  5. Step 5: Make them look like cards

    A white background, rounded corners and a soft shadow make each box look like a card. Make the emoji big. rgba(0, 0, 0, 0.15) is black at 15% strength, a light shadow.

    New: lines 32 to 36 and 38 to 41.

    style.cssCSS
    body {  font-family: Arial, sans-serif;  margin: 0;  background: #f4f7fb;} header {  background: #1e5fa8;  color: white;  text-align: center;  padding: 24px;} nav a {  color: white;  margin: 0 12px;  font-weight: bold;} main {  padding: 20px;} .cards {  display: flex;  flex-wrap: wrap;  gap: 16px;} .card {  width: 170px;  background: white;  border-radius: 14px;  padding: 14px;  text-align: center;  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);} .emoji {  font-size: 64px;}
    top-5-fan-site/index.html
    Proper cards, with shadows.
  6. Step 6: Lift on hover

    transform: translateY(-6px) moves a card up 6 pixels, but only while the mouse is over it. transition makes the move smooth instead of a jump. Finish with a footer style.

    New: lines 32 and 43 to 53.

    style.cssCSS
    body {  font-family: Arial, sans-serif;  margin: 0;  background: #f4f7fb;} header {  background: #1e5fa8;  color: white;  text-align: center;  padding: 24px;} nav a {  color: white;  margin: 0 12px;  font-weight: bold;} main {  padding: 20px;} .cards {  display: flex;  flex-wrap: wrap;  gap: 16px;} .card {  width: 170px;  transition: transform 0.2s;  background: white;  border-radius: 14px;  padding: 14px;  text-align: center;  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);} .emoji {  font-size: 64px;} .card:hover {  transform: translateY(-6px);  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);} footer {  text-align: center;  padding: 16px;  color: #555555;}
    top-5-fan-site/index.html
    Point at a card: it lifts up. Try the menu links too.

Test it

Tick each one when it works. If one does not, look back at the step it comes from.

Stretch challenges

Finished early? Try these. Each one has a hint if you get stuck.

  1. Your own top 5

    Change the page to your own top five: films, games, foods or footballers.

    Show a hint

    Change the text in each card, and pick new emoji. Keep the class names the same so the styles still work.

  2. Number them

    Put a coloured number badge, 1 to 5, in the corner of each card.

    Show a hint

    Add <span class="rank">1</span> to each card. Give .card position: relative, and .rank position: absolute; top: 8px; left: 8px; with a background and a border-radius.

  3. A favourite

    Make your number 1 card stand out from the rest.

    Show a hint

    Give it a second class, class="card top", then style .top with a gold border.

The finished code

Show the whole page
index.htmlHTML
<!DOCTYPE html><html>  <head>    <meta charset="utf-8">    <title>My Top 5 Animals</title>    <link rel="stylesheet" href="style.css">  </head>  <body>    <header>      <h1>My Top 5 Animals</h1>      <p>The five best animals on the planet, in my opinion.</p>      <nav>        <a href="#top5">Top 5</a>        <a href="#vote">Vote</a>      </nav>    </header>    <main>      <h2 id="top5">The top 5</h2>      <div class="cards">        <div class="card">          <div class="emoji">&#129418;</div>          <h3>Fox</h3>          <p>A fox's bushy tail is called a brush, and it wraps it round itself to keep warm.</p>        </div>        <div class="card">          <div class="emoji">&#128025;</div>          <h3>Octopus</h3>          <p>An octopus has three hearts and blue blood.</p>        </div>        <div class="card">          <div class="emoji">&#129446;</div>          <h3>Sea otter</h3>          <p>Sea otters sometimes hold hands while they sleep, so they do not drift apart.</p>        </div>        <div class="card">          <div class="emoji">&#128039;</div>          <h3>Emperor penguin</h3>          <p>Emperor penguins can dive more than 500 metres deep.</p>        </div>        <div class="card">          <div class="emoji">&#129417;</div>          <h3>Owl</h3>          <p>An owl cannot move its eyes, so it turns its whole head instead.</p>        </div>      </div>      <h2 id="vote">Which is your favourite?</h2>      <p>Tell me at Coding Club, and I might change my list!</p>    </main>    <footer>Made by Sam for Coding Club</footer>  </body></html>
style.cssCSS
body {  font-family: Arial, sans-serif;  margin: 0;  background: #f4f7fb;} header {  background: #1e5fa8;  color: white;  text-align: center;  padding: 24px;} nav a {  color: white;  margin: 0 12px;  font-weight: bold;} main {  padding: 20px;} .cards {  display: flex;  flex-wrap: wrap;  gap: 16px;} .card {  width: 170px;  transition: transform 0.2s;  background: white;  border-radius: 14px;  padding: 14px;  text-align: center;  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);} .emoji {  font-size: 64px;} .card:hover {  transform: translateY(-6px);  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);} footer {  text-align: center;  padding: 16px;  color: #555555;}
Notes for the teacher

Timing

  1. 10 minutes: step 1. Sketch the page's boxes on the board: header, main, cards, footer.
  2. 25 minutes: steps 2 to 4. Flexbox is the big idea: try changing the width of the preview to watch the cards wrap.
  3. 15 minutes: steps 5 and 6, the tests, then students make it their own.

Mistakes to look out for

  1. A card's </div> missing: the cards nest inside each other and the layout goes strange.
  2. display: flex on .card instead of .cards: it is the box holding the cards that lays them out.
  3. href="top5" without the #: the link looks for a page called top5 instead of jumping down.
  4. Facts copied from the internet without checking: a good moment to talk about reliable sources.

Going further

Narrow the window and watch the cards move onto new lines: this is responsive design, the same page working on a phone and a computer.