'how to clip a circle inside a shape

Frame

It's a rectangle inside a shape。

-webkit-clip-path: polygon(0% 0%, 0% 100%, 25% 100%, 25% 25%, 75% 25%, 75% 75%, 25% 75%, 25% 100%, 100% 100%, 100% 0%);
clip-path: polygon(0% 0%, 0% 100%, 25% 100%, 25% 25%, 75% 25%, 75% 75%, 25% 75%, 25% 100%, 100% 100%, 100% 0%);

how can i clip a circle inside?



Solution 1:[1]

You can use a path you draw in svg like so:

img{-webkit-clip-path: url(#clip);;
clip-path: url(#clip);}
<img src="https://assets.codepen.io/222579/darwin300.jpg" />
<svg height="0" width="0" class="svg-clip" style="position:absolute">
        <defs>
             <clipPath id="clip" clipPathUnits="objectBoundingBox">
               <path d="M0,0 L1,0 1,1 0,1 0,0M.75,.5A.25,.25 0 1 0 .25,.5A.25,.25 0 1 0 .75,.5z" />
            </clipPath>
        </defs>
</svg>

Please observe that clipPathUnits="objectBoundingBox" and the path's values are between 0 and 1. Also the first part of the path is drawn clockwise while the second path (the hole) is drawn counterclockwise.

Solution 2:[2]

Use mask instead:

.box {
  display: inline-block;
  width: 200px;
  height: 200px;
  background: url(https://picsum.photos/id/100/800/800) center/cover;
  -webkit-mask: radial-gradient(circle 40px, #0000 98%, #fff);
          mask: radial-gradient(circle 40px, #0000 98%, #fff);
}
<div class="box"></div>

<div class="box" style="width:300px;height:300px"></div>

You can have it responsive like below:

.box {
  display:inline-block;
  width:200px;
  height:200px;
  background:url(https://picsum.photos/id/100/800/800) center/cover;
  -webkit-mask:radial-gradient(circle closest-side,#0000 calc(100% - 30px),#fff calc(100% - 32px));
          mask:radial-gradient(circle closest-side,#0000 calc(100% - 30px),#fff calc(100% - 32px));
}
<div class="box"></div>

<div class="box" style="width:300px;height:300px"></div>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 enxaneta
Solution 2