<div class="gallery">
  <img src="https://picsum.photos/id/152/300/300" alt="Purple flowers">
  <img src="https://picsum.photos/id/106/300/300" alt="Pink flowers">
  <img src="https://picsum.photos/id/400/300/300" alt="Some plants">
  <img src="https://picsum.photos/id/306/300/300" alt="A water lily">
</div>
.gallery {
  --s: 200px; /* control the size */
  --g: 6px;   /* control the gap */
  --r: 42px;  /* control the triangle shape */
  
  display: grid;
  gap: var(--g);
  grid: auto-flow var(--s)/repeat(2,var(--s));
}
.gallery > img {
  object-fit: cover;
  -webkit-mask: var(--_m);
          mask: var(--_m);
}
.gallery > img:is(:nth-child(1),:nth-child(4)) {
  width: 100%;
  height: calc(100% + var(--r));
}
.gallery > img:is(:nth-child(2),:nth-child(3)) {
  height: 100%;
  width: calc(100% + var(--r));
}
.gallery > img:nth-child(1) {
  --_m: 
    conic-gradient(from 45deg at calc(100% - .5*var(--g) - var(--r)) 50%,#0000 90deg,#000 0)
      top/100% calc(100% - var(--r)) no-repeat, 
    conic-gradient(from -45deg at bottom ,#000 90deg,#0000 0)
      bottom/100% var(--r) no-repeat;
}
.gallery > img:nth-child(2) {
  place-self: end;
  --_m: 
    conic-gradient(from 135deg at 50% calc(100% - .5*var(--g) - var(--r)),#0000 90deg,#000 0) 
      right/calc(100% - var(--r)) 100% no-repeat, 
    conic-gradient(from 45deg at left ,#000 90deg,#0000 0)
      left/var(--r) 100% no-repeat;
}
.gallery > img:nth-child(3) {
  --_m: 
    conic-gradient(from -45deg at 50% calc(.5*var(--g) + var(--r)),#0000 90deg,#000 0) 
      left/calc(100% - var(--r)) 100% no-repeat, 
    conic-gradient(from -135deg at right ,#000 90deg,#0000 0)
      right/var(--r) 100% no-repeat;
}
.gallery > img:nth-child(4) {
  place-self: end;
  --_m: 
    conic-gradient(from -135deg at calc(.5*var(--g) + var(--r)) 50%,#0000 90deg,#000 0) 
      bottom/100% calc(100% - var(--r)) no-repeat, 
    conic-gradient(from 135deg at top ,#000 90deg,#0000 0)
      top/100% var(--r) no-repeat;
}


body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-content: center;
  background: #ECD078;
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.