CSS mask-image Property

Beginner
⏱️ 7 min read
📚 Updated: Jun 2026
🎯 4 Examples
Visual Effects

What You’ll Learn

The mask-image property defines an image or gradient mask that controls which parts of an element stay visible — ideal for soft fades, custom silhouettes, and creative visual effects.

01

Alpha Mask

Hide by transparency.

02

url()

PNG or SVG masks.

03

Gradients

Soft fade effects.

04

none Default

Fully visible.

05

WebKit

Prefix for Safari.

06

Related

mask-size, mode.

Introduction

The mask-image property in CSS allows you to define an image as a mask for an element. It can partially or fully hide parts of the element’s content based on the mask’s transparency.

Masks work by controlling the visibility of each pixel: a transparent mask pixel hides the corresponding part of the element, and an opaque mask pixel keeps it visible. This is especially useful for complex visual effects and shapes without extra SVG markup.

Definition and Usage

Apply mask-image when you want soft edges, image-based silhouettes, or gradient fades. Pair it with related properties like mask-size and mask-repeat to position and scale the mask.

💡
Beginner Tip

Start with a linear-gradient() mask for a simple top-to-bottom fade, then try url() with a PNG silhouette for shaped reveals.

📝 Syntax

The syntax for the mask-image property allows URLs to images, CSS gradients, and the keyword none:

syntax.css
element {
  mask-image: value;
}

Basic Example

mask-image.css
.masked-image {
  width: 300px;
  height: 300px;
  background-image: url('/images/valley-pattern.jpg');
  -webkit-mask-image: url('/images/apple.png');
  mask-image: url('/images/apple.png');
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

Syntax Rules

  • The initial value is none (no mask applied).
  • url() points to a PNG, SVG, or other image used as the mask layer.
  • Gradients like linear-gradient() and radial-gradient() create soft masks without image files.
  • Include -webkit-mask-image alongside mask-image for broader Safari support.
  • Often combined with mask-size, mask-position, and mask-repeat.

⚡ Quick Reference

QuestionAnswer
Initial valuenone
Applies toAll elements
InheritedNo
AnimatableYes, when interpolable
Common useImage silhouettes, gradient fades, textured reveals

💎 Property Values

The mask-image property accepts image URLs, gradients, or none.

ValueExampleMeaning
nonemask-image: none;No mask is applied. The element is fully visible.
url()mask-image: url('mask.png');Uses an image file as the mask layer.
Gradientmask-image: linear-gradient(black, transparent);Uses a CSS gradient as a soft mask.
initialmask-image: initial;Resets to the default value (none)
inheritmask-image: inherit;Inherits the mask value from the parent element
none url() linear-gradient() radial-gradient()

🎯 Default Value

The default value of the mask-image property is none, meaning no mask is applied and the element is fully visible.

Common Mask Sources

TypeExampleUse case
Image URLurl('/images/apple.png')Custom silhouettes, logos, and textured cutouts
Linear gradientlinear-gradient(to bottom, #000, transparent)Top-to-bottom fades and scroll reveals
Radial gradientradial-gradient(circle, #000 40%, transparent 70%)Spotlight, vignette, and circular reveals
SVG referenceurl(#myMask)Complex vector masks defined inline in SVG

👀 Live Preview

The same gradient block with three mask types — linear fade, radial spotlight, and PNG silhouette:

linear-gradient fade
radial-gradient
url(apple.png)

Examples Gallery

Mask a background with a PNG image, create gradient fades, build radial spotlights, and compare masking with clipping.

🖼 Image Masks

Start with the reference example — use a PNG image as a mask over a background.

Example 1 — Image with PNG Mask

Use an image mask to partially hide a background. Transparent parts of the mask hide the corresponding background areas.

mask-image.html
<style>
  .masked-image {
    width: 300px;
    height: 300px;
    background-image: url('/images/valley-pattern.jpg');
    background-size: cover;
    -webkit-mask-image: url('/images/apple.png');
    mask-image: url('/images/apple.png');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
  }
</style>

<div class="masked-image"></div>
Try It Yourself

How It Works

The background fills the box. The PNG mask controls visibility — opaque mask pixels show the background, transparent pixels hide it.

Example 2 — Linear Gradient Fade

Use a gradient as the mask to create a smooth top-to-bottom fade without an image file.

mask-image-linear.html
<style>
  .fade-box {
    width: 240px;
    height: 160px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    -webkit-mask-image: linear-gradient(to bottom, #000 30%, transparent);
    mask-image: linear-gradient(to bottom, #000 30%, transparent);
  }
</style>

<div class="fade-box"></div>
Try It Yourself

How It Works

Black areas in the gradient keep the element visible; transparent areas fade it out. This is a common scroll-reveal and hero-section technique.

🛠 Gradient & Comparison

Build radial spotlight masks and understand how masking differs from clipping.

Example 3 — Radial Spotlight Mask

A radial gradient mask creates a circular visible area with soft edges.

mask-image-radial.html
<style>
  .spotlight {
    width: 220px;
    height: 160px;
    background: linear-gradient(135deg, #16a34a, #059669);
    -webkit-mask-image: radial-gradient(circle, #000 35%, transparent 72%);
    mask-image: radial-gradient(circle, #000 35%, transparent 72%);
  }
</style>

<div class="spotlight"></div>
Try It Yourself

How It Works

The radial gradient defines a soft circular window. Adjust color stops to control the size and softness of the visible area.

Example 4 — mask-image vs clip-path

Both hide parts of an element, but they work differently:

mask-vs-clip.css
/* Soft gradient mask */
.masked {
  mask-image: linear-gradient(to right, #000, transparent);
}

/* Hard geometric clip */
.clipped {
  clip-path: circle(50%);
}
Try It Yourself

How It Works

mask-image supports soft alpha fades from gradients and images. clip-path cuts hard geometric edges — choose based on the effect you need.

♿ Accessibility

  • Do not hide essential content — Masked-away text or controls may be invisible but still exist in the DOM.
  • Provide alt text for images used as visible content, even when masked decoratively.
  • Test contrast — Gradient fades can reduce readability if text sits over masked areas.
  • Check pointer events — Hidden mask areas may still receive clicks unless you adjust interaction.
  • Offer fallbacks — Ensure content remains usable when masking is unsupported.

mask-image vs clip-path

Featuremask-imageclip-path
Edge typeSoft alpha fades from images and gradientsHard geometric edges
SourcesPNG, SVG, CSS gradientscircle(), polygon(), inset(), SVG path
Best forSilhouettes, vignettes, textured revealsAvatars, triangles, precise shape cuts
Related propsmask-size, mask-repeat, mask-modeStandalone shape property

🧠 How mask-image Works

1

You define a mask source

Choose a PNG, SVG, or CSS gradient with mask-image.

Mask source
2

Browser maps alpha values

Each mask pixel controls visibility of the matching element pixel.

Alpha mapping
3

Transparent areas hide content

Opaque mask pixels stay visible; transparent pixels reveal whatever is behind the element.

Compositing
=

Shaped or faded reveal

Your element appears through custom silhouettes, soft fades, or spotlight effects.

🖥 Browser Compatibility

The mask-image property is supported in most modern browsers, including Chrome, Firefox, Safari, and Edge. Include -webkit-mask-image for Safari, and test your target browser versions.

Baseline · Modern browsers

Masking in modern browsers

Image and gradient masks work in all major browsers. Use the WebKit prefix for best Safari coverage.

95% Modern browser support
Google Chrome 55+ · Desktop & Mobile
Full support
Mozilla Firefox 54+ · Desktop & Mobile
Full support
Apple Safari 9.1+ · macOS & iOS
Full support
Microsoft Edge 79+ · Chromium
Full support
Opera 42+ · Modern versions
Full support
mask-image property 95% supported

Bottom line: Safe for modern projects. Pair mask-image with -webkit-mask-image and test PNG masks in Safari.

🎉 Conclusion

The mask-image property is a powerful tool for creating visually stunning effects by manipulating element visibility with masks.

Whether you’re creating custom shapes, hiding parts of an image, or applying soft gradient fades, this property offers a flexible solution. Experiment with different masks and see how you can enhance your web designs with this technique.

💡 Best Practices

✅ Do

  • Use url() PNG masks for custom silhouettes and logos
  • Try gradient masks for soft fades without extra image files
  • Include -webkit-mask-image alongside mask-image
  • Pair with mask-size and mask-repeat for proper positioning
  • Use clip-path when you need hard geometric edges instead

❌ Don’t

  • Hide essential text or controls with masks
  • Assume masked-away areas block pointer events by default
  • Forget WebKit prefixes when targeting Safari users
  • Skip fallbacks for critical visible content
  • Use masking when a simple border-radius or clip-path would suffice

Key Takeaways

Knowledge Unlocked

Five things to remember about mask-image

Use these points when applying image and gradient masks.

5
Core concepts
02

none Default

Fully visible.

Default
url 03

Image masks

PNG silhouettes.

Values
grad 04

Gradients

Soft fades.

Technique
web 05

WebKit prefix

Safari support.

Compat

❓ Frequently Asked Questions

The mask-image property defines an image or gradient used as a mask. Transparent areas of the mask hide the corresponding parts of the element; opaque areas keep them visible.
The default value is none, meaning no mask is applied and the element is fully visible.
mask-image hard-cuts an element to a geometric shape. mask-image uses alpha or luminance from an image or gradient for softer, more complex visibility effects.
Yes. linear-gradient() and radial-gradient() are common mask values for fades, vignettes, and soft edges without extra image files.
Safari historically required the -webkit- prefix. Include both mask-image and -webkit-mask-image in production CSS for the widest support.

Practice in the Live Editor

Open the HTML editor, try mask-image with gradients and PNG masks, and preview effects instantly.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful