Inverted Corners logo

InvertedCorners

A Houdini Paint worklet for inverted corners.

Getting started

🧪  Please remember this is experimental and may not work in all browsers.

Add the following to your HTML to include Inverted Corners using unpkg.

<script src="https://unpkg.com/inverted-corners/lib/inverted-corners.min.js"></script>

That’s it!

For more advanced setups (including the worklet yourself, adding the paint module in a React app etc), read the README.

Check support

To check if a browser supports the Paint API via JavaScript:

if ('paintWorklet' in CSS) {
    // Browser supports paint worklets, add the module
    CSS.paintWorklet.addModule('https://unpkg.com/inverted-corners/lib/inverted-corners-worklet.min.js');
} else {
    console.warn('Paint Worklet is not supported on your browser.');
}

To check if a browser supports the Paint API via CSS:

@supports (background: paint(something)) {
    /* Browser supports paint worklets, do something here */
}

Usage

You can access the paint worklet with either background: paint(inverted-corners); or -webkit-mask-image: paint(inverted-corners);

Corners

You can set the radius of each corner using the --corner-radius property.

It uses a shorthand syntaxt similar to the native border-radius property.

--corner-radius: <top-left> <top-right> <bottom-right> <bottom-left>;

For example,

--corner-radius: 20 20 -20 -20;

Positive values produce normal corners (similar to the border-radius property), while negative values produce inverted corners.

Backgrounds

You can set the background using the --background property.

--background: #fff;

To add a shadow, use filter: drop-shadow() instead of box-shadow.

You can also use gradients! Just set multiple colors separated with a comma.

Basic gradient

--background: cyan, purple;

Tri-color gradient

--background: #879af2, #d3206b, #fda000;

Color stops

To set a custom color stop, use the following format:

<color> <color-stop>

where <color-stop> is a number between 0.0 and 1.0.

For example,

--background: #879af2, #d3206b 0.2, #fda000;

Angles

To set a custom angle, add the rotation (in degrees) as the first parameter:

--background: 90deg, cyan, purple;

Masks

You can also use the mask-image (and the prefixed -webkit-mask-image) property to apply a mask and reshape an element.

-webkit-mask-image: paint(inverted-corners);
mask-image: paint(inverted-corners);

When using masks, you can apply a background with the regular background, background-color, and background-image CSS properties.

Keep in mind, that while this method is really useful in some cases, you'll lose the ability to add shadows to the element.

Images

To set an image as the background of the element, you can use the list-image-type property. This is necessary to workaround an issue where images wouldn't load with custom image properties on Chrome/Opera/Edge.

list-style-image: url(YOUR_IMAGE);

Examples

Browser tab

Navbar

Instant Messaging

Bugs & Features

If you have spotted any bugs, or would like to request additional features from the library, please file an issue.

License

The MIT License, check the LICENSE file.