CKTIS / CSS
superellipse(): shaping a corner, not sizing it
Combine a corner-shape parameter with border-radius and distinguish convex, bevelled and concave corners.
Version: CSS Modules
Syntax
border-radius: 40px; corner-shape: superellipse(2);superellipse(K) supplies a unitless corner-shape parameter. The size of the corner area still comes from border-radius; K is neither a radius nor a pixel distance. The named shapes correspond to particular parameters: 1 is round, 2 is squircle, 0 is bevel, and -1 is scoop. Positive and negative infinity correspond to square and notch. Intermediate numbers produce intermediate curves rather than a fixed list of shapes.
A zero radius leaves no corner area to reshape, even with a concave parameter. Large radii and opposing concave corners are constrained to prevent overlap; the argument alone therefore does not specify the final pixel contour. This is a newer CSS Borders feature: provide an ordinary rounded-corner fallback and check the target browsers. Accepting a declaration is not proof that every clipping, border or animation case is implemented correctly.
The example actually rasterizes an 80px red box with a 40px radius and samples alpha at 10,10 and 22,22. The squircle covers both samples; the bevel and round cover only the second. The scoop and notch cover neither, while the square covers both. With zero radius the scoop covers both again. These two samples distinguish the tested cases without claiming to validate the entire curve, anti-aliasing or all browsers.
Examples
async function pixels(shape,radius) {
const svg='<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80"><foreignObject width="80" height="80"><div xmlns="http://www.w3.org/1999/xhtml" style="width:80px;height:80px;background:red;border-radius:'+radius+'px;corner-shape:'+shape+'"></div></foreignObject></svg>';
const image=new Image();image.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(svg);await image.decode();
const canvas=document.createElement('canvas');canvas.width=canvas.height=80;
const context=canvas.getContext('2d');context.drawImage(image,0,0);
return [[10,10],[22,22]].map(([x,y])=>context.getImageData(x,y,1,1).data[3]).join(',');
}
for(const value of ['superellipse(0)','superellipse(1)','superellipse(2)','superellipse(-1)','superellipse(infinity)','superellipse(-infinity)'])console.log(value+': '+await pixels(value,40));
console.log('zero-radius: '+await pixels('superellipse(-1)',0));
console.log('length-argument: '+CSS.supports('corner-shape','superellipse(2px)'));Result
superellipse(0): 0,255 superellipse(1): 0,255 superellipse(2): 255,255 superellipse(-1): 0,0 superellipse(infinity): 255,255 superellipse(-infinity): 0,0 zero-radius: 255,255 length-argument: false
The output contains measured alpha bytes: 0 is transparent and 255 is opaque. The observed rasterization is from Chromium 157; the length argument 2px is rejected because K is unitless.