Tools

Home
JSON FormatterSQL FormatterJS ValidatorMinify CSS
Merge PDFCompress PDFImage to PDF
JPG to PNGPNG to WebPCrop Image

CSS Background Image Generator

Upload an image, paste a URL, or create a gradient and generate CSS background properties with live preview

Your files never leave your browser
ControlsLayer 1 of 1
Preview & Code
xpx
/* Adjust settings to generate CSS */
Ready·0 layers

Pick your image source — file upload, URL, or CSS gradient — then adjust size, position, repeat, and attachment with visual controls. Stack up to three background layers with blend modes, and copy the generated CSS when the preview looks right. And everything runs in your browser. Nothing gets uploaded.

How It Works

Pick Image Source
→
Adjust Properties
→
Copy CSS Output

Choose between uploading a file, pasting a URL, or creating a CSS gradient. Then set size, position, repeat, attachment, and blend mode using dropdowns — the live preview reflects each change immediately. Toggle between longhand and shorthand syntax in the code output, and copy it straight into your stylesheet.

Examples

Full-bleed hero image

You need a photo that fills the entire hero section without distortion, centered on the subject.

INPUT
Image: hero-banner.jpg Size: Cover Position: Center Repeat: No-repeat Attachment: Scroll
OUTPUT
background-image: url("hero-banner.jpg"); background-size: cover; background-position: center; background-repeat: no-repeat; background-color: #ffffff;

Repeating texture pattern

A small tile image that repeats across the entire background — common for subtle textures like paper grain or dots.

INPUT
Image: dots-pattern.png Size: 40px 40px (custom) Position: Top Left Repeat: Repeat
OUTPUT
background-image: url("dots-pattern.png"); background-size: 40% 40%; background-position: top left; background-repeat: repeat; background-color: #f8f8f8;

Gradient overlay on a photo

Two layers: a semi-transparent gradient on top, a photo underneath. Creates that dark-to-transparent fade you see on card headers everywhere.

INPUT
Layer 1: Linear gradient 180deg, #000000 → #00000000 Layer 2: Upload photo.jpg Size: Cover, Position: Center Blend Mode: Normal
OUTPUT
background-image: linear-gradient(180deg, #000 0%, transparent 100%), url("photo.jpg"); background-size: cover, cover; background-position: center, center; background-repeat: no-repeat, no-repeat; background-color: #1a1a1a;

Who Uses This

👨‍💻 Front-End Developers

Generate multi-layer background CSS without memorizing every property name and comma-separated syntax.

🎨 Web Designers

Preview hero sections and card backgrounds visually before handing off pixel-perfect CSS to dev teams.

📝 Content Creators

Style blog headers and landing pages with background images — no CSS knowledge required.

🎓 Students

Learn how background-size, background-position, and background-repeat actually behave by experimenting live.

Common Mistakes

Using the base64 data URI in production

The generator creates a data URI so you can preview locally. But data URIs bloat your HTML and aren't cached by browsers. Host the image on a CDN and replace the data URI with the real URL before deploying.

Forgetting the fallback background-color

If your image fails to load or takes too long, users see a blank box. Always set a fallback color that's close to the dominant color in your image. The generator includes one by default — don't delete it.

Setting background-attachment: fixed on mobile

iOS Safari and some Android browsers ignore background-attachment: fixed entirely. Your parallax effect won't work on most phones. Use scroll as the default and only add fixed behind a media query targeting larger screens.

Technical Details

Frequently Asked Questions

What's the difference between background-size cover and contain?

cover stretches the image until it fills the container completely — parts get cropped if the aspect ratios don't match. contain fits the whole image inside without cropping, so you might see empty space on the sides. Most hero sections use cover. Use contain when the full image needs to be visible, like a product photo.

Can I layer multiple background images in CSS?

Yes, and it's more useful than most people realize. CSS lets you stack backgrounds using comma-separated values — the first one sits on top. This generator supports up to 3 layers. A common pattern is putting a semi-transparent gradient over a photo so text stays readable.

Does background-attachment fixed work on mobile?

Mostly no. iOS Safari ignores it entirely, and several Android browsers do the same. If you want a parallax-style effect on mobile, you'll need JavaScript or a CSS transform workaround. Stick with scroll for mobile and add fixed only inside a min-width media query.

Should I use shorthand or longhand background CSS?

Longhand is easier to read and debug — each property on its own line. Shorthand saves bytes but it resets any property you don't explicitly set, which trips people up all the time. For multi-layer backgrounds, longhand is almost always the safer pick. This generator gives you both options.

Is my uploaded image sent to a server?

No. Everything happens in your browser. The image is read as a base64 data URI using the File API — nothing gets uploaded anywhere. The data URI is only for the live preview. Before shipping to production, replace it with a proper hosted URL so your page stays fast.

Share: