A way to achieve this is by assigning the HTML element a mask
property that points to a <mask>
element in your SVG file or a clip-path
property that refers to a <clipPath>
element within your SVG file.
.element {
/* For demonstration purposes: */
background-image: url(beach-sunset.jpg);
/* Choose one of the following: */
clip-path: url(waves.svg#myClipPath);
mask: url(waves.svg#myMask);
}
<svg ...>
<!-- Choose one of the following: -->
<clipPath id="myClipPath">
<!-- Add shapes, etc., here -->
</clipPath>
<mask id="myMask">
<!-- Add shapes, etc., here -->
</mask>
</svg>
These two CSS features function slightly differently, where masking is more modern and versatile but may have limited browser support (requiring prefixes). Regardless, adjustments to your SVG will be necessary. A <mask>
makes a pixel white for opaque and black for transparent, with shades of grey indicating varying opacities. On the other hand, a <clipPath>
delineates the visible region as the amalgamation of various shapes.