Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk6 min

CSS Headers: How to Style a Website Header

Style a website header with semantic HTML, Flexbox, visible keyboard focus, and responsive behavior chosen to fit your content.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build a website header by giving it meaningful HTML structure first, then using CSS to align its logo, navigation, and utilities. Use Flexbox or Grid for the layout, and let the content—not a supposedly universal pixel value—determine when it needs to wrap or change at smaller widths.

Start with semantic HTML

A site-wide header commonly contains recurring site identity and utility content, such as a logo, primary navigation, or search. The W3C WAI page-regions guidance describes the purpose of page regions; MDN documents the HTML <header> element.

Use <header> for the introductory or identity region, and put a significant group of navigation links in <nav>. Use ordinary links for navigation and native buttons for actions. A page-level header is not interchangeable with an article’s introductory header: as MDN explains, a <header> in a body context defines a banner landmark, while one nested in content such as an article or section does not serve as the page banner landmark.

<header class="site-header">
  <a class="site-brand" href="/" aria-label="Example site home">
    <img src="/images/logo.svg" alt="Example Site" width="140" height="36">
  </a>

  <nav class="primary-nav" aria-label="Primary navigation">
    <ul>
      <li><a href="/guides/">Guides</a></li>
      <li><a href="/reviews/">Reviews</a></li>
      <li><a href="/about/">About</a></li>
    </ul>
  </nav>

  <a class="header-action" href="/subscribe/">Subscribe</a>
</header>

For a logo image that conveys the site’s identity, provide meaningful alternative text. If the linked image’s accessible name is already supplied by an aria-label on the link, use an empty alt value to avoid announcing the identity twice. Avoid adding a heading solely to get a particular font size; use headings for actual content structure and style their appearance separately.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Style the header with CSS

Start with a container width and spacing that suit the rest of the site, then align the brand, navigation, and action. This example uses Flexbox and allows the content to wrap instead of clipping when the row becomes crowded.

* {
  box-sizing: border-box;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
  max-width: 72rem;
  margin-inline: auto;
  padding: 1rem clamp(1rem, 4vw, 2rem);
  border-bottom: 1px solid #d9dee7;
  background: #fff;
  color: #172033;
}

.site-brand {
  flex: 0 0 auto;
  line-height: 0;
}

.site-brand img {
  display: block;
  max-width: 100%;
  height: auto;
}

.primary-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.primary-nav a,
.header-action {
  color: inherit;
  text-decoration: none;
}

.primary-nav a {
  display: inline-block;
  padding-block: 0.5rem;
}

.primary-nav a:hover,
.header-action:hover {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.primary-nav a:focus-visible,
.site-brand:focus-visible,
.header-action:focus-visible {
  outline: 3px solid #245bdb;
  outline-offset: 3px;
}

.header-action {
  flex: 0 0 auto;
  padding: 0.65rem 0.9rem;
  border: 1px solid currentColor;
  border-radius: 0.35rem;
}

@media (max-width: 42rem) {
  .site-header {
    flex-wrap: wrap;
  }

  .primary-nav {
    order: 1;
    flex-basis: 100%;
  }
}

The maximum width, padding, colors, and 42rem breakpoint above are example design choices, not standards. Adjust them for your content and test at widths where the actual logo, links, and action begin to crowd or wrap.

Why this layout works

  • Flexbox aligns the main items. The brand and action keep their intrinsic size while the navigation occupies the remaining space.
  • Wrapping is a fallback. The navigation list can wrap, and the narrow-width rule gives it a full row rather than letting the whole header overflow.
  • Focus remains visible. Keyboard users can see which link or action is active.
  • The source order stays sensible. The brand comes first, followed by navigation and the action in the HTML, so the reading and keyboard order remain logical.

Choose a responsive behavior that fits the content

There is no universal breakpoint for a header. Choose one by resizing the page until the real content no longer fits comfortably, then decide whether to wrap, stack, or provide a compact navigation control. The W3Schools responsive-header example stacks links at 500px; that is an example implementation, not a prescribed breakpoint.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
Approach Useful when Check before using it
Single row The brand, navigation, and utility items fit without crowding at the tested width. Confirm no links clip, overlap, or become difficult to tap.
Wrapping or stacked rows The same navigation can remain visible while moving to another line at narrower widths. Check that the resulting header is not excessively tall and that visual order still follows the HTML order.
Compact menu control The full navigation cannot remain usable in the available space. A real menu needs an operable native button and appropriate behavior; hiding links with CSS alone does not create a working menu.

When CSS changes visual placement, keep the DOM order aligned with the order people should read and use the controls. MDN’s HTML accessibility guidance emphasizes getting logical source order right; W3C’s H69 technique discusses headings at the beginning of content sections. H69 is a technique, not a blanket requirement to add headings for visual styling.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Inspect the result at different widths

  1. Load the page at a wide viewport and confirm the brand, navigation, and action align as intended.
  2. Reduce the viewport gradually. Note where text wraps, items collide, or the navigation becomes hard to use.
  3. Check a narrow viewport and verify every link remains available and operable.
  4. Use the keyboard to move through the header; confirm focus is visible and follows the same sensible order as the content.
  5. Check that the header’s contrast, spacing, and tap targets work with the site’s actual type and colors.

You can inspect a rendered page with ScreenshotNeo, a website screenshot API and MCP server for developers. For example, capture a test page at a chosen viewport and compare its layout as you adjust the CSS. Screenshots complement—not replace—keyboard checks and testing at intermediate widths.

Or skip the browser setup

One GET request can capture a page as an image. See the ScreenshotNeo documentation for the API options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers indicate the page verdict and whether the request was billed. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common header problems

Items overflow or overlap

The row may not have enough room for the logo, link labels, gaps, and action. Reduce unnecessary spacing, permit wrapping, or move to a stacked layout at a content-tested breakpoint. Do not solve overflow by hiding navigation links without providing a usable alternative.

The logo is too large or distorted

Set a sensible width and allow the image height to remain automatic. Explicit width and height attributes help reserve layout space, but the CSS should still constrain the image to the header’s available width.

Keyboard focus is hard to see

Check whether a reset or global rule removed outlines. Add a visible :focus-visible style with enough contrast against the header background; do not rely on hover styling as a substitute.

The header looks right but reads in the wrong order

CSS visual reordering can diverge from document order. Prefer a source order that already matches the intended reading and keyboard sequence, and use layout rules that preserve it.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Structure headings for content, not appearance

A site header’s logo and navigation do not need to be wrapped in headings simply because they are prominent. Use heading levels to identify the sections of page content, and use CSS for font size and visual hierarchy. W3C WAI’s H69 guidance describes headings at the beginning of sections as a technique for communicating structure; it does not require a heading in every header element.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.