Kala Tech

Experimenting With Scroll-Driven Corner Shape Animations

Web design constantly pushes the boundaries of geometry and motion. One of the most exciting recent additions to CSS is the `corner-shape()` property, which provides mathematical precision to your corners, going far beyond the standard `border-radius`.

Recently, CSS-Tricks published an inspiring article highlighting how to combine this new geometric capability with Scroll-Driven Animations. Let's explore how it works.

What is `corner-shape()`?

Unlike `border-radius`, which only curves the edges of a rectangle, the `corner-shape()` property allows you to define complex mathematical shapes for your corners, such as a `superellipse`. Because these shapes are mathematically defined, the browser natively understands how to interpolate and animate between them smoothly.

For instance, you can define different corner styles like so: ```css .card { corner-shape: superellipse(notch); } ```

Combining with Scroll-Driven Animations

Scroll-driven animations link an animation's progress directly to the user's scroll position rather than time. This creates highly interactive and fluid experiences without the need for complex JavaScript event listeners.

Here is an example of animating a sticky header's corners from a notched appearance to perfectly square as the user scrolls down the page:

```css @keyframes smooth-corners { from { corner-shape: superellipse(notch); } to { corner-shape: superellipse(square); } }

header { position: sticky; top: 0;

/* Bind the animation to the scroll progress */ animation: smooth-corners linear both; animation-timeline: scroll(); animation-range: 0 100px; } ```

In this snippet, as the user scrolls the first `100px`, the header's notched corners will smoothly morph into sharp squares. Add this to your Tailwind classes (e.g., `dark:bg-gray-900`) to create a stunning dark mode sticky navigation.

Browser Support

As with all bleeding-edge CSS features, browser support is something to keep an eye on. Fully supporting scroll-driven `corner-shape()` animations currently requires Chrome 139+. For other browsers, make sure to provide standard `border-radius` fallbacks so your users still see a polished interface.

Conclusion

Combining `corner-shape()` interpolation with scroll timelines opens up a vast space for creative UI micro-interactions. Try experimenting with it in your next prototype!