Emmanuel Akinfulubi

HTML and CSSPractical I

Navbar with brand left and links right in CSS

6 A navigation bar with items pushed apart

easy

Build a horizontal navigation bar with the brand on the left and the links on the right.

Stuck? Three hints, smallest first
  1. 1. justify-content: space-between pushes the first and last children to the edges.
  2. 2. Wrap the links in their own container so they stay together as one child.
  3. 3. Use a real <nav> and a list, so assistive technology can announce it.

index.html

<nav class="bar">
  <a class="brand" href="#">Jibowu Park</a>
  <ul class="links">
    <li><a href="#">Routes</a></li>
    <li><a href="#">Fares</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
</nav>

style.css

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;  /* first child left, last child right */
  padding: 10px 14px;
  background: #17171a;
  border-radius: 8px;
}

.bar a { color: #fff; text-decoration: none; }
.brand { font-weight: 600; }

.links {
  display: flex;
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}
Rendered result. Shown, not machine-checked: there is no browser in the build.
8 checks that prove this answer

Assertions, run in the browser. The markup and styles above are handed to them as html and css, so press Run and each check prints ok. The build fails if a single one fails.

Checks for exercise 6

test('the bar is a flex row', declares(css, 'display', 'flex'), true);
test('the ends are pushed apart', declares(css, 'justify-content', 'space-between'), true);
test('items are aligned on the cross axis', declares(css, 'align-items', 'center'), true);
test('the links are their own flex group', hasSelector(css, '.links'), true);
test('spaced with gap, not margins', declares(css, 'gap', '16px'), true);
test('a real nav landmark is used', hasTag(html, 'nav'), true);
test('the links are a list', hasTag(html, 'ul') && countTag(html, 'li') === 3, true);
test('four links in total including the brand', countTag(html, 'a'), 4);

Output


      

space-between works on the bar's direct children, which is why the links are wrapped in their own <ul>: that makes them one child rather than three, so they travel to the right as a group. Using <nav> and a list is not decoration either — a screen reader announces "navigation, list, three items", which a row of bare <a> tags does not.

Newsletter

New writing, when it lands.

Occasional notes on shipping software with AI agents. No schedule, no filler, unsubscribe in one click.