SolutionsCase StudiesAI ToolsResourcesAboutContact
Get Your Free AI Automation Audit Book a Free 30-Minute Strategy Call
Playground~/frontend Open editor

~/css/headers

7 CSS Headers

5 Pure CSS2 with JSPublished 2026-10-05Free · no sign-up

Seven site and app headers: the classic logo, links and button that folds into a menu, a centred logo with navigation on both sides, an announcement bar, a header built around search, a transparent header over a hero, a shop header with counted icons and an app bar with breadcrumbs.

01. Logo, Links and Call to Action

HeaderResponsive

The standard site header: logo on the left, navigation in the middle and a button on the right. Below 520px of width the links fold into a menu button with aria-expanded, using a container query so the header adapts to its own space.

View code
<div class="hd1"><header><a class="logo" href="#home">North<b>.</b></a><button class="mb" aria-expanded="false" aria-controls="hd1n">Menu</button><nav id="hd1n" aria-label="Main"><a href="#work">Work</a><a href="#services">Services</a><a href="#about">About</a></nav><a class="cta" href="#contact">Contact</a></header></div>
.hd1 { width: 640px; max-width: 100%; container-type: inline-size; font-family: Inter, system-ui, sans-serif; }
.hd1 header { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; padding: 14px 18px; border: 1px solid #e4e7ec; border-radius: 14px; background: #fff; }
.hd1 .logo { margin-right: auto; color: #101828; font-weight: 900; font-size: 20px; text-decoration: none; } .hd1 .logo b { color: #7f56d9; }
.hd1 nav { display: flex; gap: 18px; }
.hd1 nav a { color: #344054; font-weight: 600; font-size: 14px; text-decoration: none; } .hd1 nav a:hover { color: #7f56d9; }
.hd1 .cta { padding: 9px 14px; border-radius: 8px; background: #101828; color: #fff; font-weight: 700; font-size: 14px; text-decoration: none; }
.hd1 .mb { display: none; padding: 8px 12px; border: 1px solid #d0d5dd; border-radius: 8px; background: #fff; font: 600 13px Inter, system-ui, sans-serif; cursor: pointer; }
.hd1 a:focus-visible, .hd1 button:focus-visible { outline: 3px solid #d6bbfb; outline-offset: 2px; border-radius: 6px; }
@container (max-width: 519px) {
  .hd1 .mb { display: block; } .hd1 .cta { display: none; }
  .hd1 nav { display: none; flex-basis: 100%; flex-direction: column; gap: 4px; }
  .hd1 nav.open { display: flex; } .hd1 nav a { padding: 8px 0; }
}
var b = document.querySelector('.hd1 .mb'), n = document.getElementById('hd1n');
b.onclick = function () { var o = n.classList.toggle('open'); b.setAttribute('aria-expanded', o); };

02. Centred Logo with Split Navigation

HeaderBrand

A boutique-style header with the logo in the middle and links split evenly either side, built with a three-column grid of 1fr auto 1fr so the logo stays exactly centred even when the two link groups have different widths.

View code
<header class="hd2"><nav aria-label="Shop"><a href="#new">New in</a><a href="#women">Women</a></nav><a class="logo" href="#home">ATELIER</a><nav class="r" aria-label="Account"><a href="#search">Search</a><a href="#bag">Bag (2)</a></nav></header>
.hd2 { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; width: 620px; max-width: 100%; box-sizing: border-box; padding: 16px 18px; border-bottom: 1px solid #1c1917; background: #fafaf9; font-family: Inter, system-ui, sans-serif; }
.hd2 nav { display: flex; flex-wrap: wrap; gap: 4px 16px; } .hd2 .r { justify-content: flex-end; }
.hd2 a { color: #1c1917; font-size: 13px; font-weight: 600; text-decoration: none; text-transform: uppercase; letter-spacing: .06em; }
.hd2 .logo { font: 400 22px Georgia, serif; letter-spacing: .3em; }
.hd2 a:focus-visible { outline: 2px solid #1c1917; outline-offset: 3px; }
@media (max-width: 420px) { .hd2 .logo { font-size: 16px; letter-spacing: .15em; } .hd2 a { font-size: 11px; } }

03. Header with Announcement Bar

HeaderPromo

A slim announcement bar above the main header for shipping offers or sales. The bar is a separate region with its own label and a dismiss button, and dismissing removes it without moving keyboard focus unexpectedly.

View code
<div class="hd3"><div class="bar" role="region" aria-label="Announcement"><p>Free shipping on orders over $50 · <a href="#ship">Details</a></p><button aria-label="Dismiss announcement">&times;</button></div><header><a class="logo" href="#home">fern</a><nav aria-label="Main"><a href="#shop">Shop</a><a href="#journal">Journal</a></nav></header></div>
.hd3 { box-sizing: border-box; width: 600px; max-width: 100%; border: 1px solid #e4e7ec; border-radius: 14px; overflow: hidden; background: #fff; font-family: Inter, system-ui, sans-serif; }
.hd3 .bar { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 14px; background: #14532d; color: #dcfce7; font-size: 13px; }
.hd3 .bar p { flex: 1; margin: 0; text-align: center; } .hd3 .bar a { color: #fff; font-weight: 700; }
.hd3 .bar button { width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: #dcfce7; font-size: 18px; cursor: pointer; }
.hd3 header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; }
.hd3 .logo { color: #14532d; font-weight: 900; font-size: 22px; text-decoration: none; }
.hd3 nav { display: flex; gap: 16px; } .hd3 nav a { color: #344054; font-weight: 600; font-size: 14px; text-decoration: none; }
.hd3 a:focus-visible, .hd3 button:focus-visible { outline: 2px solid #22c55e; outline-offset: 2px; border-radius: 4px; }
var bar = document.querySelector('.hd3 .bar'), logo = document.querySelector('.hd3 .logo');
bar.querySelector('button').onclick = function () { bar.remove(); logo.focus(); };

05. Transparent Header over a Hero

HeaderHero

A header that sits on top of the hero image with no background of its own, common on hotel and portfolio sites. A gradient at the top of the hero keeps the white links readable over any photo, which a fully transparent header cannot guarantee.

View code
<div class="hd5"><header><a class="logo" href="#home">Casa Mar</a><nav aria-label="Main"><a href="#rooms">Rooms</a><a href="#dining">Dining</a><a href="#book">Book</a></nav></header><div class="hero"><h3>A quiet stay by the sea</h3></div></div>
.hd5 { position: relative; width: 600px; max-width: 100%; border-radius: 16px; overflow: hidden; font-family: Inter, system-ui, sans-serif; }
.hd5 header { position: absolute; top: 0; left: 0; right: 0; z-index: 1; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 18px; }
.hd5 .logo { color: #fff; font: italic 700 20px Georgia, serif; text-decoration: none; }
.hd5 nav { display: flex; gap: 14px; } .hd5 nav a { color: #fff; font-size: 14px; font-weight: 600; text-decoration: none; }
.hd5 .hero { display: grid; align-items: end; height: 260px; padding: 20px; box-sizing: border-box; background: linear-gradient(rgba(0,0,0,.55), transparent 45%), linear-gradient(transparent 55%, rgba(0,0,0,.5)), linear-gradient(170deg, #7dd3fc 0 45%, #0ea5e9 45% 65%, #e7d2a8 65%); }
.hd5 h3 { margin: 0; color: #fff; font-size: 26px; }
.hd5 a:focus-visible { outline: 2px solid #fff; outline-offset: 3px; border-radius: 4px; }

06. Ecommerce Header with Icons

HeaderEcommerce

A shop header with account, wishlist and cart icons, each a link with an accessible name that includes its count, such as Cart, 3 items. The count badges are decorative copies of that number, and the icons keep 44px tap targets.

View code
<header class="hd6"><a class="logo" href="#home">KNIT</a><nav aria-label="Account"><a href="#account" aria-label="Account"><svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c1-4 4.5-6 8-6s7 2 8 6"/></svg></a><a href="#wishlist" aria-label="Wishlist, 1 item"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 20s-7-4.4-7-10a4 4 0 0 1 7-2.6A4 4 0 0 1 19 10c0 5.6-7 10-7 10z"/></svg><span aria-hidden="true">1</span></a><a href="#cart" aria-label="Cart, 3 items"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 8h14l-1.5 12h-11zM9 8V6a3 3 0 0 1 6 0v2"/></svg><span aria-hidden="true">3</span></a></nav></header>
.hd6 { display: flex; align-items: center; justify-content: space-between; width: 560px; max-width: 100%; box-sizing: border-box; padding: 10px 14px; border: 1px solid #e4e7ec; border-radius: 14px; background: #fff; font-family: Inter, system-ui, sans-serif; }
.hd6 .logo { color: #101828; font-weight: 900; font-size: 20px; letter-spacing: .2em; text-decoration: none; }
.hd6 nav { display: flex; }
.hd6 nav a { position: relative; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; color: #101828; }
.hd6 nav a:hover { background: #f2f4f7; }
.hd6 svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.hd6 nav span { position: absolute; top: 6px; right: 5px; min-width: 16px; height: 16px; border-radius: 8px; background: #b42318; color: #fff; font-size: 10px; font-weight: 800; line-height: 16px; text-align: center; }
.hd6 a:focus-visible { outline: 3px solid #84adff; outline-offset: 1px; }

07. App Header with Title and Avatar

HeaderApp

A web app's top bar: the current page title as the main heading, a breadcrumb trail above it, and an avatar button for the account menu. Inside apps the header orients people rather than markets, so the title is the largest thing in it.

View code
<header class="hd7"><div><nav aria-label="Breadcrumb"><ol><li><a href="#projects">Projects</a></li><li><a href="#acme">Acme rebrand</a></li></ol></nav><h3>Design review</h3></div><button aria-label="Account menu for Ana Ribeiro" aria-haspopup="menu" aria-expanded="false">AR</button></header>
.hd7 { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 560px; max-width: 100%; box-sizing: border-box; padding: 14px 16px; border-bottom: 1px solid #2a3350; background: #121828; font-family: Inter, system-ui, sans-serif; }
.hd7 ol { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 2px; padding: 0; list-style: none; font-size: 12px; }
.hd7 li + li::before { content: "/"; margin-right: 6px; color: #64748b; }
.hd7 ol a { color: #94a3b8; text-decoration: none; } .hd7 ol a:hover { color: #e2e8f0; }
.hd7 h3 { margin: 0; color: #f8fafc; font-size: 20px; }
.hd7 button { flex: none; width: 40px; height: 40px; border: 0; border-radius: 50%; background: #6366f1; color: #fff; font: 800 13px Inter, system-ui, sans-serif; cursor: pointer; }
.hd7 a:focus-visible, .hd7 button:focus-visible { outline: 2px solid #a5b4fc; outline-offset: 2px; border-radius: 4px; }
.hd7 button:focus-visible { border-radius: 50%; }

About these CSS Headers

Landmarks first

Wrap the header in <header> and each group of links in <nav> with an aria-label when there is more than one, such as Main and Account, so screen reader users can jump straight to them.

Collapse with a real button

When links fold away on small screens, the toggle is a <button> with aria-expanded and aria-controls. A container query lets the header collapse based on its own width.

Icons need names

Icon links such as cart and account need an aria-label, and counts belong in that name (Cart, 3 items). Keep tap targets at least 44 by 44 pixels.

Readable over images

A header over a photo needs a scrim: a dark gradient at the top of the hero guarantees contrast for white links whatever the image looks like.

Frequently asked questions

Should the header be sticky?

Often, on long pages. See the sticky elements collection for a header that only gains a shadow once it is stuck.

How do I keep a logo exactly centred?

Use a grid of 1fr auto 1fr; the side columns share the space equally regardless of their content.

Where should the main call to action go?

Top right is the convention people look for, and it should stay visible on mobile when it matters most.