mask-image
Uses an image or gradient as a transparency mask for an element.
- Initial value
none- Inherited
- No
- Animatable
- no
- Applies to
- all elements
- JavaScript
element.style.maskImage = "linear-gradient(black, transparent)"
Example
#.scroller {
overflow-x: auto;
mask-image: linear-gradient(to right, black 80%, transparent);
}<div style="display: flex; gap: 8px; overflow-x: auto; mask-image: linear-gradient(to right, black 80%, transparent); -webkit-mask-image: linear-gradient(to right, black 80%, transparent);">
<span class="box">HTML</span><span class="box">CSS</span><span class="box">JavaScript</span><span class="box">TypeScript</span><span class="box">Python</span><span class="box">React</span>
</div>Definition and usage
#The mask-image property defines a mask: where the mask is opaque the element is visible, and where it is transparent the element disappears. Unlike clip-path, a mask can have smooth transitions.
The most common use is a linear gradient that gradually fades the element at an edge, for example the end of a scrollable list or a photo fading into the background.
The mask-size, mask-position and mask-repeat properties work like their background counterparts. A mask from an SVG or PNG file lets you give an element any shape.
Syntax
#mask-image: none | url(…) | <gradient> [, …]*;Values
#- No mask, the element is fully visible.
linear-gradient(black, transparent)
fade out
The image gradually disappears towards the bottom.radial-gradient(circle, black 40%, transparent 70%)
vignette
A visible centre and faded edges.linear-gradient(to right, black 70%, transparent)
edge
A faded right edge.
Values in practice
#none
.demo { mask-image: none; }linear-gradient(black, transparent)
.demo { mask-image: linear-gradient(black, transparent); }radial-gradient(circle, black 40%, transparent 70%)
.demo { mask-image: radial-gradient(circle, black 40%, transparent 70%); }linear-gradient(to right, black 70%, transparent)
.demo { mask-image: linear-gradient(to right, black 70%, transparent); }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- A faded edge on a scrollable strip is a subtle hint that there is more content there.
- For older browsers add a version with the
-webkit-mask-imageprefix.
Related entries
#Spotted a mistake or missing an example? Write to us.