How can I apply a mask from an inline SVG that can work in Chrome?
How can I apply a mask from an inline SVG that can work in Chrome?
30321-Jul-2023
Updated on 21-Jul-2023
Home / DeveloperSection / Forums / How can I apply a mask from an inline SVG that can work in Chrome?
How can I apply a mask from an inline SVG that can work in Chrome?
Aryan Kumar
21-Jul-2023Here are the steps on how to apply a mask from an inline SVG that can work in Chrome:
maskUnits
andmaskContentUnits
properties of the mask element toobjectBoundingBox
. This will ensure that the mask is applied to the object in the same way, regardless of its size or position.id
attribute of the mask element to a unique value. This value will be used to reference the mask in the CSS.mask
property of the masked element to the ID of the mask element that you created in step 3.Here is an example of how you can apply a mask from an inline SVG that can work in Chrome:
HTML
In this example, we have created an SVG mask element with a black rectangle. We have then created an SVG circle element and set its
mask
property to the ID of the mask element. The result is that the circle will be masked by the black rectangle.This technique will work in Chrome, Firefox, and most other modern browsers. However, it is important to note that some older browsers may not support SVG masks.