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.
Set up a background image with the right size, position and overlay, preview it with text on top, and copy the CSS.
| Value | Result | Use for |
|---|---|---|
cover | Fills the whole box, cropping the overflow | Hero sections, banners, full-screen backgrounds |
contain | Whole image visible, empty space around it | Logos, product shots, illustrations |
auto | Natural size | Small decorative images |
100% 100% | Stretched to fit, distorting the image | Abstract textures only |
200px + repeat | Tiles at a fixed size | Patterns |
With cover, background-position decides which part survives the crop: center top keeps faces in portrait photos, center bottom keeps a horizon.
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.
<img> with fetchpriority="high" and object-fit: cover, which also lets you add alt text.background-attachment: fixed creates a parallax effect but repaints on scroll and is ignored on iOS Safari; the generated CSS includes a fallback.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.
Yes. Separate them with commas in background-image; the first one is drawn on top, which is how the overlay works.