CSS mask fade generator — fade images and text out at the edges

Choose which edges should fade and how long the fade is, and the tool writes a gradient mask-image that makes that part of any element, image or text block gradually transparent.

Live demo · real result from this tool

Press Generate to create a result.

Processed on your device — nothing is uploaded.

How to use the CSS mask fade generator

  1. Pick the Fade: Bottom edge, Top edge, Right edge, Left edge, Top and bottom, Left and right, or All edges (radial).
  2. Set the Fade length from 5% to 100% of the element.
  3. Compare the faded sample photo against the white preview background.
  4. Copy the .fade rule and add the class to the element you want to fade.

What it does and when to use it

Fading an edge tells people there is more content, or softens an image so it blends into the page. Common uses are a long article preview that fades out above a “Read more” button, a horizontal scrolling row of cards whose left and right edges fade, a hero photo that melts into the background below it, and a soft vignette around a picture.

For a hard-edged shape instead of a soft fade, use the clip-path generator. To cut text to a fixed number of lines with an ellipsis, use the line clamp generator, and for the gradient syntax itself, see the CSS gradient generator.

How it works

The mask is a gradient from opaque #000 to transparent:

  • One edge uses linear-gradient(<direction>, #000 <100 − length>%, transparent 100%). With 35%, the first 65% is solid and the last 35% fades.
  • Two opposite edges use four stops: transparent at 0%, solid from the fade length to 100% minus it, and transparent again at 100%.
  • All edges uses radial-gradient(ellipse at center, #000 <70 − length>%, transparent 70%), so the element is fully hidden beyond 70% of the way out from the centre.

The tool writes the gradient twice, as -webkit-mask-image and mask-image. MDN lists mask-image as Baseline widely available since December 2023.

Worked examples

Default bottom fade:

.fade {
  -webkit-mask-image: linear-gradient(to bottom, #000 65%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 65%, transparent 100%);
}

A scrolling card row. Left and right, 10%: linear-gradient(to right, transparent 0%, #000 10%, #000 90%, transparent 100%). Cards slide in and out of view softly instead of being cut at the edge.

A soft vignette. All edges, 30%: radial-gradient(ellipse at center, #000 40%, transparent 70%). The centre 40% is untouched and the corners disappear completely.

Limits and tips

  • The fade length is a percentage of the element, so a tall element gets a taller fade. For a fixed height, change the stops to px by hand, for example #000 calc(100% - 80px).
  • Masks also hide focus rings and shadows near the faded edge. Keep buttons and links out of the fade.

Frequently asked questions

Why is the mask colour black?
A gradient mask works on transparency, not colour. Wherever the mask is opaque, black or any solid colour, the element shows; where it is transparent, the element is hidden. Black is simply the usual choice.
How is this different from putting a gradient over the image?
An overlay gradient fades towards a fixed colour, so it only looks right on a matching background. A mask makes the element itself transparent, so the real page background, a pattern or a photo shows through the fade.
What does Fade length mean for Top and bottom?
Each of the two edges fades over that length. 10% means the top 10% and the bottom 10% fade. Values above 50% are capped at 50%, so the fades meet in the middle.
Does masked text still exist for screen readers and search?
Yes. The mask only changes what is painted. The full text stays in the page, so make sure faded content is not something people must read, or offer a way to show it all.
Why does the CSS include -webkit-mask-image?
Some older browser versions only supported the prefixed property. The standard mask-image line comes second, so browsers that know it use it.

Sources

  1. mask-image - CSS | MDN — MDN Web Docs, accessed 2026-10-08

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close