Turning an image into a heart
Having a heart shape is good but putting an image inside it is better! For this, we are going to reuse the previous code with masking. The method that uses background will rely on mask and the one with border will rely on mask-border.
Why not use only the last version which is the shortest?
That’s what I recommend for the future but for now, mask-border has a very low browser support so will rely on the mask property as a fallback.
img {
width: 250px;
aspect-ratio: 1;
--_m: radial-gradient(#000 69%,#0000 70%) 84.5%/50%;
-webkit-mask-box-image: var(--_m);
mask-border: var(--_m);
clip-path: polygon(-42% 0,50% 91%, 142% 0);
}
/* fallback until better support for mask-border */
@supports not (-webkit-mask-box-image: var(--_m)) {
img {
--_m:
radial-gradient(at 70% 31%,var(--c) 29%,#0000 30%),
radial-gradient(at 30% 31%,var(--c) 29%,#0000 30%),
linear-gradient(#000 0 0) bottom/100% 50% no-repeat;
-webkit-mask: var(--_m);
mask: var(--_m);
}
}
See the Pen by Temani Afif () on .