# CSS border-shape for custom borders and shadows

<https://ics.media/en/entry/261204/>

Author: IWAMA Hina

Published: 2026-12-04 / Updated: 2026-12-04

The CSS `border-shape` property lets you **give an element’s border a custom shape**. You can draw circles and polygons, or combine straight lines and curves in the same shape.

Adding a border and shadow around a cutout photo used to require workarounds such as layering several elements. With `border-shape`, a single element can clip the photo, draw its border, and cast a shadow. Change the shape and the border and shadow follow it.

Start with a simple hexagon, then apply the same idea to photos, speech bubbles, and navigation links.

### Draw a hexagon with border-shape

To draw a hexagon, use `border` to set the line width and color, and `border-shape` to define the shape.

The [`polygon()`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/polygon) function takes a pair of coordinates for each vertex. The first pair, `50% 0%`, marks the midpoint of the box’s top edge. The remaining vertices follow clockwise.

```html
<div class="box"></div>
```

```css
.box {
  width: 120px;
  aspect-ratio: 1;
  border: 5px solid #e879a0;
  /* Connect the six vertices clockwise, starting at the top. */
  border-shape: polygon(
    50% 0%, 100% 25%, 100% 75%,
    50% 100%, 0% 75%, 0% 25%
  );
}
```

![Numbers 1 through 6 match the coordinate pairs in polygon() to the vertices of the hexagon, clockwise from the top.](https://ics.media/entry/261204/images/261204_border_shape_basic_hexagon_coordinates.png)

With one shape, the browser draws a line along its outline. This is called *stroke mode*. Use [`circle()`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/circle) for a circle, [`ellipse()`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/ellipse) for an ellipse, or [`shape()`](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/basic-shape/shape) for a mix of straight lines and curves.

### Demo 1. Add a border and shadow to a hexagonal photo

The demo uses four techniques to crop the same photo into a hexagon. Toggle **Border** and **Shadow** and watch the edges of each photo. Which techniques give you a hexagonal border? Which give you a hexagonal shadow?

![Four hexagonal photos. The border-shape example shows both a border and a shadow. The clip-path and mask-image examples show neither. Applying drop-shadow() to the parent adds a shadow around the hexagon.](https://ics.media/entry/261204/images/261204_border_shape_photo_comparison_marks.png)

<small>Try the demos in Chrome or Edge 147 or later.</small>

<https://ics-creative.github.io/261204_css_border-shape/demo/01/>

- [Open the demo in a new window](https://ics-creative.github.io/261204_css_border-shape/demo/01/)
- [View the source code](https://github.com/ics-creative/261204_css_border-shape/blob/main/demo/01/index.html)

In the `clip-path` and `mask-image` examples, the rectangular border and shadow fall outside the hexagon and disappear. The `clip-path` + `drop-shadow()` example applies `drop-shadow()` to the clipped element’s parent using the `filter` property. The parent then casts a hexagonal shadow.

For the `border-shape` example, give the photo’s wrapper a hexagonal border. Set `overflow: hidden` to clip any part of the photo that extends beyond it. On that same element, use `border` to style the border and `box-shadow` to add the shadow.

```css
.photo.shaped {
  /* Size and image styles omitted */
  border-shape: polygon(
    24% 7%, 75% 7%, 96% 51%, 77% 89%, 31% 94%, 4% 60%
  ) border-box;
  overflow: hidden;
  border: 5px solid #ece8ff;
  box-shadow: 8px 8px #b7aff5;
}
```

### Demo 2. Extend a speech bubble’s shadow around its tail

An earlier speech bubble design uses the `::before` and `::after` pseudo-elements to draw a triangular tail and layer it over a rectangular body. You can see the original example in [HTML・CSSで実装するかわいいフキダシのアイデア](https://ics.media/entry/240425/#1-6-%E6%9E%A0-%2B-%E4%B8%89%E8%A7%92%E3%81%A4%E3%81%BE%E3%81%BF%E3%81%AE%E3%83%95%E3%82%AD%E3%83%80%E3%82%B7).

Look for `border + ::before + ::after` in the demo to see that design alongside a bubble drawn with `border-shape`. Both bubbles have the same `box-shadow` on the body.

```css
/* Both speech bubbles use the same shadow. */
.fukidashi-01-06,
.shaped {
  box-shadow: 4px 6px 0 #b7aff5;
}
```

The original bubble casts a rectangular shadow with a flat bottom edge. Toggle **box-shadow** and look beneath the tail. In the `border-shape` example, the shadow follows the triangle all the way to its tip.

![On the left, the border-shape bubble casts a shadow beneath its triangular tail. On the right, the shadow of the bubble built with pseudo-elements has a flat bottom edge.](https://ics.media/entry/261204/images/261204_border_shape_bubble_shadow_methods_comparison.png)

<https://ics-creative.github.io/261204_css_border-shape/demo/02-01/>

- [Open the demo in a new window](https://ics-creative.github.io/261204_css_border-shape/demo/02-01/)
- [View the source code](https://github.com/ics-creative/261204_css_border-shape/blob/main/demo/02-01/index.html)

In the original, the body and tail each have their own border. With `border-shape`, the `shape()` function traces the body and tail as one continuous outline. A single `border` declaration sets the color and width for both.

In the next demo, select **Left**, **Center**, or **Right** to move the tail. The CSS custom property `--tip-x` sets its horizontal position.

![The triangular tail and its shadow move together to the left, center, or right of the speech bubble.](https://ics.media/entry/261204/images/261204_border_shape_triangular_tip_positions_shared.png)

<https://ics-creative.github.io/261204_css_border-shape/demo/02-02/>

- [Open the demo in a new window](https://ics-creative.github.io/261204_css_border-shape/demo/02-02/)
- [View the source code](https://github.com/ics-creative/261204_css_border-shape/blob/main/demo/02-02/index.html)

To draw the tail, start at the right end of its base, draw a line to the tip, then return to the left end of the base. Add half the tail’s width to `--tip-x` to get the right end, and subtract the same amount to get the left end.

The coordinates are relative to the `border-box`, which includes the border. Try changing `--tip-x` to `75%` in the code below. The tip moves three-quarters of the way across the box from its left edge.

```html
<p class="bubble">Copy link</p>
```

```css
.bubble {
  border: 2px solid #61519a;
  --tip-x: 50%;
  --tip-half-width: 9px;
  --body-bottom: calc(100% - 1px);
  /* Other styles omitted */

  border-shape: shape(
    from 1px 1px,
    hline to calc(100% - 1px),
    vline to var(--body-bottom),
    /* Trace the tail from its right base corner to the tip, then to its left base corner. */
    hline to calc(var(--tip-x) + var(--tip-half-width)),
    line to var(--tip-x) calc(var(--body-bottom) + 11px),
    line to calc(var(--tip-x) - var(--tip-half-width)) var(--body-bottom),
    hline to 1px,
    close
  ) border-box;
}
```

#### Change the shape of the bubble

The same technique works for ovals and even clouds. The border and shadow follow every curve of the bubble.

Switch between **Oval**, **Box**, and **Cloud** in the demo to see how the shadow changes with each shape.

![An oval, a rounded rectangle, and a cloud, each with a shadow that follows the outline of the speech bubble.](https://ics.media/entry/261204/images/261204_border_shape_bubble_shapes_shared.png)

<https://ics-creative.github.io/261204_css_border-shape/demo/02-03/>

- [Open the demo in a new window](https://ics-creative.github.io/261204_css_border-shape/demo/02-03/)
- [View the source code](https://github.com/ics-creative/261204_css_border-shape/blob/main/demo/02-03/index.html)

### Demo 3. Draw a focus ring along slanted edges

In this navigation bar, the links meet at an angle.

Press **Tab** until the **Type** link has focus. The `outline` property draws the focus ring that tells you which link has keyboard focus. The ring follows the shape defined by `border-shape`, including the slanted edges.

Press **Enter** or **Space** to switch to the section for the focused link.

![The Palette section is still visible while Type has keyboard focus. The focus ring follows the slanted edges of the Type link.](https://ics.media/entry/261204/images/261204_border_shape_focus_ring_shared.png)

<https://ics-creative.github.io/261204_css_border-shape/demo/03/>

- [Open the demo in a new window](https://ics-creative.github.io/261204_css_border-shape/demo/03/)
- [View the source code](https://github.com/ics-creative/261204_css_border-shape/blob/main/demo/03/index.html)

Here’s the **Type** link from the horizontal layout. When you tab to it, the link matches the `:focus-visible` pseudo-class and the focus ring appears. The `outline-offset` property leaves a gap between the ring and the border so the ring is easier to see.

```html
<nav>
  <a href="#type">Type</a>
</nav>
```

```css
nav a {
  /* Other styles omitted */
  border: 1px solid #9389a4;
  border-shape: polygon(
    12px 0, 100% 0, calc(100% - 12px) 100%, 0 100%
  ) border-box;
}

nav a:focus-visible {
  outline: 2px solid #5141c3;
  outline-offset: 3px;
}
```

### Demo 4. Use two shapes to vary the border width

You can also give `border-shape` two shapes, one for the outer edge of the border and one for the inner edge. The browser fills the area between them. This is called *fill mode*.

The farther apart the two edges are, the thicker the border. For example, a circle on the outside and a wide ellipse on the inside give you a border that’s thicker at the top and bottom than on the sides.

List the outer shape first and the inner shape second, separated by a space. Try replacing the `border-shape` value in the hexagon example with this one.

```css
.box {
  /* Other styles omitted */
  border-shape: circle(50%) ellipse(40% 30%);
}
```

The camera viewfinder in the demo uses the same technique. Its outer frame is an octagon, and its window is a wide opening with curved sides. Drag the **Pan** slider to move the photo left or right. Uncheck **Clip** to see the parts of the photo that extend beyond the window.

![Two camera viewfinders frame the same photo. In the border-shape version, one element draws the frame, clips the photo, and casts the shadow.](https://ics.media/entry/261204/images/261204_border_shape_viewfinder_comparison_centered.png)

<https://ics-creative.github.io/261204_css_border-shape/demo/04/>

- [Open the demo in a new window](https://ics-creative.github.io/261204_css_border-shape/demo/04/)
- [View the source code](https://github.com/ics-creative/261204_css_border-shape/blob/main/demo/04/index.html)

Both viewfinders look the same, but their markup differs. The `border-shape` version uses a single `div` around the photo for the frame, clipping, and shadow. The `clip-path` version uses three `div` elements. Keeping the frame and window on separate elements makes it easy to adjust them independently, for instance by moving just the window.

```html
<!-- border-shape version -->
<div class="viewfinder shaped">
  <img src="../01/beach.webp" alt="Waves breaking on a beach at sunrise" />
</div>

<!-- clip-path version -->
<div class="viewfinder clipped">
  <div class="shell"></div>
  <div class="window">
    <img src="../01/beach.webp" alt="Waves breaking on a beach at sunrise" />
  </div>
</div>
```

The following CSS shows the styles with **Clip** checked. Both versions use `--outer` for the frame and `--inner` for the window.

```css
.viewfinder-demo {
  /* Octagonal outer frame */
  --outer: polygon(
    17% 3%, 83% 3%, 98% 27%, 98% 73%,
    83% 97%, 17% 97%, 2% 73%, 2% 27%
  );
  /* Window outline */
  --inner: shape(
    from 26% 18%,
    hline to 74%,
    curve to 88% 38% with 80% 18% / 87% 30%,
    curve to 88% 62% with 90% 44% / 90% 56%,
    curve to 74% 82% with 87% 70% / 80% 82%,
    hline to 26%,
    curve to 12% 62% with 20% 82% / 13% 70%,
    curve to 12% 38% with 10% 56% / 10% 44%,
    curve to 26% 18% with 13% 30% / 20% 18%,
    close
  );
}
```

The code below offsets the shadow by `7px` to the right and `7px` down, just as the demo does on a wide screen.

```css
.shaped {
  /* Positioning and other styles omitted */
  border-color: #b7aff5;
  border-shape: var(--outer) border-box var(--inner) border-box;
  overflow: hidden;
  box-shadow: 7px 7px 0 #5141c3;
}
```

In the `clip-path` version, `.shell::before` draws the outer frame, `.shell` casts the shadow, and `.window` clips the photo to the shape of the opening. Open **Compare CSS** in the demo to compare the two versions.

```css
.shell {
  /* Positioning and other styles omitted */
  filter: drop-shadow(7px 7px 0 #5141c3);

  &::before {
    content: "";
    background: #b7aff5;
    clip-path: var(--outer);
  }
}

.window {
  clip-path: var(--inner);
}
```

### Browser support

Chrome and Edge have supported `border-shape` since version 147, released in April 2026.

<https://webstatus.dev/features/border-shape>

See [Can I use...](https://caniuse.com/mdn-css_properties_border-shape) for browser support.

### Conclusion

As of December 2026, `border-shape` has two limitations to keep in mind.

- `border-radius` and `corner-shape` have no effect on the corners of a shape drawn with `border-shape`. To round the corners, draw them as curves with `shape()`.
- A shaped border renders as a solid line even when `border-style` is set to `dashed` or `dotted`.

With `border-shape`, the same outline guides both the border and the shadow. Move a speech bubble’s tail, for example, and its border and shadow move with it. That makes even a cloud-shaped bubble straightforward to style in CSS.

If you only want to change the corners of an element, `corner-shape` lets you bevel them or scoop them inward. For examples, see [CSS corner-shape for customize corner styles](https://ics.media/en/entry/260226/).

### References

- [border-shape CSS property - MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/border-shape)
- [New in Chrome 147 - Chrome for Developers](https://developer.chrome.com/blog/new-in-chrome-147)
- [Border Shaping - CSS Borders and Box Decorations Module Level 4](https://drafts.csswg.org/css-borders-4/#border-shape)
