CSS propertyEffects

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)"
On this page

Example

#
CSS
.scroller {
  overflow-x: auto;
  mask-image: linear-gradient(to right, black 80%, transparent);
}
Preview

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

#
Syntax
mask-image: none | url(…) | <gradient> [, …]*;

Values

#

Values in practice

#

none

No mask, the element is fully visible.
.demo { mask-image: none; }

linear-gradient(black, transparent)

The image gradually disappears towards the bottom.
.demo { mask-image: linear-gradient(black, transparent); }

radial-gradient(circle, black 40%, transparent 70%)

A visible centre and faded edges.
.demo { mask-image: radial-gradient(circle, black 40%, transparent 70%); }

linear-gradient(to right, black 70%, transparent)

A faded right edge.
.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-image prefix.

Related entries

#

Spotted a mistake or missing an example? Write to us.