Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk5 min

CSS Masking: How to Use Masks in Web Design

CSS masks control visibility from gradients, image transparency, or SVG artwork. Learn when to use alpha or luminance, how layers combine, and how masking compares with clip-path.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

CSS masks control which parts of an element show and how opaque they are. Use mask-image with a gradient, image, or SVG mask: opaque mask areas reveal the element, transparent areas hide it, and partial opacity creates a soft transition. For a sharp, all-or-nothing shape, clip-path is usually simpler.

How CSS masking works

A mask is applied to an element’s rendered appearance. In alpha mode, the mask’s transparency determines visibility: fully opaque areas reveal the element, fully transparent areas hide it, and intermediate alpha values partially reveal it. The mask’s color is irrelevant in alpha mode. MDN’s introduction to CSS masking explains the model and its available source types.

As an Amazon Associate I earn from qualifying purchases.

A mask source can be a CSS gradient, a raster image such as PNG or JPEG, or an SVG <mask>. Choose the source based on the effect: gradients are convenient for fades, image transparency can define a silhouette, and SVG can provide authored mask artwork.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a gradient mask for a fade

This example fades an image out at its lower edge. The gradient is opaque through 70% of the height and transitions to transparent at the bottom.

#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
.fade-image {
  mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
  mask-mode: alpha;
}

In alpha mode, black and any other fully opaque color reveal the element; transparency hides it. Use mask-mode: alpha explicitly when you want the gradient’s opacity—not its brightness—to determine the result.

Choose alpha or luminance mode

Alpha and luminance are two ways to turn a source into mask opacity. Alpha uses the source’s transparency. Luminance uses its brightness together with its alpha, so brighter pixels reveal more and darker pixels hide more. This makes luminance useful for a fully opaque grayscale source, such as white artwork on black.

The default match-source typically resolves to alpha for image sources, but an SVG <mask> defaults to luminance unless configured otherwise. If the distinction affects the design, set the mode deliberately with CSS mask-mode or the SVG mask’s mask-type. See MDN’s mask-image reference for source behavior and details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a raster image or SVG mask

Raster image with transparency

A PNG with transparent and opaque pixels can define a mask silhouette using its alpha channel. Point mask-image at the image and set mask-mode: alpha when alpha behavior needs to be unambiguous. Make sure the image is reachable from the page and served from an allowed origin.

SVG mask

An SVG mask may be referenced through an external SVG or an inline fragment. For an inline fragment, the mask source is a URL fragment such as url(#my-mask); the referenced SVG must define an element with that ID. Check the source’s mask type: SVG masks default to luminance unless you configure alpha behavior, so a mask that looks correct as artwork may produce an unexpected result under a different mode.

Mask images are subject to HTTP/HTTPS and CORS-related restrictions, and local file:// sources are not accepted as image values. If an image source is missing or unsupported, it behaves like transparent black, which can make the masked element disappear.

Masking versus clip-path

Use clip-path when the effect is a simple hard-edged shape: each point is either visible or hidden. Use masking when you need soft edges, partial transparency, brightness-driven visibility, or combined visual masks. MDN notes: “While masking provides more control and options, clipping can perform better if a basic shape is all that’s required — they are easier to interpolate.” See MDN’s CSS masking guide for the distinction.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Both techniques affect rendering after the element’s base styles are applied. MDN describes the effect order as filters, clipping, masking, then opacity. Prefer the simpler clipping approach when it expresses the design; use a mask when the extra control is needed.

Size, position, repeat, and combine mask layers

A mask layer can be adjusted with properties including mask-size, mask-position, and mask-repeat. Multiple sources can be supplied as comma-separated layers. Their order matters, especially when using compositing: the operator determines how one layer combines with another.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

The mask-composite operators are add, subtract, intersect, and exclude. A none entry still occupies a layer position, which matters when matching comma-separated layer properties. Keep the source and property lists aligned, and verify the visual result when changing layer order or operator. The MDN mask-properties guide and mask-composite reference cover these controls.

Compatibility and production checks

MDN marks mask-image widely available and says it has been available across browsers since December 2023. That summary does not mean every mask-* subproperty or edge case behaves identically in every target browser. Check compatibility for the exact properties you use and test the actual browsers your site supports. MDN’s compatibility data is the place to verify the current status.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot a mask that is not showing

  • The entire element disappears: confirm the mask URL or SVG fragment resolves and the source loads. A missing or unsupported mask image behaves like transparent black.
  • A grayscale SVG has the opposite or unexpected effect: check whether the source is using luminance. SVG <mask> sources default to luminance unless configured otherwise; set mask-mode or mask-type to match the intended behavior.
  • A transparent image reveals the wrong areas: verify that the source has the intended alpha channel and that alpha mode is selected when transparency should control visibility.
  • An external mask fails to load: check that it is served over HTTP or HTTPS and that cross-origin access permits its use. A local file:// path is not a supported image source.
  • Multiple layers combine unexpectedly: inspect comma-separated layer ordering, make sure related property lists align, and check the chosen mask-composite operator. Remember that none still takes a layer position.
  • It differs between browsers: check support for each masking property used, not only mask-image, and test the specific browsers and versions you need to support.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a screenshot of the finished page to check the mask, ScreenshotNeo can capture a URL with one GET request. Cookie banners are accepted and removed, along with known newsletter popups and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status in headers. Its MCP server lets AI agents use take_screenshot, get_page_info, and capture_pdf.

For a WebP screenshot, replace the example URL with your page and use your API key:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up free for ScreenshotNeo.

Frequently Asked Questions

Does a CSS mask change the element’s layout size?

No. A mask changes which rendered parts are visible; it does not define the element’s layout dimensions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I use CSS masking without an image file?

Yes. A CSS gradient can be the mask source, so a fade does not require a separate image asset.

Quick Recap

SaleBestseller No. 1
HTML and CSS: Design and Build Websites
HTML and CSS: Design and Build Websites
HTML CSS Design and Build Web Sites; Comes with secure packaging; It can be a gift option
$14.94
SaleBestseller No. 3
SaleBestseller No. 4
Web Design with HTML, CSS, JavaScript and jQuery Set
Web Design with HTML, CSS, JavaScript and jQuery Set
Brand: Wiley; Set of 2 Volumes
$35.05

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.