A background overlay darkens, lightens, or tints a background image to make overlaid text readable and to give photographic content a deliberate brand tone.
Loading Background Gen…
Generates pseudo-element overlay with position: absolute
Supports rgba solid overlays and gradient overlays
Multiple background stacking approach also generated
Live preview of overlay opacity and colour on a background image
Drop the Background Gen into any page — blog post, product docs, intranet, school portal — with a single line of HTML. Your visitors get the full tool, processed entirely in their browser. No backend, no uploads, no signup.
Embed code
<iframe
src="https://www.fixtools.io/css-tool/background-gen?embed=1"
width="100%"
height="780"
frameborder="0"
style="border:0;border-radius:16px;max-width:900px;"
title="Background Gen by FixTools"
loading="lazy"
allow="clipboard-write"
></iframe>Attribution-friendly: a small "Powered by FixTools" link appears in the embed footer.
The background shorthand overlay method stacks a semi-transparent gradient or rgba layer above the image using comma-separated layers, and the first layer listed paints on top of every subsequent layer. background: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url("photo.jpg") center/cover no-repeat is the canonical example. The approach is concise, requires no additional HTML, and adds zero extra CSS rules to your stylesheet. The limitation is that the overlay applies to the element background only: child content within the element is not tinted or darkened, only the background layer is. Adjusting the rgba transparency directly controls overlay density. A gradient overlay running from rgba(0,0,0,0.7) at the bottom to transparent at the top provides more refined control than a flat overlay when the text sits at the bottom of the element.
The pseudo-element overlay uses ::before with position: absolute and inset: 0, which is the modern shorthand for top: 0; right: 0; bottom: 0; left: 0 all at once. The parent element must have position: relative to contain the absolute pseudo-element inside its own box. Set a z-index on the overlay and a higher z-index on the content wrapper to ensure the overlay sits between the background and the text in the stacking context. This approach allows the overlay to carry its own background, border, blend mode, and animation independently of the element background. You can transition the overlay opacity on hover without affecting the underlying image, which is not possible with shorthand stacking because the entire background property would need to interpolate.
Multiple background stacking with rgba colours handles non-gradient overlays efficiently and reads cleanly in code review. background: rgba(79, 70, 229, 0.4), url("photo.jpg") center/cover applies a semi-transparent indigo tint over the image with a single declaration. CSS treats solid rgba colours in background layers as infinitely-sized gradient images for stacking purposes, so the syntax works exactly like layering gradient layers. Adding multiple colour layers creates blended overlays: background: rgba(0, 0, 0, 0.3), rgba(79, 70, 229, 0.2), url("photo.jpg") center/cover stacks a black darkening layer and a colour tint above the image. The order of layers determines which tint applies on top and how the resulting tone composites with the image beneath.
Pointer events and accessibility are easy to overlook when adding overlays. A pseudo-element overlay with a higher z-index than child content will swallow click events on buttons and links unless you set pointer-events: none on the overlay. Adding pointer-events: none keeps the overlay purely visual while letting clicks pass through to the content below. For accessibility, overlays should never be the only mechanism that makes text readable: if the overlay fails to load due to a connection issue or a custom user stylesheet, the text must still pass contrast against the underlying image. Always set a fallback background-color on the element so the text remains readable even before the image arrives or if the image fails entirely.
Enter a background image URL and choose an overlay type: solid rgba colour, gradient, or pseudo-element. Set the overlay colour and opacity using the sliders. The tool generates either the background shorthand with stacked layers or the ::before pseudo-element CSS depending on your selection.
Step-by-step guide to css background overlay generator:
Enter the background image URL
Paste the image URL from your CDN or local asset path. The preview renders the image at full container width with cover sizing, so you can immediately see how the overlay will read against the actual photograph rather than against a placeholder you will need to replace later.
Choose overlay approach
Select background stacking or pseudo-element based on whether you need interactivity. Background stacking is the simplest possible overlay for static decoration. The pseudo-element approach is required if you want hover transitions, blend mode tinting, scroll-bound animation, or pointer-events control on the overlay layer.
Set overlay colour and opacity
Choose the overlay colour with the colour picker and drag the opacity slider to find the right balance. Use a darker opacity for light text readability and a lighter opacity for subtle brand tints. The preview updates in real time, so you can iterate until the headline reads clearly against every part of the underlying image.
Copy the CSS output
Copy the generated CSS in one click. For the pseudo-element approach, the output includes both the parent element rules and the ::before rules with proper positioning, z-index, and pointer-events declarations. Paste into your stylesheet and the overlay renders identically to the preview.
Common situations where this approach makes a real difference:
Developer adding a tinted overlay for a team section
A developer needs to apply a brand-colour tint to team member photographs in a grid layout so the section reads cohesively despite the photos being shot in different studios over two years. They use the pseudo-element overlay with background: rgba(79, 70, 229, 0.4) and mix-blend-mode: multiply to tint each photograph indigo on hover. The ::before overlay transitions from opacity: 0 to opacity: 1 on :hover with a 0.3s ease transition, creating a smooth colour reveal when hovering each team card while leaving the unhovered cards in full colour.
Designer applying a gradient overlay for a text-heavy hero
A designer creates a hero section with a bright sunlit landscape photograph and a dark serif headline that must read clearly without sacrificing the brightness of the image. To prevent the headline from being lost against a light sky, they apply a directional gradient using linear-gradient(to bottom, rgba(0,0,0,0.65) 0%, transparent 60%) stacked above the image in the background shorthand. The gradient darkens only the top 60% of the section where the headline sits while the lower image area stays bright, preserving the photographic impact of the scene.
Accessibility engineer verifying text contrast on overlaid backgrounds
An accessibility engineer needs to confirm that white headline text on a hero with a 50% black overlay passes WCAG AA across the full range of images the marketing team rotates through. They sample the brightest image tone under the overlay using a colour picker, calculate the effective composited background luminance, and check the contrast ratio against pure white text. The 50% overlay produces 7.2:1 on the brightest test image, which passes AAA comfortably. They document the minimum overlay opacity required for AA compliance and add it to the design system guidelines so future marketing assets stay compliant.
Student learning CSS stacking context with overlays
A student creates a card with a ::before pseudo-element overlay but the overlay covers the card title text so the headline disappears under a translucent black layer. The tool shows them they need position: relative on the text wrapper and a z-index higher than the overlay to bring the text above the pseudo-element in the stacking context. Without position: relative on the content, z-index has no effect at all and the overlay stays on top of the text. Seeing the fix demonstrated visually clarifies why z-index requires a positioned ancestor to participate in the stacking context.
Get better results with these expert suggestions:
Use mix-blend-mode on a pseudo-element for colour tinting
Set the pseudo-element background to a solid brand colour and add mix-blend-mode: multiply. The colour multiplies with the image pixels beneath, creating a duotone-style tint effect. Black areas in the image stay black, lighter areas take on the overlay colour, and the result preserves contrast and shape rather than flattening into a uniform tint. This is far more visually refined than an rgba veil for brand-coloured overlays and reads as intentional design.
Use inset shorthand instead of four position values
inset: 0 is equivalent to top: 0; right: 0; bottom: 0; left: 0 and reduces four lines of boilerplate to a single declaration on every pseudo-element overlay. inset is supported in all modern browsers since 2021 and reads more clearly in code review. Include the four-value fallback only if your browser support matrix still includes pre-2021 browsers that you cannot drop, which is rare in 2026.
Animate overlay opacity for image reveal effects
Set the ::before overlay to opacity: 1 by default and transition to opacity: 0 on hover, which produces an image reveal effect where hovering an element fades out a colour overlay to show the full-colour image beneath. Combine with transition: opacity 0.5s ease for a smooth reveal that feels deliberate rather than abrupt. The technique is the foundation of most modern hover-reveal portfolio grids and works without any JavaScript at all.
Test overlay at the WCAG contrast minimum for text
After applying the overlay, measure the effective background colour at the exact point where text sits rather than at an arbitrary point on the image. Use a colour picker tool to sample the darkened image tone under the overlay and check the resulting contrast ratio against the text colour using a WCAG contrast checker. A 50% black overlay on a mid-grey image may still not reach 4.5:1 for small body text, and the deficit is invisible until you measure.
Use pseudo-element overlay for hover transitions
A ::before pseudo-element overlay allows transition: opacity 0.3s ease on hover. The image remains unchanged while the overlay fades in or out. Background shorthand stacking cannot transition individual layers independently.
Set z-index on content above pseudo-element overlay
A ::before overlay at z-index: 1 will cover content unless the content wrapper has z-index: 2 and position: relative. Without this, the overlay blocks pointer events and covers text even though it appears behind visually in some browsers.
Use directional gradients instead of flat overlays
A flat rgba overlay at 50% opacity applies the same darkening to the entire image. A gradient overlay from dark at the bottom to transparent at the top darkens only the text area while leaving the rest of the image more visible, which looks more polished.
More use-case guides for the same tool:
Other tools you might find useful:
Open the full Background Gen — free, no account needed, works on any device.
Open Background Gen →Free · No account needed · Works on any device