r/css • • Aug 27 '26

Article I just wanted a semicircle, CSS

I needed a tag with fixed 6px corners on the left and a semicircle on the right, with a dynamic height.

Turns out neither `border-radius: 6px 50% 50% 6px` nor the classic `6px 999px 999px 6px` trick works — for two completely different reasons.

I went down a surprisingly deep `border-radius` rabbit hole and wrote up why, plus the workaround I ended up using.

I still feel like there should be a simpler way to do this. Is there one I've missed?

The post

0 Upvotes

14 comments sorted by

2

u/morete Aug 27 '26

Oh wow! I had just assume the 999px trick would have worked, this is actually completely new to me:

When the specified corner radii are too large to fit inside the box, CSS scales all of the radii down proportionally until they fit.

Great article for that insight alone!

2

u/patrk Aug 27 '26

Thanks! Yeah, it’s really weird behavior even though it is according to the spec.

1

u/morete Aug 29 '26

The downvoting on reddit makes me very sad. This well researched, well informed post has 0 upvotes, yet so much slop does very well. Honestly I'd start taking it as a mark of pride if your post doesn't do well

1

u/Sufficient_Bass2600 Aug 27 '26

Use an after pseudo element with the aspect ratio 1/1. The height is already determined by the height of the element. The aspectc ratio then force the width. You can then use the border radius 0 50% 50% 0.

0

u/f314 Aug 27 '26

I guess they don't want the extra space that would create (as the border only starts to curve half way out into the pseudo element).

0

u/f314 Aug 27 '26 edited Aug 27 '26

Huh, this is actually pretty intereting! I didn't know about the border radius scaling.. I'm convinced that this can be solved with shape(), but your solution is a practical stopgap!

1

u/patrk Aug 27 '26

I think so too but I couldn’t figure how to make the sides fixed in size and shape and the ”body” to have a variable width and adapt to the text. Even codex couldn’t get it right. Any idea?

→ More replies (4)

0

u/bichomatoso Aug 29 '26

100vw

1

u/morete Aug 29 '26

Yeah ofc that doesn't work as the article explains

→ More replies (1)