Dev Helpers

CSS / Media and shapes

Clip a swatch to a diamond

Dev Helpers · November 21, 2025

A polygon clip can turn a square swatch into a diamond while its allocated layout box stays rectangular.

Worked example

<style>
  .demo {
    width: 6rem;
    height: 6rem;
    clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  }
</style>
<div class="demo" aria-hidden="true"></div>

Implementation notes

Polygon points are relative to the reference box. A non-square box stretches a diamond, so give the shape the ratio its design assumes.

Try it yourself

Tab through nearby controls and inspect the space around the clipped shape.

Open the CSS example →

Editorial date November 21, 2025 · Published December 6, 2026

Related articles

Fluid width with a maximum

A fluid container needs a small-screen width and a large-screen maximum. Outer gutters should remain visible at both extremes.

Square aspect ratio

A square ratio reserves equal sides even before media loads. Fit rules decide whether rectangular content is cropped or letterboxed.