You can turn an HTML list into a colourful navigation menu or sidebar with a few CSS rules. Keep the list structure, style the links and make the layout work on narrow screens as well as desktop.
This updated version of the original lesson builds a header, a horizontal menu, a content area, a sidebar list and a footer. It uses Flexbox and Grid instead of floats. No JavaScript, extension or image download is required.
1. Create the HTML file
Save the following as index.html in a new practice folder. The menu links point to real sections in this example, so they work without creating additional pages.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1">
<title>Colourful lists</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="page">
<header><h1>Creative projects</h1></header>
<nav aria-label="Main">
<ul class="menu" role="list">
<li><a href="#design">Design</a></li>
<li><a href="#code">Code</a></li>
<li><a href="#resources">Resources</a></li>
</ul>
</nav>
<main class="layout">
<article>
<section id="design">
<h2>Design</h2>
<p>Plan a clear layout and readable text.</p>
</section>
<section id="code">
<h2>Code</h2>
<p>Use HTML for structure and CSS for style.</p>
</section>
</article>
<aside id="resources">
<h2>Resources</h2>
<ul class="resources">
<li>Sketch your layout</li>
<li>Test narrow screens</li>
<li>Check keyboard navigation</li>
</ul>
</aside>
</main>
<footer><p>Practice project</p></footer>
</div>
</body>
</html>
The ul element contains list items, and each menu item contains a link. nav, main, article and aside describe the purpose of the page regions. The sidebar remains a normal unordered list.
The stylesheet link must say rel="stylesheet", with straight quotation marks. Save the CSS beside the HTML file with the exact name style.css. The viewport declaration allows the layout to use the device’s screen width.
2. Add the CSS
Copy this into style.css, save both files and open index.html in your browser.
* { box-sizing: border-box; }
body {
margin: 0;
font: 1rem/1.6 system-ui, sans-serif;
color: #17212b;
background: #eef2f6;
}
.page {
max-width: 60rem;
margin: auto;
padding: 1rem;
}
header, article, aside, footer {
padding: 1rem;
background: white;
border-radius: .5rem;
}
h1, h2 { line-height: 1.2; }
.menu {
display: flex;
flex-wrap: wrap;
gap: .5rem;
list-style: none;
padding: 0;
}
.menu a {
display: block;
padding: .75rem 1rem;
color: white;
background: #174b78;
border-radius: .35rem;
text-decoration: underline;
}
.menu li:nth-child(2) a {
background: #4d326d;
}
.menu li:nth-child(3) a {
background: #246047;
}
.menu a:hover,
.menu a:focus-visible {
background: #111827;
}
.menu a:focus-visible {
outline: 3px solid #111827;
outline-offset: 3px;
}
.layout {
display: grid;
gap: 1rem;
margin-bottom: 1rem;
}
.layout > * { min-width: 0; }
.resources {
padding-left: 1.5rem;
}
.resources li {
padding: .5rem;
margin-bottom: .5rem;
background: #e4f0f6;
}
.resources li:nth-child(even) {
background: #ede6f5;
}
@media (min-width: 45rem) {
.layout {
grid-template-columns: 2fr 1fr;
}
}
3. Understand the list styling
display: flex arranges the menu items along a row. flex-wrap: wrap allows them to move onto another line when space runs out. gap provides spacing between items. MDN’s flex-wrap reference explains the wrapping behaviour.
list-style: none removes the menu bullets, while the HTML still contains a list. The explicit list role helps preserve that meaning in accessibility tools. The sidebar keeps its bullets because they help identify the separate items.
Styling the link as a block makes its padded area clickable. The :nth-child() rules give the menu items different backgrounds and alternate the sidebar row colours. These are decorative colours; the text still explains each item’s meaning.
:hover responds to a pointer. :focus-visible gives keyboard users a visible outline and matching colour change. Do not rely on hover alone or remove focus indicators. See MDN’s link styling guidance.
4. Make the layout responsive
The page has a maximum width rather than a fixed width. The content and sidebar stack by default; at 45rem and wider, Grid puts them into two columns. The menu can wrap independently. This avoids using overflow: hidden as a general layout fix: hidden overflow can clip content and focus outlines.
After loading the example, you should see blue, purple and green menu links, pale alternating sidebar items, and a white content panel. At a narrow width the sidebar should appear below the main article. These are expected results for the supplied practice code, not screenshots of a particular browser interface.
5. Test before adapting it
- Resize the browser and check for horizontal scrolling or clipped text.
- Press Tab to reach each menu link. Confirm the focus outline is visible, then press Enter and check that the matching section is reached.
- Zoom the page and check that the content remains readable.
- When changing colours, check text/background contrast and preserve a clear focus indicator.
- If styles do not load, check the filename, folder and stylesheet link. Use the browser’s built-in developer tools to inspect the applied rules.
Replace the practice text and section links with your own content once the layout works. A navigation list uses links because they move to a destination; use buttons for actions such as opening a dialog.
Build your HTML and CSS skills
Explore Academy Class HTML5/CSS3 beginner training for practical work with page structure and styling.