Support0

CSS border-shape playground

Draw non-rectangular borders with basic shapes and shape(), compare stroke and fill modes, and see the border follow the geometry.

Ask AI

CSS border-shape playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.

CSS geometry

The border can have a shape, too

Content and border share the same contour.

This browser does not support border-shape yet. The preview uses an approximate clip-path fallback; a shaped border requires native support.

HTML
<article class="border-shape" aria-labelledby="border-shape-title">
  <p>CSS geometry</p>
  <h2 id="border-shape-title">The border can have a shape, too</h2>
  <p>Content and border share the same contour.</p>
</article>
Tailwind CSS
Examples for Tailwind CSS 4.3 with the default theme. Custom values keep arbitrary classes when there is no equivalent utility. Changing the theme can change utility values.
<article class="box-border w-full max-inline-md min-w-0 min-block-72 p-[min(3rem,10%)] wrap-anywhere text-center bg-[#172033] border-7 border-solid border-[#f97316] text-slate-50 [clip-path:polygon(2%_2%,_calc(100%_-_2%)_2%,_calc(100%_-_2%)_calc(100%_-_2%_-_24px),_calc(62%_+_24px)_calc(100%_-_2%_-_24px),_62%_calc(100%_-_2%),_calc(62%_-_24px)_calc(100%_-_2%_-_24px),_2%_calc(100%_-_2%_-_24px))_border-box] supports-[border-shape:circle(50%)]:[clip-path:none] supports-[border-shape:circle(50%)]:[border-shape:shape(_from_calc(2%_+_17px)_2%,_hline_to_calc(100%_-_2%_-_17px),_curve_to_calc(100%_-_2%)_calc(2%_+_17px)_with_calc(100%_-_2%)_2%,_vline_to_calc(100%_-_2%_-_24px_-_17px),_curve_to_calc(100%_-_2%_-_17px)_calc(100%_-_2%_-_24px)_with_calc(100%_-_2%)_calc(100%_-_2%_-_24px),_hline_to_calc(62%_+_24px),_line_to_62%_calc(100%_-_2%),_line_to_calc(62%_-_24px)_calc(100%_-_2%_-_24px),_hline_to_calc(2%_+_17px),_curve_to_2%_calc(100%_-_2%_-_24px_-_17px)_with_2%_calc(100%_-_2%_-_24px),_vline_to_calc(2%_+_17px),_curve_to_calc(2%_+_17px)_2%_with_2%_2%,_close_)_border-box]" aria-labelledby="border-shape-title">
  <p>CSS geometry</p>
  <h2 id="border-shape-title">The border can have a shape, too</h2>
  <p>Content and border share the same contour.</p>
</article>
CSS
@supports (border-shape: circle(50%)) {
  .border-shape {
    border-shape: shape(
      from calc(2% + 17px) 2%,
      hline to calc(100% - 2% - 17px),
      curve to calc(100% - 2%) calc(2% + 17px) with calc(100% - 2%) 2%,
      vline to calc(100% - 2% - 24px - 17px),
      curve to calc(100% - 2% - 17px) calc(100% - 2% - 24px) with calc(100% - 2%) calc(100% - 2% - 24px),
      hline to calc(62% + 24px),
      line to 62% calc(100% - 2%),
      line to calc(62% - 24px) calc(100% - 2% - 24px),
      hline to calc(2% + 17px),
      curve to 2% calc(100% - 2% - 24px - 17px) with 2% calc(100% - 2% - 24px),
      vline to calc(2% + 17px),
      curve to calc(2% + 17px) 2% with 2% 2%,
      close
    ) border-box;
  }
}

.border-shape {
  box-sizing: border-box;
  inline-size: min(100%, 28rem);
  min-inline-size: 0;
  min-block-size: 18rem;
  padding: min(3rem, 10%);
  overflow-wrap: anywhere;
  text-align: center;
  background-color: #172033;
  border: 7px solid #f97316;
  color: #f8fafc;
}

@supports not (border-shape: circle(50%)) {
  .border-shape {
    clip-path: polygon(2% 2%, calc(100% - 2%) 2%, calc(100% - 2%) calc(100% - 2% - 24px), calc(62% + 24px) calc(100% - 2% - 24px), 62% calc(100% - 2%), calc(62% - 24px) calc(100% - 2% - 24px), 2% calc(100% - 2% - 24px)) border-box;
  }
}

Educational guide to border-shape

Shape the border while keeping content readable

A border can follow a diamond or a curve. Learn to separate contour, reference box and content, compare one and two shapes, and keep a readable base when support is missing.

Mental model

Layout calculates a box; border-shape changes how its border is painted.

  1. Box

    Dimensions, padding and border-width still reserve rectangular space.

  2. Contour

    A geometric function resolves against a reference box.

  3. Painting

    One shape produces a stroke; two bound the region to fill.

Visual geometry and layout are separate decisionsStatic diagram, not to scale. The following examples test native CSS in your browser.

border-shape enables nonrectangular borders with circle(), ellipse(), polygon(), path() or shape(). Its initial value is none. It does not rearrange text lines to follow the silhouette: content keeps its rectangular flow.

One shape: stroke the contour

With a single shape, border-width determines stroke thickness.

These two samples use the same polygon() from the lab generator. Only border-width changes: 4px versus 12px. The stroke is centered on the path; border-box is explicit here and the vertices are inset to leave room for the stroke.

One diamond, two stroke widths

A · 4px stroke
A
B · 12px stroke
B

Native syntax available for this example.

Rectangular fallback: this border-shape syntax is unavailable.

With native support, B has a thicker stroke than A along the same path. Without this syntax, two rectangular borders retain their original widths.
One diamond, two stroke widths
<div class="border-shape-scene-stroke">
  <figure>
    <figcaption>A · 4px stroke</figcaption>
    <div class="reference"><div class="sample sample-1">A</div></div>
  </figure>
  <figure>
    <figcaption>B · 12px stroke</figcaption>
    <div class="reference"><div class="sample sample-2">B</div></div>
  </figure>
  <p class="native">Native syntax available for this example.</p>
  <p class="fallback">Rectangular fallback: this border-shape syntax is unavailable.</p>
</div>
.border-shape-scene-stroke {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  font: 1rem/1.5 system-ui, sans-serif;
  overflow-wrap: anywhere;

  figure {
    margin: 0;
    inline-size: min(100%, 12rem);
  }

  figcaption {
    margin-block-end: 0.5rem;
  }

  .sample {
    box-sizing: border-box;
    inline-size: 100%;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border: 4px solid currentColor;
  }

  > p {
    flex-basis: 100%;
    margin: 0;
  }

  .native {
    display: none;
  }

  .sample-2 {
    border-width: 12px;
  }

  @supports (border-shape: polygon(50% 8%, calc(100% - 8%) 50%, 50% calc(100% - 8%), 8% 50%) border-box) {
    .sample {
      border-shape: polygon(50% 8%, calc(100% - 8%) 50%, 50% calc(100% - 8%), 8% 50%) border-box;
    }

    .native {
      display: block;
    }

    .fallback {
      display: none;
    }
  }
}

Without an explicit box, one shape uses half-border-box: the path runs through the middle of the conventional border. These examples use a uniform solid border; with different sides, the specification takes the first side whose style is not none in logical order: block-start, inline-start, block-end, inline-end.

Two shapes: outer and inner

The first contour bounds the outside; the second defines the inner opening.

Write two shapes separated by a space, without a comma. The border fills the region between them using border-color. Both samples fix both contours against border-box: changing border-width no longer changes those explicit paths, although it still affects layout.

Same contours, different border-width

A · fixed contours, 4px border
A
B · fixed contours, 12px border
B

Native syntax available for this example.

Rectangular fallback: this border-shape syntax is unavailable.

In native mode A and B share the same border region, despite reserving 4px and 12px in the box model. The rectangular fallback does show that thickness difference. No overlaid element simulates the opening.
Same contours, different border-width
<div class="border-shape-scene-fill">
  <figure>
    <figcaption>A · fixed contours, 4px border</figcaption>
    <div class="reference"><div class="sample sample-1">A</div></div>
  </figure>
  <figure>
    <figcaption>B · fixed contours, 12px border</figcaption>
    <div class="reference"><div class="sample sample-2">B</div></div>
  </figure>
  <p class="native">Native syntax available for this example.</p>
  <p class="fallback">Rectangular fallback: this border-shape syntax is unavailable.</p>
</div>
.border-shape-scene-fill {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  font: 1rem/1.5 system-ui, sans-serif;
  overflow-wrap: anywhere;

  figure {
    margin: 0;
    inline-size: min(100%, 12rem);
  }

  figcaption {
    margin-block-end: 0.5rem;
  }

  .sample {
    box-sizing: border-box;
    inline-size: 100%;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border: 4px solid currentColor;
  }

  > p {
    flex-basis: 100%;
    margin: 0;
  }

  .native {
    display: none;
  }

  .sample-2 {
    border-width: 12px;
  }

  @supports (border-shape: polygon(50% 8%, calc(100% - 8%) 50%, 50% calc(100% - 8%), 8% 50%) border-box
    polygon(50% 18%, calc(100% - 18%) 50%, 50% calc(100% - 18%), 18% 50%) border-box) {
    .sample {
      border-shape: polygon(50% 8%, calc(100% - 8%) 50%, 50% calc(100% - 8%), 8% 50%) border-box
        polygon(50% 18%, calc(100% - 18%) 50%, 50% calc(100% - 18%), 18% 50%) border-box;
    }

    .native {
      display: block;
    }

    .fallback {
      display: none;
    }
  }
}

Without explicit boxes, the outer contour uses border-box and the inner one padding-box; border-width then also changes the inner reference. Two different percentages do not guarantee constant thickness perpendicular to the contour. Keep the inner shape inside the outer one and check the actual size.

Reference boxes

The same function can produce different paths depending on where it is measured.

border-box includes the border; padding-box excludes it; content-box also excludes padding. In these samples, inset(0) follows the boundary of each reference. The dashed outer box belongs to the wrapper so you can compare the path with the reserved rectangular space.

inset(0) measured from three boxes

A · border-box
A
B · padding-box
B
C · content-box
C

Native syntax available for this example.

Rectangular fallback: this border-shape syntax is unavailable.

A measures from border-box, B from padding-box and C from content-box. All retain an 8px border and 1rem padding; only the reference changes. Without support, all three keep the same base rectangular border.
inset(0) measured from three boxes
<div class="border-shape-scene-boxes">
  <figure>
    <figcaption>A · border-box</figcaption>
    <div class="reference"><div class="sample sample-1">A</div></div>
  </figure>
  <figure>
    <figcaption>B · padding-box</figcaption>
    <div class="reference"><div class="sample sample-2">B</div></div>
  </figure>
  <figure>
    <figcaption>C · content-box</figcaption>
    <div class="reference"><div class="sample sample-3">C</div></div>
  </figure>
  <p class="native">Native syntax available for this example.</p>
  <p class="fallback">Rectangular fallback: this border-shape syntax is unavailable.</p>
</div>
.border-shape-scene-boxes {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  font: 1rem/1.5 system-ui, sans-serif;
  overflow-wrap: anywhere;

  figure {
    margin: 0;
    inline-size: min(100%, 12rem);
  }

  figcaption {
    margin-block-end: 0.5rem;
  }

  .sample {
    box-sizing: border-box;
    inline-size: 100%;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border: 4px solid currentColor;
  }

  > p {
    flex-basis: 100%;
    margin: 0;
  }

  .native {
    display: none;
  }

  .reference {
    outline: 1px dashed currentColor;
  }

  .sample {
    padding: 1rem;
    border-width: 8px;
  }

  @supports (border-shape: inset(0) border-box) and (border-shape: inset(0) padding-box) and (border-shape: inset(0) content-box) {
    .sample-1 {
      border-shape: inset(0) border-box;
    }

    .sample-2 {
      border-shape: inset(0) padding-box;
    }

    .sample-3 {
      border-shape: inset(0) content-box;
    }

    .native {
      display: block;
    }

    .fallback {
      display: none;
    }
  }
}

Percentages resolve according to the function and its box: for example, circle() does not treat its percentage radius as simply half the width. For a predictable circle, test the box proportions too. path() uses its path coordinates; shape() allows adaptable lengths and percentages. Check each combination, not just the property name.

Comparisons

Clipping a box and painting a shaped border solve different problems.

clip-path hides everything outside its region: it also cuts the existing rectangular border, shadows and content. It does not create a border along the diagonals. border-shape defines the border path itself; outline and box-shadow can follow that shape according to their support.

The same silhouette, two operations

A · border-shape
A
B · clip-path
B

Native syntax available for this example.

Rectangular fallback: this border-shape syntax is unavailable.

With native border-shape, A draws the slanted sides too. B applies clip-path to a rectangular border: slanted sides are cuts, not new strokes. Without border-shape, A stays rectangular and B keeps its clipping.
The same silhouette, two operations
<div class="border-shape-scene-comparison">
  <figure>
    <figcaption>A · border-shape</figcaption>
    <div class="reference"><div class="sample sample-1">A</div></div>
  </figure>
  <figure>
    <figcaption>B · clip-path</figcaption>
    <div class="reference"><div class="sample sample-2">B</div></div>
  </figure>
  <p class="native">Native syntax available for this example.</p>
  <p class="fallback">Rectangular fallback: this border-shape syntax is unavailable.</p>
</div>
.border-shape-scene-comparison {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  font: 1rem/1.5 system-ui, sans-serif;
  overflow-wrap: anywhere;

  figure {
    margin: 0;
    inline-size: min(100%, 12rem);
  }

  figcaption {
    margin-block-end: 0.5rem;
  }

  .sample {
    box-sizing: border-box;
    inline-size: 100%;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border: 4px solid currentColor;
  }

  > p {
    flex-basis: 100%;
    margin: 0;
  }

  .native {
    display: none;
  }

  .sample-2 {
    clip-path: polygon(18% 0, 100% 0, 82% 100%, 0 100%);
  }

  @supports (border-shape: polygon(18% 0, 100% 0, 82% 100%, 0 100%) border-box) {
    .sample-1 {
      border-shape: polygon(18% 0, 100% 0, 82% 100%, 0 100%) border-box;
    }

    .native {
      display: block;
    }

    .fallback {
      display: none;
    }
  }
}

Choose clip-path to hide part of an image or surface; border-shape to define a border. An approximate clip-path can be a visual alternative, but it is not equivalent to a shaped border and can clip focus or information. This guide uses a rectangle as its base; the existing playground explicitly identifies its approximate clip-path fallback.

Content, spacing and focus

Reserve space for reading before adjusting a silhouette.

The visual inner region does not change text flow. Avoid enclosing paragraphs in a fixed-height diamond. This note cuts only a 1rem corner and reserves 1.5rem padding, with no fixed height, so content can grow when text is enlarged.

A note that grows with its text

One corner, readable content

This note preserves its text when the window narrows or the font grows. Padding separates the lines from the border; the shape does not rearrange them.

Native syntax available for this example.

Rectangular fallback: this border-shape syntax is unavailable.

The top-left corner changes with native support; text keeps rectangular lines and height grows with them. Without support, the same note keeps a rectangular border and the same padding.
A note that grows with its text
<div class="border-shape-scene-content">
  <article class="note">
    <h4>One corner, readable content</h4>
    <p>This note preserves its text when the window narrows or the font grows. Padding separates the lines from the border; the shape does not rearrange them.</p>
  </article>
  <p class="native">Native syntax available for this example.</p>
  <p class="fallback">Rectangular fallback: this border-shape syntax is unavailable.</p>
</div>
.border-shape-scene-content {
  font: 1rem/1.5 system-ui, sans-serif;
  overflow-wrap: anywhere;

  .note {
    padding: 1.5rem;
    border: 4px solid currentColor;

    h4 {
      margin: 0;
      font-size: 1rem;
    }

    p {
      margin: 0.75rem 0 0;
    }
  }

  .native {
    display: none;
  }

  @supports (border-shape: polygon(0 1rem, 1rem 0, 100% 0, 100% 100%, 0 100%) border-box) {
    .note {
      border-shape: polygon(0 1rem, 1rem 0, 100% 0, 100% 100%, 0 100%) border-box;
    }

    .native {
      display: block;
    }

    .fallback {
      display: none;
    }
  }
}

overflow remains a separate decision: when overflow is clipped, the inner contour contributes to the clipping area. Do not use overflow: hidden or clip-path as an automatic fix for text that does not fit. If you add links or buttons, check Tab, visible focus, hit areas and forced colors. border-radius and corner-shape do not combine to round border-shape: with a value other than none, their corners are ignored.

Common mistakes

Check painting, references and reading separately.

Thickness does not respond as expected

Expected result
Control the visible border region.
Cause
With two explicit contours measured in the same border-box, the opening depends on those shapes, not just border-width.
Solution
Adjust the inner shape and check its boxes; remember that border-width still reserves layout space.

Text or focus disappears

Expected result
Keep content and actions readable.
Cause
The silhouette intrudes into content or a clip-path/overflow clips necessary areas.
Solution
Reduce the cuts, increase padding and let height grow; test enlarged text and keyboard use at the minimum size.

The clipped shape has no diagonal border

Expected result
A continuous stroke around the whole shape.
Cause
clip-path cuts a rectangular border; it does not redraw it along the polygon.
Solution
Use border-shape with verified support or retain a conventional border as fallback; do not present clipping as equivalent.

One example works and another does not

Expected result
Apply the specific combination of shapes and references.
Cause
Accepting circle() does not prove support for two shapes, shape() or every box.
Solution
Consult current data and test the exact value with @supports; also check the painted result.

Support and compatibility

An experimental property needs a useful base and syntax-specific detection.

Checked on October 22, 2026: limited availability. Web Platform DX and MDN BCD record Chrome/Edge from 147 and no stable support in Firefox/Safari. The general card does not certify every function, box or interaction.

Each recipe keeps border outside @supports and enables the enhancement with its specific value. Notices switch through CSS, including without JavaScript. @supports checks syntax acceptance, not painting quality, contrast or accessibility. Check the result in target browsers and revisit the sources before publishing.