Hero Section Background Image: Size, CSS and Dark Mode

How to pick and code a hero section background image: file size, text-safe area, background-position, light and dark pairs, LCP, and free sources.

Amit Yadav
14 min read
On this page

A good hero section background image is a WebP about 1600 px wide, small enough to load fast, with a calm area where the headline sits and the main subject placed where a crop will not cut it. Set it with background-size: cover and a background-position that anchors that subject, give it a dark twin for dark mode, and if it is the largest thing on the page, load it as an <img> so it does not slow your Largest Contentful Paint (LCP).

This guide covers the parts that break in production: unreadable text, a subject cropped away on phones, a hero that flashes in dark mode, and a background the browser finds too late. The examples use real files from our free hero backgrounds, with sizes and contrast numbers we measured on November 30, 2026.

Key takeaways

  • Serve a 1600 px WebP to laptops and a 640 px WebP to phones. Our 48 hero files weigh 14 KB to 332 KB at 1600 px, median about 46 KB.
  • Put text only in a text-safe area: a calm, low-detail part of the image. White text on a light sky can fall to 1.8:1 contrast; a dark ink from the image's own palette reached 6.7:1.
  • Use background-position (or `object-position` on an `<img>`) to anchor the subject. For a subject at the bottom, `center 85%` keeps it in frame on wide screens.
  • A CSS background is found late by the browser. If the hero is your LCP element, use an `<img>` with `fetchpriority="high"`, or preload the file.
  • Swap a light and dark pair with `prefers-color-scheme`, in CSS or with `<picture>`. For a quiet surface, tint one grey texture with `background-blend-mode: hard-light`.

Size and file format

Width matters more than height, because background-size: cover scales the image to fill the box and crops the overflow. About 1600 px wide looks sharp on most laptops. Serve two widths and let the browser pick:

FileUse it forOur files, measured
WebP, 640 px widePhones, small cards3.7 KB to 48 KB
WebP, 1600 px wideLaptop and desktop heroes14 KB to 332 KB, median about 46 KB
JPG, full sizeEditing, print, retina hero on a large screen70 KB to 593 KB

Those ranges cover our 24 backgrounds and their 24 dark versions, fetched on November 30, 2026. Flat styles compress well and busy ones do not: the 3D "Glass Shapes" is 14 KB at 1600 px, the brush-textured "Linen Hills" 332 KB. If a hero file is far above 200 KB at 1600 px, a calmer image usually saves more than a lower quality setting.

Pick the format by what is in the picture:

  • WebP for photos, paintings and 3D renders. It is smaller than JPG at the same visual quality, and every current browser supports it.
  • JPG as the full-size master you keep for edits.
  • SVG for flat shapes, waves, blobs and repeating patterns. A few kilobytes of SVG can fill a 4K screen with no blur. Our SVG vs PNG test shows where vector stops winning: once an image has gradients, grain or painted detail, a raster file is smaller.

Leave a text-safe area

The most common hero bug is a headline that reads well on one screen and not on another, because the crop moved a cloud or a bright patch behind the text. Plan a text-safe area first: a part of the image with low detail and steady color, where text stays readable at every crop. In a landscape that is usually the sky; in a product shot, the empty wall above the objects.

Glass Shapes, a light 3D background: frosted glass arches, spheres and pastel pills sit in the lower part of a light grey studio, with empty space above for a headline

In "Glass Shapes" above, the shapes sit in a band from 55% to 90% of the image height, and the top half is plain studio grey. That empty top is the text-safe area. Our backgrounds page stores it as a box in percent of the image (for this file: 10% from the left, 6% from the top, 80% wide, 42% tall) and draws it on the preview when you turn on Areas.

Then pick the text color from the image, not from habit. We checked a few pairs with the WCAG contrast formula, using colors from each image's own palette:

Image and areaText colorContrast
Coastal Cliffs, sky blue #87C9FDWhite #FFFFFF1.8:1, fails
Coastal Cliffs, sky blue #87C9FDNavy #0B3A5B6.7:1, passes
Glass Shapes, studio grey #E6E7E9Near black #1F232912.8:1, passes
Glass Shapes dark, night blue #191D28Near white #EEF6F715.4:1, passes

WCAG asks for 4.5:1 for normal text and 3:1 for large text, so white on a light sky fails both. These numbers use each area's average color; real pixels under a letter vary. If the area is busy, add a soft gradient behind the text instead of a dark overlay that hides the image:

.hero {
  background:
    linear-gradient(to bottom, rgb(255 255 255 / 0.6), transparent 55%),
    url("/img/coastal-cliffs-1600.webp") center 85% / cover no-repeat;
}

Keep the subject in frame with background-position

background-size: cover always crops: top and bottom on a wide desktop, the sides on a tall phone. background-position decides what survives. The default 0% 0% (top left) and the common center both fail when the subject sits low. Point the position at the subject instead.

Coastal Cliffs, a painted hero background: green clifftops with wildflowers above a turquoise sea, under a large open blue sky

In "Coastal Cliffs" the cliffs and sea fill the bottom 38%. A hero at 70% of a 1920 x 1080 screen is 1920 x 756 px, so cover shows only about 59% of the image height. With center center it cuts about 20% off the bottom, half the cliffs. With center 85% it loses only the last 6% and crops the sky instead:

.hero {
  min-height: 70vh;
  background: url("/img/coastal-cliffs-1600.webp") center 85% / cover no-repeat;
  color: #0b3a5b;
}

A percent in background-position lines up the point 85% down the image with the point 85% down the box, so the number is roughly where the subject is, at any box height. Each image on our backgrounds page lists its own position value (from 50% 70% to 50% 100%) and a crop note, such as "square and tall crops lose the cliffs at the edges first".

On phones, check the sides too: a wide subject loses its edges whatever the vertical value. Accept it, or give phones a different crop with a media query.

CSS background or img: the LCP question

LCP measures when the largest visible element finishes painting, and a full-width hero is often that element. Google counts an LCP of 2.5 seconds or less as good.

A CSS background image starts loading late. The browser's preload scanner fetches <img> sources from the HTML right away, but it does not see URLs inside a stylesheet, so the background waits until the CSS is parsed and the element matched. Shopify's theme performance guide calls this out and recommends an <img> for hero and LCP images.

You do not lose the cropping control. object-fit and object-position do for an <img> what background-size and background-position do for a background:

<section class="hero">
  <img
    src="/img/coastal-cliffs-1600.webp"
    srcset="/img/coastal-cliffs-640.webp 640w, /img/coastal-cliffs-1600.webp 1600w"
    sizes="100vw"
    width="1600" height="1067"
    alt=""
    fetchpriority="high"
    class="hero-bg">
  <h1>Your headline</h1>
</section>
.hero { position: relative; min-height: 70vh; }
.hero-bg {
  position: absolute; inset: 0; z-index: -1;
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center 85%;
}

Leave alt empty when the image is decoration, so screen readers skip it. Never put loading="lazy" on the hero: lazy loading is for images below the fold, as our lazy loading guide explains. fetchpriority="high" puts this file ahead of other images.

If you want to keep the CSS background, preload the file in the <head> instead:

<link rel="preload" as="image" href="/img/coastal-cliffs-1600.webp" fetchpriority="high">

A CSS background is still fine below the fold and for small repeating tiles.

Swap a light and dark pair with the theme

A bright hero on a dark site flashes like a camera. A black overlay turns a sunny scene muddy. A better fix is a second image painted for the dark theme with the same layout, so the subject and text area stay put when the theme changes.

Glass Shapes, dark version: the same glass shapes in low light, with soft glowing edges on a dark blue-grey ground

This is the dark twin of the "Glass Shapes" image from earlier. The shapes sit in the same place, so the same background-position and the same text area work for both. Only the text color flips. In CSS:

.hero {
  background: url("/img/glass-shapes-1600.webp") center 75% / cover no-repeat;
  color: #1f2329;
}
@media (prefers-color-scheme: dark) {
  .hero {
    background-image: url("/img/glass-shapes-dark-1600.webp");
    color: #eef6f7;
  }
}

With the <img> approach from the LCP section, use <picture>. The browser downloads only the file that matches:

<picture>
  <source srcset="/img/glass-shapes-dark-1600.webp" media="(prefers-color-scheme: dark)">
  <img src="/img/glass-shapes-1600.webp" width="1600" height="1067" alt="" fetchpriority="high" class="hero-bg">
</picture>

One catch: prefers-color-scheme follows the visitor's system setting. If your site has its own theme toggle that sets a class or a data-theme attribute, the <picture> source will not follow it. In that case switch the image in CSS with the same selector your toggle uses, for example [data-theme="dark"] .hero { background-image: ... }.

Every image on our free backgrounds page comes as such a pair, and its Copy CSS button writes this media query with the position you picked. Small details can differ between the two versions; the layout does not.

Tint a texture instead of a photo

Not every hero needs a picture. A plain color with a fine paper or linen grain keeps any text readable, and one small tile repeats across the whole area. Keep one grey tile and let CSS add the color. Our free textures are grey tiles that average exactly 50% grey, and background-blend-mode: hard-light treats that 50% grey as "no change". The grain moves lighter and darker around your color, and the color you set is the color you see:

.hero {
  background: #f4f1ea url("/img/paper.jpg") 0 0 / 256px;
  background-blend-mode: hard-light;
  color: #000;
}

Why not multiply, the blend mode most tutorials use? Multiply always darkens. Multiplied by 50% grey, white turns mid grey, bright yellow turns mustard, and black loses all its grain. Hard-light keeps all three.

Dark mode is one line: keep the file and change only the color, ideally through a CSS variable your dark theme already swaps. The JPG tiles are 1024 x 1024 px and the WebP tiles 512 x 512 px; show the JPG at background-size: 512px or smaller to stay sharp on high-density screens. The Cotton Paper tile is 13 KB as WebP and covers a hero of any size.

Where to get free hero backgrounds

We read each license on November 30, 2026. Sources are listed in order of fit for a typical marketing hero with a headline on top. Licenses change, so check again before you ship.

Disclosure: Free Backgrounds and Free Textures are made by the All SVG Icons team, so read those rows with that in mind.

SourceWhat you getLicense in shortCreditBest for
UnsplashMillions of photosFree for commercial use; no selling unmodified copies, no compiling the photos into a similar or competing service. Unsplash+ photos have a separate, stricter licenseNot requiredA real-world photo of a specific subject
PexelsPhotos and videosFree; no selling unaltered copies, no reposting on other stock or wallpaper sites, no showing people in a bad lightNot requiredPhotos and short background videos
Free Backgrounds (ours)24 hero images, each with a dark twin, plus Notion (1500 x 600), LinkedIn (1584 x 396) and video call (1920 x 1080) cutsFree for commercial use; written permission needed only to redistribute the files or build a competing libraryNot requiredIllustrated or 3D heroes that switch with the theme
PixabayPhotos, illustrations, vectorsFree; no selling or sharing files on their own, care with visible brands and logosNot requiredIllustrations and vectors as well as photos
Burst by ShopifyPhotos aimed at online storesFree for commercial use; no selling the photos as digital filesNot requiredProduct and lifestyle shots for a shop
Hero PatternsRepeating SVG patternsCC BY 4.0RequiredA light geometric pattern behind text
Free Textures (ours)11 seamless paper, linen and concrete tilesSame license as our backgroundsNot requiredA calm, tinted surface instead of a picture

Limits on our two rows: 24 backgrounds is a small set, with no people, offices or products, so for "team at work" you still need a photo site. All are made with AI image tools from our own prompts, then picked, cropped and tagged by hand; in some countries AI images may have limited copyright protection, as our Free Asset License explains. What they add is hero data: a text-safe box, a position value, a crop note, a 5-color palette and a text color for both versions. Our resources page lists the rest of what we make for free.

For any source, download the file and serve it from your own host. Our license asks you not to hotlink in production, because we may rate-limit or move files.

FAQ

What size should a hero background image be?
About 1600 px wide covers most laptop and desktop heroes, with a 640 px version for phones through srcset. Keep the 1600 px WebP small: our hero files range from 14 KB to 332 KB, and flat or 3D images land at the low end.
How do I stop the subject getting cropped on mobile?
Point background-position (or object-position on an img) at the subject. For a subject at the bottom, center 85% keeps it in frame on wide screens. Narrow phones still crop the sides, so check the edges.
Is a CSS background image bad for page speed?
Only when it is the largest element on screen. The browser finds a CSS background late, which can push back LCP. Use an img with fetchpriority high and object-fit cover, or preload the file.
How do I make the hero image change in dark mode?
Swap a second image with the same layout inside a prefers-color-scheme: dark media query, or use a picture element with a dark source. With your own theme toggle, switch the image in CSS with the toggle's selector.
How do I make text readable on a hero background?
Place the text in a calm, low-detail area, pick a text color from the image's own palette and check it reaches 4.5:1 contrast. If the area is busy, add a soft gradient behind the text.
Can I use free hero backgrounds commercially?
Usually yes. Unsplash, Pexels, Pixabay, Burst and our own backgrounds allow commercial use with no credit, with limits on reselling or redistributing the files. Hero Patterns uses CC BY 4.0, so it needs a credit. Read each license before you ship.

Related posts

Share this post