The corner shape utility for Tailwind CSS
Installation
npx shadcn@latest add @caprice/corner-shape@caprice-ui/tailwindInstall the following dependencies:
npm install @caprice-ui/tailwindCopy and paste the following code into your project.
/** * @utility corner-shape-* * Sets the corner shape of an element. * @example * <div class="flex p-8 rounded-lg corner-smooth supports-corner:rounded-2xl"> * ... * </div> * @link https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/corner-shape * @source https://x.com/frederic_ooo/status/1989681563106218177/ */@theme inline { --corner-shape-round: round; --corner-shape-scoop: scoop; --corner-shape-bevel: bevel; --corner-shape-notch: notch; --corner-shape-square: square; --corner-shape-squircle: squircle; --corner-shape-smooth: superellipse(1.25);}@utility corner-* { corner-shape: --value(--corner-shape-*); corner-shape: --value([*]);}@utility corner-t-* { corner-block-start-shape: --value(--corner-shape-*); corner-block-start-shape: --value([*]);}@utility corner-b-* { corner-block-end-shape: --value(--corner-shape-*); corner-block-end-shape: --value([*]);}@utility corner-l-* { corner-block-start-shape: --value(--corner-shape-*); corner-block-start-shape: --value([*]);}@utility corner-r-* { corner-block-end-shape: --value(--corner-shape-*); corner-block-end-shape: --value([*]);}@utility corner-tl-* { corner-start-start-shape: --value(--corner-shape-*); corner-start-start-shape: --value([*]);}@utility corner-tr-* { corner-start-end-shape: --value(--corner-shape-*); corner-start-end-shape: --value([*]);}@utility corner-bl-* { corner-end-start-shape: --value(--corner-shape-*); corner-end-start-shape: --value([*]);}@utility corner-br-* { corner-end-end-shape: --value(--corner-shape-*); corner-end-end-shape: --value([*]);}/** Custom variant to check if the browser supports the corner-shape property */@custom-variant supports-corner { @supports (corner-shape: squircle) { @slot; }}Usage
Import the utility into your global.css file:
@import "tailwindcss";
@import "@caprice-ui/tailwind/utility/corner-shape";Add the utility classes to your markup / components:
<div class="rounded-lg bg-neutral-100 p-4 corner-smooth supports-corner:rounded-2xl">
I'm smooth on chromium, but have similar radius on non corner-shape supporting browsers with the supports media query
</div>