Skip to content

Instantly share code, notes, and snippets.

@pouyakary
Last active May 22, 2025 11:18
Show Gist options
  • Save pouyakary/136fafc75a14abd867e0100856add5a0 to your computer and use it in GitHub Desktop.
Save pouyakary/136fafc75a14abd867e0100856add5a0 to your computer and use it in GitHub Desktop.

CSS Clip-Path Shape() Based Squircle

Pure CSS Squircle has always been the fantasy of a web developer's good night's sleep. It is possible to clip a div with a custom SVG, but you have to make that SVG, put it on top of your HTML, then reference it inside the CSS, and regenerate it on each resize... It is a nightmare and the performance is horrible. You can go mad and implement a CSS Houdini to render squircle..., while this is mind-blowingly awesome, it doesn't work in Safari, and still not Pure CSS (my nightmare for those who disable JavaScript on their clients...). While there is work underway to add the superellipse() to CSS, the shape() function is now supported on all major browsers (not on every user, they will take ages to update their stuff), but still, it is available and you can use this code to have that effect in your website. You're welcome 🥰


Screenshot 2025-05-17 at 1 08 22 AM
.squircle {
    --squircle-displacement:
        25pt;

    clip-path: shape(
      from 0 var(--squircle-displacement),
      curve to var(--squircle-displacement) 0 with 0 0 / 0 0,
      hline to calc(100% - var(--squircle-displacement)),
      curve to 100% var(--squircle-displacement) with 100% 0 / 100% 0,
      vline to calc(100% - var(--squircle-displacement)),
      curve to calc(100% - var(--squircle-displacement)) 100% with 100% 100% / 100% 100%,
      hline to var(--squircle-displacement),
      curve to 0 calc(100% - var(--squircle-displacement)) with 0 100% / 0 100%,
      close
    );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment