CSS Background Image Generator
Generate CSS background-image code — set the image URL, size (cover, contain or custom), position, repeat and attachment, add a color or gradient overlay for readable text, and copy the CSS with a live preview.
Input
An absolute https:// URL, a path on your own site, or a data:image URI.
Cover fills the box (may crop), contain shows the whole image (may letterbox).
Shown while the image loads, or if it fails.
A gradient layer stacked above the image so text on top stays readable.
Only used for the preview and HTML snippet. Leave blank for none.
Output
Your background will appear here.
More ways to use this tool
REST API
curl -X POST https://api.iotools.cloud/v1/tool/css-background-image-generator \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"imageUrl": "https://images.unsplash.com/photo-1506744038136-…",
"size": "cover",
"customSize": "50",
"position": "center",
"repeat": "no-repeat",
"attachment": "scroll",
"fallbackColor": "#1e293b",
"overlay": "solid",
"overlayColor": "#000000",
"overlayOpacity": "40",
"height": "320",
"text": "Hello, background!"
}'Swap in your own key from your account. The tool's fields are the body — no wrapper.
Ask an AI agent
Use the IOTools `css-background-image-generator` tool (CSS Background Image Generator) on this input:
YOUR_INPUT_HEREPaste this at any agent connected to the IOTools MCP server, then add your input.
Embed widget
<iframe
src="https://iotools.cloud/embed/css-background-image-generator/"
width="100%" height="520" frameborder="0" scrolling="no" loading="lazy"
title="CSS Background Image Generator — iotools.cloud"
sandbox="allow-scripts allow-forms allow-same-origin allow-downloads allow-popups allow-popups-to-escape-sandbox"
allow="clipboard-write"
style="width:100%;border:1px solid #e5e7eb;border-radius:12px;overflow:hidden"></iframe>
<script src="https://iotools.cloud/embed.js" async></script>Drop this into your own page — free, no key required, just a link back.
| Cost per API/MCP call | From 5 credits |
|---|---|
| Need more credits? | View pricing |
Also available with
Guides
Build the CSS for a background image visually — pick the image, choose how it scales, where it sits and whether it tiles, then copy a ready-to-paste rule. A live preview shows the result on a sample box as you change each setting.
Everything is generated in your browser: no upload, no signup, no AI. The image URL you enter is only loaded by your own browser for the preview.
How to use it
- Paste an Image URL — an absolute
https://link, a path on your own site such as/images/hero.jpg, or adata:image/...URI. - Choose the Size:
coverfills the whole box and crops the overflow,containshows the entire image and may leave empty bands,autokeeps the image's natural size, and Custom (%) sets the width as a percentage of the box. - Set the Position (which part of the image stays visible when it's cropped), Repeat and Attachment.
- Optionally add an Overlay — a solid tint or a fade — so white text on top of a busy photo stays readable.
- Copy the
backgrounddeclarations on their own, or the full CSS and HTML snippet.
Settings explained
- Repeat —
no-repeatfor photos;repeat,repeat-xorrepeat-yfor tiling patterns.spacetiles without cropping and spreads the gaps evenly,roundstretches tiles slightly so a whole number fits. - Attachment —
scrollmoves with the element (the default).fixedpins the image to the viewport for a simple parallax effect; note that most mobile browsers ignore it.localscrolls the image along with the element's own scrollable content. - Fallback Color — the
background-colorpainted underneath the image. It shows while the image is loading or if it fails, and it keeps text contrast acceptable in the meantime. - Overlay — added as a
linear-gradient()layer stacked above the image in the samebackground-imageproperty. The generator writes comma-separated values for size, position, repeat and attachment so the overlay always covers the whole box, whatever you choose for the image.
Why does my image not show in the preview?
The preview loads the image straight from the URL you gave it. If the host blocks hot-linking, the link needs a login, or the path is relative to your own site, the box falls back to the fallback color — the generated CSS is still correct for your page.
Can I embed the image in the CSS instead of linking it?
Yes — convert the file to a data URI with the CSS Data URI Converter and paste the result into the Image URL field. For a background with no image at all, use the CSS Gradient Generator or the CSS Background Pattern Generator.