63

I want to be able to round out the 3 leftmost corners on this shape that I have created, any idea how that can be done?

div {
  position: absolute;
  z-index: 1;
  width: 423px;
  height: 90px;
  background-color: #b0102d;
  color: white;
  right: 0;
  margin-top: 10vw;
  -webkit-clip-path: polygon(100% 0%, 100% 50%, 100% 100%, 25% 100%, 0% 50%, 25% 0%);
  clip-path: polygon(100% 0%, 100% 50%, 100% 100%, 25% 100%, 0% 50%, 25% 0%);
}
<div></div>

8
  • 1
    bennettfeely.com/clippy Commented Aug 1, 2015 at 19:30
  • yeah thats what I used to make the shape but i just don't know how to round the corners. Any ideas? Commented Aug 1, 2015 at 19:34
  • 2
    You'd have to go the SVG clip path route I suspect. I don't think polygon supports curves. - sarasoueidan.com/blog/css-svg-clipping Commented Aug 1, 2015 at 19:39
  • 1
    @Paulie_D is correct. CSS only clip-path supports only basic shapes (like polygon, circle). It does not support a combination of shapes or paths and you would have to use SVG (inline or external) for that. Commented Aug 2, 2015 at 5:09
  • 10
    for later readers, replying to the question in title: notice in Clippy you have the rounded border option in inset(): clip-path: inset(0 0 0 0 round 10%); Commented Nov 26, 2016 at 14:34

8 Answers 8

40

use inset with round property :

inset(0% 45% 0% 45% round 10px)
Sign up to request clarification or add additional context in comments.

4 Comments

Can you dig this a little dipper? I really don't understand how can I round the corners with inset with this kind of shape
perfect. elegant. exactly what i was looking for.
Mehrshad Cheshm Khavari for use of clip-path: w3schools.com/cssref/css3_pr_clip-path.php Yes you can just round a div, but in some cases if you need to use the clip-path: inset that was my solution make the border round
The inset property is not a substitute for a custom polygon, this is not a solution.
20

An SVG filter can round any kind of clip-path. You simply need to apply it to a parent element. Adjust the stdDeviation to control the radius:

.box {
  width: 423px;
  height: 90px;
  background-color: #b0102d;
  color: white;
  clip-path: polygon(100% 0%, 100% 50%, 100% 100%, 25% 100%, 0% 50%, 25% 0%);
}

.parent {
  filter: url('#goo');
  overflow:hidden;
  position: fixed;
  right:-50px;
  z-index: 1;
  margin-top: 10vw;
}
<div class="parent">
  <div class="box"></div>
</div>

<svg style="visibility: hidden; position: absolute;" width="0" height="0" xmlns="http://www.w3.org/2000/svg" version="1.1">
  <defs>
        <filter id="goo"><feGaussianBlur in="SourceGraphic" stdDeviation="8" result="blur" />    
            <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 19 -9" result="goo" />
            <feComposite in="SourceGraphic" in2="goo" operator="atop"/>
        </filter>
    </defs>
</svg>

Related: https://stackoverflow.com/a/65485455/8620333

2 Comments

This works well for me in Chrome, but not in Firefox. Are there any solutions for this?
nice, what if that shape has different color of border, how can we add border?
11

I've recently found success experimenting with approaches like this...

SVG

<svg width="0" height="0">
  <defs>
    <clipPath id="clipped">
      <circle cx="var(--myRad)" cy="var(--myRad)" r="var(--myRad)"></circle>
      <circle cx="var(--myRad)" cy="calc(var(--myHeight) - var(--myRad))" r="var(--myRad)"></circle>
      <circle cx="calc(var(--myWidth) - var(--myRad))" cy="calc(var(--myHeight) - var(--myRad))" r="var(--myRad)"></circle>
      <circle cx="calc(var(--myWidth) - var(--myRad))" cy="var(--myRad)" r="var(--myRad)"></circle>
      <rect y="var(--myRad)" width="var(--myWidth)" height="calc(var(--myHeight) - (2 * var(--myRad)))"></rect>
      <rect x="var(--myRad)" width="calc(var(--myWidth) - (2 * var(--myRad)))" height="var(--myHeight)"></rect>
    </clipPath>
  </defs>
</svg>

CSS

.clipped {
  --myWidth: 100vw;
  --myHeight: 10rem;
  --myRad: 2rem;
  clip-path: url(#clipped);
}

I found this useful as compared to using border-radius with overflow set to hidden, because this approach doesn't create a BFC or break things like sticky position and css perspective effects. Also, this allows you to "inset" the position of the svg paths to clip inside the element with a "corner-radius" if you want.

4 Comments

Can you post a pen?
@ElvioCavalcante not completely reduced, but try it in a chromium browser, and add prefixed properties for others, you can see how values are derived between this fiddle and my original answers example. jsfiddle.net/y7heo6md/1
For folks who missed the comment by @antoni above, my answer here is effectively doing the same thing as using the inset() method with the round option. Like clip-path: inset(0 round 2rem), but keep in mind the round option hasn't always been supported by browsers, so progressively enhance or just use this SVG approach for compat.
So can you not use var/calc for SVG dimensions? The jsfiddle you posted you converted everything to pixels, and I can't get an example to work based on what you posted here.
9

You can also mess around with the circle to get some different effects.

-webkit-clip-path: circle(60.0% at 50% 10%);
clip-path: circle(50.0% at 50% 50%);

Codepen

Too bad you can't combine the polygon and circle... or maybe you can and I haven't played around with it enough to figure it out. HTH

Comments

8

clip-path: inset(45% 0% 33% 10% round 10px)

Comments

1

I don't have a comment option yes, so I'm writing it as an answer..

you need to write as many points as possible to round the corner. Nothig else... for, example a few more points to make lower part bit rounder:

-webkit-clip-path: polygon(100% 0%, 100% 100%, 100% 100%, 25% 100%, 5% 70%,1% 60%, 0% 50%, 25% 0%);

oh, yes, or SVG as comment people here.. :)

Comments

1

You could use a child element and do a nested clip-path on that and the child's pseudo element. The parent will do a polygon clip on the shape first, then the pseudo will have an ellipse to round the borders. The clips will have a combined effect.

.parent, .parent div, .parent div:before {
  width: 423px;
  height: 90px;
  position: absolute;
}

.parent {
  right: 0;
  background-image: linear-gradient(to right, transparent 210px, #b0102d 210px);
  margin-top: 15vh;
}

.parent div {
  clip-path: polygon(100% 0%, 100% 100%, 25% 100%, 0 50%, 25% 0);
}

.parent div:before {
  content: "";
  background-color: #b0102d;
  clip-path: ellipse(200px 45px at 210px);
}
<div class="parent">
  <div></div>
</div>

Here is the demo with some adaptations to illustrate what's going on:

.parent, .parent div, .parent div:before {
  width: 423px;
  height: 90px;
  position: absolute;
}

.parent {
  right: 0;
  background-image: linear-gradient(to right, transparent 210px, yellow 210px);
  margin-top: 15vh;
}

.parent div {
  background-color: blue;
  clip-path: polygon(90% 0%, 90% 100%, 25% 100%, 0 50%, 25% 0);
}

.parent div:before {
  content: "";
  background-color: #b0102d;
  clip-path: ellipse(200px 45px at 210px);
}
<div class="parent">
  <div></div>
</div>

The horizontal size and position of the ellipse can be used to get a different effect on the edges. Note that the background starting postion of the parent needs to be adjusted to the same value as the placement of the ellipse (last value in the clip-path) because it fills up whatever gets clipped off on the right side. This can be visualised by removing background-color: blue from .parent div in the second demo.

Here is an additional Codepen to to try it out.

Comments

0

In 2025 we get to use the shape CSS function, thank goodness. So, cutting out a shape (such as a fancy gradient glow around another object) is much easier, even if it still looks a bit intimidating at first.

The shape I specified in the code below is actually two shapes: a rectangle 50px larger than its parent and a rectangle the same size as its parent with manually rounded corners using the curve command, and the second shape is "cut out" while the first shape is what is allowed to show, thanks to the evenodd fill rule.

.thing-you-want-to-have-a-sweet-glow::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(45deg, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1));
  --br: 10px; /* Border Radius */
  --dbr: 20px; /* double the Border Radius */
  border-radius: var(--br);
  filter: blur(var(--br));
  clip-path: shape(evenodd from -50px -50px, line to calc(100% + 50px) -50px, line to calc(100% + 50px) calc(100% + 50px), line to -50px calc(100% + 50px), close, line to var(--dbr) 0, line to calc(100% - var(--dbr)) 0, curve to 100% var(--dbr) with 100% 0, line to 100% calc(100% - var(--dbr)), curve to calc(100% - var(--dbr)) 100% with 100% 100%, line to var(--dbr) 100%, curve to 0 calc(100% - var(--dbr)) with 0 100%, line to 0 var(--dbr), curve to var(--dbr) 0 with 0 0);
}

2 Comments

How does "a fancy gradient glow" answer a question about rounding corners on a specific given shape?
Not sure what the gradient stuff is about but thank you for introducing me to the 'shape' function! Which happens to be supported on my current workplace's supported browsers (developer.mozilla.org/en-US/docs/Web/CSS/basic-shape/…)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.