🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to CSS Notes
Topic #154

Masking - SVG


CSS SVG Mask Layers

The SVG <mask> element can be used to apply a mask to an image.

Here, we use the SVG <mask> element to create different mask layers for an image.


SVG Mask Layer - Circle

The SVG <circle> element is used to create a circle.

Example

    <svg width="600" height="400" xmlns="http://www.w3.org/2000/svg">

    <mask id="svgmask1">
    <circle r="150" cx="200" cy="200"
    fill="#ffffff" />
  </mask>
  <image
    xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="img_5terre.jpg"
    mask="url(#svgmask1)"></image>
</svg>

SVG Mask Layer - Ellipse

The SVG <ellipse> element is used to create an ellipse.

Example

    <svg width="600" height="400" xmlns="http://www.w3.org/2000/svg">

    <mask id="svgmask1">
    <ellipse cx="220" cy="150"
    rx="200" ry="100" fill="#ffffff" />
  </mask>
  <image
    xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="img_5terre.jpg"
    mask="url(#svgmask1)"></image>
</svg>

SVG Mask Layer - Triangle

The SVG <polygon> element is used to create a graphic that contains at least three sides.

Example

    <svg width="600" height="400"
    xmlns="http://www.w3.org/2000/svg">
  <mask id="svgmask1">

    <polygon fill="#ffffff" points="200 0, 400 400, 0 400"></polygon>

    </mask>
  <image xmlns:xlink="http://www.w3.org/1999/xlink"
    xlink:href="img_5terre.jpg" mask="url(#svgmask1)"></image>
</svg>

SVG Mask - Star

The SVG <polygon> element can also be used to create a star-shaped mask layer.

Example

  <svg width="600" height="400"
  xmlns="http://www.w3.org/2000/svg">
<mask id="svgmask1">

  <polygon fill="#ffffff" points="100,10 40,198 190,78 10,78
  160,198"></polygon>
</mask>
<image xmlns:xlink="http://www.w3.org/1999/xlink"
  xlink:href="img_5terre.jpg" mask="url(#svgmask1)"></image>

  </svg>

SVG Mask - Multiple Circles

Here we define three circles with different x and y positions.

Example

    <svg width="600" height="400"
    xmlns="http://www.w3.org/2000/svg">
  <mask
    id="svgmask1">
    <circle fill="#ffffff" cx="75" cy="75"
    r="75"></circle>
    <circle fill="#ffffff" cx="80"
    cy="260" r="75"></circle>
    <circle fill="#ffffff"
    cx="270" cy="160" r="75"></circle>
  </mask>
  <image
    xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="img_5terre.jpg"
    mask="url(#svgmask1)"></image>
</svg>

CSS All Masking Properties

The following table lists all the CSS masking properties:

Property Description
mask-clip Specifies which area is affected by a mask image
mask-composite Specifies a compositing operation used on the current mask layer with the mask layers below it
mask-image Specifies an image to be used as a mask layer for an element
mask-mode Specifies whether the mask layer image is treated as a luminance mask or as an alpha mask
mask-origin Specifies the origin position (the mask position area) of a mask layer image
mask-position Sets the starting position of a mask layer image (relative to the mask position area)
mask-repeat Specifies how the mask layer image is repeated
mask-size Specifies the size of a mask layer image
mask-type Specifies whether an SVG element is treated as a luminance mask or as an alpha mask

Want to go beyond the notes?

Join CodingNow 2.0's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Masking - SVG – FAQs

Quick answers about learning Masking - SVG in CSS.

This free note from CodingNow 2.0 explains Masking - SVG in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on CodingNow 2.0, including Masking - SVG, is 100% free with no signup required.
With focused practice, most students grasp Masking - SVG in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now