Thursday, July 9, 2026

Get Prepared For the Highly effective CSS border-shape Property!


So, we lately obtained the brand new form() operate (now Baseline!) in addition to the corner-shape property. What else may we presumably want so far as making shapes in CSS? Let me inform you: the border-shape property!

form()? corner-shape? border-shape?! The place did all these come from?

If you’re not a CSS form fanatic like me, you in all probability missed these options once they got here out, so let’s give them temporary, formal introductions, beginning with…

form() and corner-shape

The form() operate is a brand new worth for clip-path and offset-path that makes use of SVG syntax to create CSS shapes rather more simply than, say, path(). I wrote a four-article collection exploring this characteristic, and one other article the place I discover the creation of advanced shapes.

Talking about SVG, you’ll be able to specific any SVG form utilizing form(). Mentioned in another way, you’ll be able to convert any SVG form right into a CSS form and, guess what, I made a converter that does precisely that!

So far as corner-shape goes, it’s a property that works together with border-radius. As its title suggests, it permits you to management the form of a component’s nook utilizing predefined key phrases.

.nook  scoop 
A graphic displaying different CSS corner shapes: 'round', 'scoop', 'bevel', 'notch', and 'squircle', each in a purple background with white text.

It may also be used to create widespread CSS shapes, like I get into in one other article, “CSS Shapes utilizing corner-shape.

CSS-only shapes (triangle, rhombus, hexagon, etc.)`

However is that this the corner-shape property actually helpful and even wanted? Apart from the squircle worth, a lot of the shapes can already be created utilizing clip-path or masks. However what corner-shape does that these others can’t is well add borders and different decorations to these shapes!

Five shapes with different corner styles labeled: round, scoop, bevel, notch, and squircle, all displayed on a purple background.

corner-shape is not going to solely form the corners, but it surely additionally helps different properties like border and box-shadow, permitting them to comply with the form fairly than the factor’s field. It is a game-changer as a result of everyone knows that including borders to shapes is a nightmare.

Help continues to be not nice (Chromium-only as I’m scripting this), but it surely’s time to discover it and get an outline of its potential.

Enter border-shape!

Shaping corners is sweet, but it surely’s nonetheless pretty restricted so far as what we are able to do with it. Like, what about shaping the entire factor as an alternative? That’s what border-shape will do. It accepts the identical values as clip-path, together with the brand new form() operate.

So, it has the identical job as clip-path? What’s new?

Like with corner-shape, most ornamental properties equivalent to border, box-shadow, and define comply with the form.

Showing the difference between clip-path and border-shape

clip-path (and masks) will clip/masks the entire factor, together with the decorations, so having borders is a giant NO. That’s a serious downside for creating CSS shapes.

The border-shape property is right here to resolve this challenge. As an alternative of clipping the factor, it “shapes” the factor, permitting its decorations to comply with that form. In different phrases, placing borders on CSS shapes will develop into little one’s play!

To not point out that border-shape can be very straightforward to make use of. If you’re acquainted with clip-path, then you definitely virtually don’t have anything new to be taught. Merely substitute one property with one other, and you’re accomplished.

.form  ...;

I invite you once more to be taught extra concerning the form() operate as a result of it’s the worth that makes border-shape actually highly effective. The 2 actually go hand-in-hand.

Now that you understand the essential use of the property, lets begin the enjoyable stuff? I are right here to push the bounds and present you what is feasible utilizing border-shape.

Be aware: Help is restricted to Chrome-only for now so try the following demos utilizing Chrome.

Border-Solely Shapes

As I mentioned, the primary main benefit right here is including borders to shapes that comply with the precise form, which additionally means the power to create border-only shapes. All it’s important to do is write the next code:

.form {
  border: 8px strong crimson;
  border-shape: /* your form code */;
}

No extra hacks and no extra complications!

Four shapes with borders and no fill, including a red heart, yellow starburst, green flower, and blue jagged rectangle.

Many of the shapes are already accessible in my CSS Shapes assortment, so actually, making border-only shapes is one thing you are able to do with a easy copy/paste. Even a few of my on-line turbines are already configured to supply border-only variations of advanced shapes, like blobs, wavy traces, and fancy frames, amongst many, many others.

border-only shapes using the CSS border-shape property, including a jagged red circle, a squiggly blue line, and a jagged blue rectangle.

Cutout Shapes

Let’s take the earlier code and replace it as follows:

.form {
  border: 8px strong crimson;
  border-shape: inset(0) /* you form code */;
}

You retain the form code you had, and also you add inset(0) at first. Sure, you’ll be able to have two form values inside border-shape and the end result will probably be as follows:

Four shapes cut out from squares with filled colors, including a heart with red background, a stardust against yellow, a flower against green, and a jagged square against blue.

From the specification:

The border-shape property accepts both a single or two s:

Single (Stroke mode): The border is rendered as a stroke alongside the form’s path, with the stroke width decided by the related aspect’s computed border width. This mode is helpful for creating outlined shapes.

Two s (Fill mode) The border is rendered as the world between the 2 paths. The primary form defines the outer boundary, and the second form defines the internal boundary. This mode supplies exact management over the border area’s geometry.

Utilizing a fundamental rectangle because the outer form (inset(0)), I used to be in a position to simply remodel the border-only model right into a cutout model!

Would you like the form inside a circle? Simple!

Four shapes cut out from circles with filled colors, including a heart with red background, a stardust against yellow, a flower against green, and a jagged square against blue.

All I did is substitute inset(0) (a rectangle) with circle() (a circle).

However we are able to do that with a easy border-radius: 50%, proper?

No! When working with border-shape, the border-radius is ignored, which is sort of logical since we now not have corners to spherical — the factor is now formed. This isn’t a giant deal since we are able to actually create any sort of form that replaces the usage of border-radius, as proven within the earlier instance.

Be aware: If you’re questioning why I’m utilizing circle()with none argument, try my article “CSS Capabilities that work with out arguments.

Listed below are a number of extra examples with the 2 shapes worth to have a look at earlier than we transfer to the following half:

Four shapes cut out from polygons with filled colors, including a heart with red background, a stardust against yellow, a flower against green, and a jagged square against blue.

You possibly can actually use any mixture to get complex-looking shapes with no bunch of effort!

Breakout Decorations

Now let’s take a block of textual content and apply the earlier code with the 2 form values:

.field {
  border-shape: inset(0) circle();
  border-color: pink;
}

Maybe that is nothing shocking contemplating what now we have realized to this point. We outline two shapes and the border is drawn inside the world between them. What’s new right here is that we’re coping with content material and, as you’ll be able to see, it overlaps the border.

border-shape shapes the entire factor, together with the factor’s ornament, however any content material inside stays unchanged and follows the preliminary rectangle form. That’s not new habits because the similar occurs even even with basic border-radius. And the content material will overflow until we resolve to cover it utilizing overflow hidden.

On this case, I gained’t contemplate the overflow property as I need the content material to overflow and be positioned on high of the border ornament.

Now let’s replace the code of the form like this:

.field {
  border-shape: inset(0 -100px) circle(50px);
  border-color: pink;
}

I made the circle smaller and the rectangle greater. Do you see the place I’m going? By making the radius of the circle 0 and the rectangle greater, I create a breakout background impact!

.field {
  border-shape: inset(0 -100vw) circle(0);
  border-color: pink;
}

A paragraph of black text against a full-width pink rectangle.

The factor stays centered, however its background (that we’re simulating utilizing a border!) extends to the sting of the display.

And this isn’t restricted to utilizing two form values. Even with the one form worth, we are able to obtain a breakout ornament (which is often tough) if you happen to contemplate any worth that will get you out of the factor’s boundary.

Here’s a demo with many examples that I’ll allow you to discover:

Three examples of border text decorations, including an orange line through a main heading, heading against a blue caret-shaped background, and black text against a full-width pink background.

Partial Decorations

Let’s piggy-back off that final demo to strive completely different decorations.

Three examples of border text decorations, including a short orange underline for a mina heading, a heading with a partial blue background with a diagonal right edge, and a corner border in the top-left of a paragraph.

This time, as an alternative of extending exterior the factor boundary, I’m staying inside it to create partial ornament. In different phrases, we now not have boundaries. border-shape has no restrict. The one restrict is your creativeness!

I’m primarily counting on the form() operate to create the ornament, so do your self a favor and discover this characteristic by studying my four-article collection! If you happen to grasp form(), you’ll be able to simply produce advanced decorations utilizing border-shape.

Form Animation

Sure, border-shape may be animated, and we are able to have completely different sorts of animations. With the two-value syntax, we are able to animate the border-width worth to create a reveal impact:

Hover the under and see the end result:

Cool, proper? We will additionally apply this to picture parts as properly:

We will additionally animate the form values to create extra advanced animations. Here’s a demo of a bouncing hover impact utilized to blob shapes (from my article “Making Complicated CSS Shapes Utilizing form().”

I take the identical code, substitute clip-path with border-shape, and tada!

And why not add a refined animation to these earlier decorations? Hover the titles and the textual content to see what occurs:

Need Extra? Let’s Go!

Here’s a hand-drawn underline that slides between the menu gadgets on hover. Straight traces are boring!

And why not an electrical body round your content material? Don’t fear, it’s protected for contact screens.

What a couple of fancy border-only loader? (code taken from my squishy loader assortment)

Let’s join circles with a straight line that bends when the circles get nearer and stretches once they get farther. Drag the circles within the demo under and see the magic in play:

Conclusion

I believe it’s clear now why I’m calling this new property “highly effective.” Along with making it straightforward to create CSS shapes, it lets us add fancy decorations, cool animations, and extra!

I didn’t go into tremendous element with a lot of the demos as I needed to maintain this a lightweight article displaying the potential of border-shape. Now that you understand we are able to create loopy stuff with it, keep tuned for extra elaborate articles!

Don’t overlook to bookmark my CSS Shapes assortment and my on-line turbines. I’ve already up to date most of the shapes utilizing form(), and I’m within the strategy of additionally together with the border-shape model.

Related Articles

Latest Articles