Learn HTML and CSS: A menu
A menu for several pages
One long page isn't enough any more. Hilary wants a page for the dogs, one for the cats and one about adopting, and a menu at the top so nobody gets lost.
A site is a folder of pages
Each page is an HTML file of its own. index.html is the home page: it opens when you go to the site's address. Next to it come dogs.html, cats.html and adopt.html.
The menu is a list of links in a <nav>. A list, because it's a series of similar things: a screen reader says straight away how many choices there are.
The menu is on every page, so you can get anywhere from any page. The items sit side by side without bullets here because of the shelter's CSS. You'll learn how that works in the flexbox module.
<header> <h1>The Cosy Basket</h1> <nav> <ul> <li><a href="index.html">Home</a></li> <li><a href="dogs.html">Dogs</a></li> <li><a href="cats.html">Cats</a></li> <li><a href="adopt.html">Adopt</a></li> </ul> </nav></header><main> <h2>Welcome</h2> <p>Every animal deserves a cosy basket.</p></main>Folders and paths
A big site puts pages in folders, like an animals folder with a page per animal. A relative path always starts from the folder of the page you're on.
cats.html is in the same folder. animals/misty.html goes one folder down, into the animals folder. And ../index.html goes one folder up: .. means "the folder above".
This is the page animals/misty.html. A link to index.html won't take you to the home page from here: the browser then looks for animals/index.html.
<main> <h1>Misty</h1> <p>Playful cat, 2 years old, mad about cardboard boxes.</p> <p><a href="../cats.html">All cats</a> · <a href="../index.html">Back to home</a></p></main>Try it yourself
Under the name, add a menu with four links: Home to index.html, Dogs to dogs.html, Cats to cats.html and Adopt to adopt.html.
<header> <h1>The Cosy Basket</h1></header>body { margin: 0; font-family: system-ui, sans-serif; background: #fffaf3; color: #3d2b1f;}header { padding: 20px 16px 14px; background: #f6c88f;}header h1 { margin: 4px 0 0;}.slogan { margin: 4px 0 10px;}nav ul { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 0; padding: 0; list-style: none;}nav a { color: #7a3e12; font-weight: bold;}main { padding: 8px 16px 24px;}table { border-collapse: collapse;}th,td { padding: 6px 12px; border: 1px solid #e3c9a8; text-align: left;}th { background: #fbe3c4;}.card { margin: 12px 0; padding: 12px 16px; border-radius: 16px; background: #ffffff;}.card h3 { margin: 4px 0;}.box { padding: 4px 16px; border-radius: 16px; background: #fde9d4;}.breed { color: #b5541c;}.closed { color: #b42318; font-weight: bold;}footer { padding: 12px 16px; background: #f6c88f;}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