Design a website header image as a responsive component, not as one universal banner file. Choose a clear focal subject, reserve low-detail space for live HTML text, let the container determine the crop, and test the result at desktop, tablet, phone, and zoomed text sizes. The right dimensions depend on your header’s aspect ratio, breakpoints, typography, and subject—not on a single “best” pixel number.
1. Define the header’s job before opening an image editor
A header image may establish brand mood, explain a product, support a campaign, or simply add visual texture. Write that purpose in one sentence. Then identify one focal subject that must survive every crop: a person’s face, a product, a landscape feature, or a logo mark. Secondary details are optional; the focal subject is not.
Choose a crop-safe composition
- Keep the focal subject near the region that remains visible at your narrowest breakpoint. Centering is a safe default when text placement changes, but a left or right focal point can work if the opposite side is deliberately quiet.
- Leave an area of low visual detail for the live heading, supporting copy, and call to action. A flat sky, wall, gradient, or blurred background is easier to read than foliage, faces, or fine patterns.
- Do not put essential words, prices, or navigation inside the bitmap. HTML text can resize, wrap, translate, receive focus, and be read by assistive technology; text baked into an image cannot.
MDN’s responsive-image guidance demonstrates why a wide header can lose its outer sides on a narrow screen: important detail must stay near the chosen focal area. Treat the crop as a design decision at each breakpoint, not as an accidental side effect.
2. Pick dimensions from the container, not a template
Start with the header’s rendered shape. If the hero is 1,440 pixels wide and 420 pixels tall on desktop, its aspect ratio is about 3.43:1. A phone layout might be 390 by 520 pixels, a very different 0.75:1 crop. One source can serve both only when the subject and composition tolerate that change.
A practical sizing process
- Measure the maximum content width and the header height at each breakpoint.
- Multiply each CSS dimension by the highest device-pixel ratio you intend to support, then export a source near that result. Avoid sending a 4,000-pixel image to a 390-pixel viewport.
- Export a small, medium, and large source (for example, 640, 1,200, and 2,000 pixels wide) when the image is used as content.
- Keep the source’s important subject inside the overlap of your desktop and mobile safe areas. If that is impossible, create a separate mobile composition.
There is no universal “website banner size.” A fluid container, the header’s height rules, and your crop strategy determine the correct dimensions.
3. Decide between an HTML image and a CSS background
Use <img> when the image conveys information
An informative hero image belongs in the document, with useful alternative text. Responsive attributes let the browser select an appropriate file:
#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
<header class="hero">
<img
src="hero-1200.jpg"
srcset="hero-640.jpg 640w, hero-1200.jpg 1200w, hero-2000.jpg 2000w"
sizes="100vw"
alt="A ceramic mug beside a notebook on a sunlit desk"
>
<div class="hero__shade" aria-hidden="true"></div>
<div class="hero__content">
<h1>Plan your work clearly</h1>
<p>A short supporting line remains editable HTML.</p>
</div>
</header>
The sizes value describes the image’s likely rendered width under media conditions. Use a more precise expression when the image occupies only part of the viewport, such as sizes="(max-width: 700px) 100vw, 50vw".
Use CSS backgrounds for purely decorative art
If the heading already communicates the page purpose and the image adds atmosphere only, a background can keep it out of the accessibility tree:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →<header class="hero hero--decorative">
<div class="hero__content">
<h1>Build a calmer workspace</h1>
</div>
</header>
.hero--decorative {
background: url("hero-1200.webp") center / cover no-repeat;
}
Use background-position to keep the focal subject visible, and change it at a breakpoint when the crop changes. A background image cannot provide meaningful alternative text, so do not use this technique for an image that carries information the heading does not.
4. Make cropping predictable with CSS
For an <img>, a fixed-height hero commonly uses object-fit: cover. This fills the box while cropping overflow; object-position selects the focal point.
.hero {
position: relative;
min-height: clamp(22rem, 48vw, 34rem);
overflow: hidden;
}
.hero > img {
width: 100%;
height: 100%;
display: block;
object-fit: cover;
object-position: 65% 50%;
}
@media (max-width: 700px) {
.hero { min-height: 30rem; }
.hero > img { object-position: 50% 35%; }
}
If cropping would remove essential content, use object-fit: contain with a controlled background color, reduce the hero’s height, or provide a mobile-specific source with <picture>:
<picture>
<source media="(max-width: 700px)" srcset="hero-mobile-800.jpg 800w, hero-mobile-1200.jpg 1200w" sizes="100vw">
<img src="hero-wide-1200.jpg" srcset="hero-wide-640.jpg 640w, hero-wide-1200.jpg 1200w, hero-wide-2000.jpg 2000w" sizes="100vw" alt="A ceramic mug beside a notebook on a sunlit desk">
</picture>
5. Layer readable HTML text over the image
Keep the content in normal document flow where possible. Positioning the text inside the hero is fine, but do not make the bitmap the only place a user can find the message.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
.hero__shade {
position: absolute;
inset: 0;
background: linear-gradient(90deg, rgba(0,0,0,.72), rgba(0,0,0,.12));
pointer-events: none;
}
.hero__content {
position: relative;
z-index: 1;
max-width: 42rem;
padding: clamp(1.5rem, 5vw, 5rem);
color: #fff;
}
.hero__content h1 {
max-width: 18ch;
text-wrap: balance;
}
.hero__content p { max-width: 45ch; }
Overlay strength should follow the actual crop. A gradient that works on desktop may leave white text over a bright object on mobile. Check every breakpoint with the real heading, navigation, buttons, and hover or focus states.
Rank #2
6. Meet contrast and zoom requirements
WCAG guidance summarized by MDN requires at least a 4.5:1 contrast ratio for normal text and 3:1 for large-scale text. The enhanced targets are 7:1 for normal text and 4.5:1 for large text. Active interface components and meaningful graphical objects need at least 3:1 contrast. These ratios must hold where the text actually appears after the image is cropped—not merely against an average color.
- Use a translucent overlay or directional gradient behind text.
- Move the content to a calmer part of the image at narrow widths.
- Darken or lighten the image, or choose a less detailed photograph.
- Test links, buttons, and focus outlines separately from the heading.
- Zoom the page to 200% or more and confirm that text remains readable, wraps without clipping, and controls remain usable.
Text beside the image is the most robust option when a stable contrast ratio matters more than an immersive overlay. A two-column desktop layout can become a stacked layout on phones without sacrificing readability.
7. Write alternative text that matches the image’s role
Informative image
Describe the information the image adds, concisely. For example: alt="A ceramic mug beside a notebook on a sunlit desk". Do not begin with “image of,” and do not duplicate the heading word for word unless the image itself conveys that same meaning.
Decorative image
Use an empty value, alt="", when the heading and surrounding content already communicate the purpose. This lets assistive technology skip the visual decoration. Do not omit the attribute; an omitted attribute can cause a screen reader to announce a filename or URL.
Logos and functional images
A logo that links home needs a concise label such as the organization name. An image inside a button needs alternative text describing the action, not the pixels.
8. Optimize files without damaging the focal subject
- Use modern WebP or AVIF where your delivery pipeline supports them, with JPEG or PNG fallbacks when needed.
- Export only the dimensions your layout can display and generate responsive sources rather than one oversized file.
- Compress at several quality settings and inspect faces, text-like detail, gradients, and edges at 100% zoom.
- Reserve PNG for transparency or graphics that suffer visibly from lossy compression; photographs generally compress more efficiently in a photographic format.
- Set explicit width and height (or an aspect-ratio box) to reduce layout shift while the image loads.
- Use lazy loading for below-the-fold imagery. The primary hero is often part of the first view, so measure before adding
loading="lazy".
Fluid sizing prevents overflow when an image is not a background:
img { max-width: 100%; height: auto; }
9. Test the finished header systematically
- Review a wide desktop, a medium tablet, and a narrow phone viewport. Resize between them rather than checking only preset device widths.
- Confirm the focal subject remains visible and that the heading does not cover a face, product label, or other essential detail.
- Turn on text zoom or browser zoom and verify readable wrapping, keyboard focus, and no horizontal scrolling.
- Check contrast after every overlay and at the actual crop. Test light and dark themes if the design supports both.
- Throttle the network and inspect the loading state, reserved space, placeholder color, and whether content shifts when the image arrives.
- Disable images temporarily. The heading, navigation, and calls to action must still explain and operate the page.
- Use a screen reader or accessibility tree to confirm that decorative art is skipped and informative art has useful alternative text.
10. Troubleshoot common failures
The subject disappears on phones
Cause: cover crops the sides or the focal point is centered incorrectly. Fix object-position or background-position, reduce the hero height, or serve a mobile composition with <picture>.
Rank #3
The headline is unreadable over one breakpoint
Cause: the overlay was tuned for a different crop. Fix the gradient direction or opacity, move the text, select a calmer image, or place the text beside the image. Recheck the measured contrast ratio.
The browser downloads an unnecessarily large file
Cause: a single high-resolution source or an inaccurate sizes value. Generate width-specific files, provide srcset, and describe the rendered width accurately.
The image creates a layout jump
Cause: no reserved dimensions. Add width and height attributes, an aspect-ratio container, or a CSS height rule that matches the intended layout.
The image is announced twice
Cause: the alt text repeats the nearby heading or the same message is exposed in both the bitmap and HTML. Shorten the alt text to the visual information that is not already present.
Mobile art looks soft or pixelated
Cause: the selected source is too small for the rendered CSS width and device-pixel ratio. Add a larger source at that breakpoint, while still avoiding an oversized desktop file on small screens.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
When you need reference screenshots of your finished header across URLs or states, ScreenshotNeo returns a PNG, JPEG, WebP, or PDF from one request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and whether it was billed. Its MCP server gives Claude, Cursor, and other MCP clients take_screenshot, get_page_info, and capture_pdf tools.
For a direct call, see the ScreenshotNeo API documentation:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
The API also supports full-page captures with lazy images loaded, CSS-selector element captures, dark mode, 12 device presets plus custom viewports, retina scale, PDF paper sizes and page ranges, custom CSS and JavaScript, clicks, selector or network-idle waits, ad and tracker blocking, custom headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed public-image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Familiar parameter names from other screenshot APIs can be used when switching.
Recommended Free Tools
Rank #4
The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; Growth is $15 for 15,000, Pro $39 for 60,000, Scale $99 for 250,000, and Business $249 for 1,000,000. Yearly billing gives two months free, and every feature is available on every plan. Create a free ScreenshotNeo account to start without a card.
Frequently asked questions
Should a header image be above or below the heading in the HTML?
Use the order that best reflects meaning and keyboard flow. The heading and controls should remain discoverable even if the image fails; visual layering does not require changing the semantic order.
Can I use one image for desktop and mobile?
Yes, when the focal subject and quiet text area survive both crops. Otherwise, use a mobile-specific source rather than forcing an unreadable or misleading crop.
Is a gradient overlay always accessible?
No. It improves many photographs, but only measured contrast at the final crop proves adequacy. Recheck large text, body text, controls, and focus indicators at each breakpoint.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsWhen should I preload a hero image?
Consider preloading only when it is a confirmed first-view image and performance measurements justify it. Otherwise, correct dimensions, responsive sources, compression, and a reserved aspect ratio usually provide a better foundation.
Frequently Asked Questions
What is the best header image size for a website?
There is no universal size. Derive source dimensions from the header’s rendered width, height, breakpoints, and device-pixel ratio, then provide responsive sources and test the crop.
Should header text be part of the image file?
No. Keep headings, navigation, and calls to action as HTML so they can resize, wrap, translate, receive focus, and remain accessible.
What alt text should a website header image have?
Describe concise information the image adds. If it is purely decorative and the heading already communicates the purpose, use alt=””.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Quick Recap
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.




