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

Use the semantic <header> element for the region, then use CSS to control its dimensions and the typography of the heading inside it. Set the region with properties such as min-height, height, padding, and layout rules; set the title with font-size, line-height, font-weight, and margins. A flexible starting point is:

<header class='site-header'>
  <h1>Site title</h1>
</header>
.site-header {
  min-height: 4rem;
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
}

.site-header h1 {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 3rem);
  line-height: 1.1;
}

Those values are design examples, not a universal standard. The right size depends on your content, navigation, logo, and target viewports.

Decide which “header size” you mean

People use “header size” for three different things. Identify the one that is wrong before changing CSS.

What you want to change Element or property What it controls
The outer header region header or a class such as .site-header; min-height, height, padding, width The box that contains branding, navigation, and other introductory content
The title’s visual size header h1; font-size, line-height, font-weight, margin The rendered text, not the height of the whole region
The document’s heading level h1 through h6 in HTML Structure and accessibility; it does not dictate visual size

The <header> element has no HTML attribute that sets a visual height. HTML supplies meaning and structure; CSS supplies appearance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
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

Build a semantic header first

A typical site header groups a logo, the page’s introductory heading, and navigation:

<header class='site-header'>
  <a class='site-brand' href='/' aria-label='Home'>
    <img src='/images/logo.svg' alt='Example site'>
  </a>
  <div class='site-heading'>
    <h1>Example site</h1>
    <p>Practical guides for developers</p>
  </div>
  <nav aria-label='Primary'>
    <ul>
      <li><a href='/guides'>Guides</a></li>
      <li><a href='/contact'>Contact</a></li>
    </ul>
  </nav>
</header>

Keep the heading rank that matches the page structure. If the page has one main title, that is normally an h1; use lower ranks for subsections. Do not change an h1 to an h2 merely to make the text smaller. Style its appearance with CSS instead.

Set the header region’s dimensions

Prefer min-height when content can wrap

A fixed height is predictable but can clip a two-line title, a larger browser text setting, or a navigation row that wraps. min-height establishes a visual target while allowing the box to grow:

.site-header {
  min-height: 4rem;
  padding: 1rem 2rem;
  box-sizing: border-box;
}

Use a fixed height only when the content is deliberately constrained and you have tested every supported viewport and text size. If you do use one, include box-sizing: border-box so the declared height includes padding and borders.

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

Use padding to create breathing room

Padding often produces a better result than increasing height. It keeps the header responsive to its contents and gives you separate control over horizontal and vertical space:

.site-header {
  padding-block: 1rem;
  padding-inline: clamp(1rem, 4vw, 4rem);
}

When a header appears too tall, inspect padding before shrinking the title. A large vertical padding value can add more height than the text itself.

Control width and the inner content separately

A block-level header normally occupies the available width. To limit the line length of its contents while keeping the background full-bleed, add an inner wrapper:

.site-header {
  width: 100%;
}

.site-header__inner {
  width: min(100% - 2rem, 70rem);
  margin-inline: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

The wrapper prevents very wide navigation and headings from stretching across the entire screen. A fluid maximum width also adapts as the viewport changes.

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

Align children with layout properties

Flexbox controls how the logo, heading, and navigation occupy the header; it does not change heading semantics:

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-header nav ul {
  display: flex;
  gap: 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

align-items: center centers children on the cross axis. If the title or navigation wraps, flex-wrap: wrap lets the region grow instead of forcing an overlap.

Change the heading’s size independently

Target the heading, not the outer box, when the letters are too large or too small:

.site-header h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1.1;
  font-weight: 700;
}

Reset the default heading margin when you need exact spacing, then add deliberate margins to the surrounding elements. line-height controls the vertical space occupied by each line; a value near 1.1 is compact, while body-sized text generally needs more leading.

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

Make the title fluid with clamp()

A fluid declaration sets a minimum, a preferred viewport-based value, and a maximum:

.site-header h1 {
  font-size: clamp(1.75rem, 3vw + 1rem, 3.5rem);
  line-height: 1.1;
}

The browser keeps the computed size between 1.75rem and 3.5rem while allowing it to scale with the viewport. Relative units such as rem and em respect user and ancestor text sizing better than unqualified pixel values.

Keep visual size separate from heading rank

An h2 can be styled larger than an h1 if a design needs that visual treatment. The rank still communicates the document hierarchy, so choose the HTML element for structure and CSS for appearance.

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

Make the header responsive

Responsive headers need room for long translations, zoomed text, narrow phones, and navigation wrapping. Combine flexible dimensions with a breakpoint only where the layout actually changes:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.site-header {
  min-height: 4rem;
  padding-inline: clamp(1rem, 4vw, 4rem);
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

@media (max-width: 40rem) {
  .site-header {
    min-height: auto;
  }

  .site-header__inner {
    align-items: flex-start;
  }

  .site-header nav {
    flex-basis: 100%;
  }
}

40rem is a valid numeric media-query length; a word such as fortyrem is not. At the narrow breakpoint, allowing the navigation to occupy a full row is safer than compressing every item into one line.

Unit or technique Best use Trade-off
px Small borders, icons, or a tightly controlled fixed measurement Does not scale with user text preferences by itself
rem Header padding, minimum heights, and type that should follow the root text size Changes when the root font size changes
em Measurements intentionally relative to the component’s font size Nested font-size changes can compound
clamp() Fluid headings and padding with explicit limits Needs a tested minimum and maximum
Media queries Switching from a horizontal to a wrapped or stacked layout Adds another state to maintain

Use a comfortable maximum line length for the inner content. A fluid layout with a maximum around 70em is a useful starting point, but measure your actual navigation and heading rather than copying a number blindly.

Understand semantics and landmark behavior

The <header> element represents introductory content, commonly including a heading, logo, navigation, search form, or author information. A header at the body level has the site-wide banner landmark meaning. When it is nested inside article, main, section, nav, or aside, it is a generic grouping instead.

This context does not change its CSS dimensions, but it changes how assistive technology can expose the landmark. Use the element where it matches the content’s structure; do not add a role solely to obtain a visual effect.

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

Heading rank follows the document outline: rank 1 (h1) is the most important and rank 6 (h6) the least. A larger-looking heading is not necessarily a higher-ranked heading.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Override browser defaults deliberately

Browsers provide default heading margins and font sizes. Those defaults can make a header appear taller than expected or introduce inconsistent spacing between browsers. Set the values you rely on:

h1, h2, h3, p {
  margin-block: 0;
}

.site-heading {
  display: grid;
  gap: 0.25rem;
}

.site-heading p {
  margin: 0;
}

Apply this reset narrowly when possible. A global reset can affect article content, forms, and third-party components that were designed around the browser defaults.

Troubleshoot a header that is the wrong size

  • The box is too short: inspect height, min-height, vertical padding, flex alignment, and whether children wrap. Remove a rigid height or switch to min-height so the content can expand.
  • The box is too tall: check inherited margins on h1, p, and lists, then check vertical padding and line-height. Use the browser’s computed-style panel to identify which declaration contributes the extra pixels.
  • The text is the wrong size: inspect font-size, inherited styles, browser defaults, and media-query rules. A later or more specific selector may be overriding header h1.
  • Content is clipped or overlaps: look for a fixed height combined with overflow: hidden, absolutely positioned children, or a non-wrapping flex row. Let the header grow, enable wrapping, and reserve space for the largest expected label.
  • The logo changes the height: give the image a predictable display and maximum size, for example display: block; max-height: 2.5rem; width: auto;. Avoid stretching it with an unrestricted width and height pair.
  • The navigation drops unexpectedly: measure the combined width of the logo, heading, gaps, and links. Reduce gaps only after confirming the text remains usable; otherwise switch to a deliberate stacked layout at a breakpoint.
  • The heading hierarchy is wrong: change the HTML rank only when the document structure is wrong. Use font-size and related CSS when the issue is visual.
  • The header is not announced as a banner: check its location in the DOM. A header nested in a sectioning element has a different landmark context from a body-level header.

Verify the result before shipping

  1. Open browser developer tools and inspect the header element, then read its box-model and computed-style values.
  2. Resize the viewport through the narrowest supported width and a wide desktop width. Check for wrapping, overlap, and unexpected horizontal scrolling.
  3. Increase browser text size or zoom and confirm that the region grows instead of clipping its contents.
  4. Test long titles, translated navigation labels, and a missing or slow-loading logo; these reveal fixed-height assumptions.
  5. Check keyboard focus visibility and the reading order of the logo, heading, and navigation. A visually centered item should still occur in a logical DOM order.
  6. Keep the component’s dimensions and typography in one stylesheet section so later media-query overrides are easy to find.

Or skip the browser setup

If you need a rendered image of the finished page for documentation, visual checks, or a responsive-header review, ScreenshotNeo can capture the URL with one GET request. Its API can select a viewport or device preset, capture the full page or one CSS-selected element, wait for a selector, delay, or network idle, and apply custom CSS or JavaScript before the shot.

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

See the ScreenshotNeo API documentation for all parameters. A minimal cURL request is:

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

The same request in Python:

import requests
r = requests.get(
    'https://api.screenshotneo.com/v1/shot',
    params={'access_key': 'YOUR_API_KEY', 'url': 'https://example.com'},
    timeout=90,
)
open('shot.webp', 'wb').write(r.content)

And in Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Before capture, ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in X-Page-Verdict and X-Billed headers. It also provides an MCP server with 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 with no card. Paid plans start at $5 for 3,000 shots; yearly billing provides two months free, and every feature is available on every plan. Create a free ScreenshotNeo account to capture your header without setting up a browser.

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.

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