CSS Background Image Generator

Set up a background image with the right size, position and overlay, preview it with text on top, and copy the CSS.

Readable heading on a photo

How to set a background image

  1. Paste the URL of your image, or choose a local file to preview it (the CSS then uses a path you can edit to match your project).
  2. Pick how the image should fill the box with background-size and background-position.
  3. Add an overlay if text sits on top, and copy the CSS.

cover vs contain

ValueResultUse for
coverFills the whole box, cropping the overflowHero sections, banners, full-screen backgrounds
containWhole image visible, empty space around itLogos, product shots, illustrations
autoNatural sizeSmall decorative images
100% 100%Stretched to fit, distorting the imageAbstract textures only
200px + repeatTiles at a fixed sizePatterns

With cover, background-position decides which part survives the crop: center top keeps faces in portrait photos, center bottom keeps a horizon.

Making text readable on photos

White text on a busy photo usually fails WCAG contrast somewhere in the image. The overlay options stack a semi-transparent gradient above the image in the same background-image list (layers are drawn first-on-top), so no extra HTML is needed. A dark overlay of 40–60% is enough for most photos; the bottom fade keeps the top of the image bright for captions at the bottom. Always set a background-color close to the image's average colour so text stays readable while the image loads or if it fails.

Performance

FAQ

Why doesn't my background image show?

The element has no height (backgrounds do not give an element size; add min-height), the path is relative to the CSS file rather than the page, or the URL needs quotes because it contains spaces or parentheses.

Can I use several background images?

Yes. Separate them with commas in background-image; the first one is drawn on top, which is how the overlay works.