header

Introductory content for its nearest sectioning ancestor. Contains headings, logos, navigation, search forms, or other introductory elements.

Usage

Use the <header> element for:

  • Site header with logo, navigation, and search
  • Page header with title and breadcrumbs
  • Article header with title, author, and publication date
  • Section headers with title and description
  • Card headers with title and actions

A page can have multiple header elements: one for the site and additional ones within articles, sections, or other content.

Examples

Default

Basic header without additional styling.

.site

Full-width site header with flexbox layout.

.page

Page header with bottom border and spacing.

.card

Card header with bottom border.

Sticky

Add data-sticky to pin the header to the top of the viewport during scroll. See the data-sticky attribute page for full details and recipes.

.centered

Centered header for landing pages.

.compact

Compact header with reduced padding and smaller text.

Variants

Class Description
.site Flexbox layout with space-between, padding, and bottom border
.page Bottom border and margin for page title headers
.card Padding with bottom border for card headers
data-sticky Pins header to top of viewport on scroll (see attribute page)
.transparent Absolute positioning with transparent background for hero overlays
.centered Centered text and auto margins for children
.compact Reduced padding and smaller font size

Accessibility

  • The document's main header becomes a banner landmark (only when not nested)
  • Include skip links at the start of the header to bypass navigation
  • Use <nav> with aria-label to identify navigation regions
  • Sticky headers should not obscure content when users navigate with keyboard
  • Ensure transparent headers maintain sufficient contrast with background
  • Consider prefers-reduced-motion for sticky header animations

Related

  • <nav> - Primary navigation typically lives in site headers
  • <hgroup> - For grouping heading with subtitle in headers
  • <footer> - Complementary element for closing content
  • <article> - Header provides article metadata
  • <section> - Header introduces section content