Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →CSS masks control which parts of an element show and how opaque they appear. Use mask-image with a gradient for a quick fade, or use an image or SVG when the mask needs a particular shape. In alpha mode, opaque mask areas reveal the element, transparent areas hide it, and partial transparency creates a soft transition.
How CSS masking works
A mask affects an element’s visibility across its area: each point in the mask determines how much of the corresponding point in the element is shown. In alpha mode, the mask’s transparency determines visibility; its color is irrelevant. This makes a mask useful for fades and partially transparent edges that a simple shape cannot provide. MDN’s introduction to CSS masking explains the model and the available source types.
A mask source can be a CSS gradient, a raster image such as a PNG or JPEG, or an SVG <mask>. SVG masks can be referenced from an external SVG or from an inline fragment. Choose the source according to the effect: gradients are convenient for fades, image transparency can define a silhouette, and SVG can describe authored vector mask artwork.
Use mask-image for a gradient fade
This example keeps the upper part of an image visible and fades it out toward the bottom:
#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
.fade-image {
/* The opaque portion reveals; the transparent portion hides. */
mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
mask-mode: alpha;
}
The explicit mask-mode: alpha makes the intended interpretation clear. In alpha mode, opaque black is visible because it is opaque—not because it is black. The transparent end hides the image, with intermediate gradient values producing partial visibility. For an image mask, the source image’s alpha channel can similarly define which parts appear.
Choose alpha or luminance mode
Mask mode determines how the source becomes opacity. Alpha mode uses transparency. Luminance mode uses the source’s brightness together with its alpha: bright areas reveal more, while dark areas reveal less. A fully opaque grayscale image can therefore serve as a luminance mask—for example, white for visible and black for hidden.
The default match-source usually resolves to alpha for image sources, but SVG <mask> sources default to luminance unless configured otherwise. If the result depends on a particular interpretation, specify the mode with CSS mask-mode or set the SVG source’s mask-type as appropriate. See MDN’s mask-image reference for source behavior and details.
Use an SVG mask
An SVG mask is useful when the silhouette is easier to author as vector artwork than as a gradient or raster image. Reference an SVG mask source in mask-image; it may be an external SVG mask or an inline fragment. For example, an inline mask can be selected by its fragment ID:
<svg aria-hidden="true" width="0" height="0">
<defs>
<mask id="soft-circle">
<circle cx="50" cy="50" r="45" fill="white" />
</mask>
</defs>
</svg>
<img class="masked-image" src="photo.jpg" alt="A landscape">
.masked-image {
mask-image: url("#soft-circle");
mask-mode: luminance;
}
Here, the white circle reveals the image under luminance interpretation and the unpainted area hides it. In a production SVG, ensure the mask’s coordinate system and dimensions match the intended element; the snippet illustrates the source relationship rather than a universal sizing setup.
Size, position, and combine mask layers
Mask layers use comma-separated values. You can set properties such as mask-size, mask-position, and mask-repeat to control each layer, much as you would for background layers. Multiple mask sources can be combined with mask-composite; its operators are add, subtract, intersect, and exclude.
Rank #3
For example, an intersection keeps only the overlap of two layers:
.intersection-mask {
mask-image: linear-gradient(black, black),
radial-gradient(black 60%, transparent 61%);
mask-mode: alpha, alpha;
mask-composite: intersect;
}
The first listed layer is the linear gradient and the second is the radial gradient; intersect combines them so only their shared visible area remains. Layer ordering and the selected operator affect the outcome, particularly with subtraction and intersection. A none entry still occupies a layer position, so it can affect how comma-separated property values match up. MDN’s mask properties guide and mask-composite reference cover layer configuration and composition.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchMasking or clip-path?
Use clip-path when the design needs a straightforward hard-edged shape: each point is either visible or hidden. Use a mask when you need soft edges, partial opacity, luminance-controlled visibility, or multiple visual layers.
Rank #4
- 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
Clipping may perform better for basic shapes and can be easier to interpolate. As MDN puts it, “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.” Both operate after the element’s base styles are applied; MDN describes the effect order as filters, clipping, masking, then opacity. Read MDN’s CSS masking guide when deciding between the techniques.
Compatibility and production checks
MDN marks mask-image widely available and says it has been available across browsers since December 2023. That is not a guarantee that every mask-* subproperty or edge case behaves identically in every browser. Check compatibility data for the exact properties you use and test the actual browsers your site supports.
- Use the simplest source that achieves the visual effect; a gradient avoids needing an external mask asset for a basic fade.
- Make alpha or luminance behavior explicit when the source type or expected result could be ambiguous.
- Verify that referenced SVG and image resources load and that their dimensions and mask coordinates produce the intended visible region.
- Test the rendered result in target browsers, especially when combining layers or relying on less commonly used mask properties.
Troubleshoot a mask that hides everything
- The mask source fails to load: Check the URL, file availability, and whether the source is permitted. MDN notes that a missing or unsupported mask image behaves like transparent black, which can make the whole element disappear.
- The mask is interpreted with the wrong mode: Check whether the source is being read as alpha or luminance. Set
mask-modeexplicitly, or configure the SVG mask’smask-typewhen alpha behavior is required. - An external image or SVG is blocked: Image mask sources are subject to HTTP/HTTPS and CORS-related restrictions; local
file://URLs are not accepted as image values. Serve the asset from an appropriate web origin and check its access policy. - A layered mask has an unexpected shape: Inspect the comma-separated layer order, each layer’s size and position, and the composite operator. Remember that
nonestill takes a layer slot. - A gradient appears reversed or invisible: In alpha mode, inspect opacity rather than hue: opaque regions reveal and transparent regions hide. Confirm the gradient stops and direction correspond to the desired visible area.
Or skip the browser setup
If you want to inspect a rendered page with your CSS in place, you can request a screenshot from ScreenshotNeo instead of setting up a browser capture flow. Its API can return a screenshot in PNG, JPEG, or WebP, or a PDF. For an existing page URL, a basic call is:
Recommended Free Tools
Best Value
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
See the ScreenshotNeo API documentation for request options. ScreenshotNeo accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; these steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers say which page verdict applied and whether the request was billed. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots. Sign up for free to try it.
Frequently Asked Questions
Does a CSS mask change the element’s layout size?
A mask controls rendered visibility; it is not a layout-sizing property. Keep the element’s dimensions and positioning separate from the masked appearance.
Can I use a mask on text as well as images?
Masks apply to elements, so they can affect text and other element content, not only image pixels.
Quick Recap
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.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.

