This repo contains a shape() function generator for writing CSS clip-path and offset-path values without hand-coding complex path syntax.
Every generated shape must start with the from command, which defines the starting point of the path. After from, you can add additional commands such as line to, vline by, hline by, and arc.
Use to for absolute coordinates, and by for relative coordinates.
See the most up to date documentation on MDN.
- Use the generator UI to build a
shape()expression. - The app outputs valid CSS for
clip-pathandoffset-path. - Generated shapes can be copied into your stylesheet.
A shape function begins with shape( and must include from first.
Example:
clip-path: shape(
from 0 0,
line by 10px 1rem,
vline by 1vw,
arc to 100% 50% of 20px 20px large cw rotate 45deg,
close
);from x y- Start a new path at coordinates
xandy. - You can also prefix the first command with
evenoddornonzero(default) to set the fill rule.
- Start a new path at coordinates
line <to | by> x y- Draw a straight line
hline <to | by> x- Horizontal line
vline <to | by> y- Vertical line
curve to x y with cpx1 cpy1- Quadratic curve using a single control point.
curve to x y with cpx1 cpy1 / cpx2 cpy2- Cubic curve using two control points.
smooth to x y- Smooth quadratic curve to the point.
smooth to x y with cpx2 cpy2- Smooth cubic curve to the point using a second control point.
arc to x y of radiusX radiusY [large] [cw] [rotate angle]- Draw an arc to the point with the given radii.
move to x y- Move the current point without drawing.
close- Close the current path.
frommust be the first command.- The default fill rule is
nonzero. fill-ruleis supported only onclip-path/ fill-based shapes.fill-ruleis not valid inoffset-path; using it inoffset-pathcan invalidate the value.
The generator supports a mix of units:
- Absolute units:
px,rem,em,%,vw,vh,vmin,vmax custom- Select
customfrom the unit dropdown and type any value directly into the input. - This is the right way to use custom properties, logical units, container query expressions, keywords like
centerorstart, anchor positioning, or unfamiliar units. - Example values:
--my-offset,calc(100% - 1rem),anchor(left),50dppx,-10px
- Select
shape(from 0 0, line by 10px 1rem, vline by 1vw, hline by 2vmin, line to 50% 25%);offset-path: shape(from 0 0, line to 100px 0, line to 100px 100px, close);clip-pathacceptsshape()values in browsers that support CSS Shapes Level 2 syntax.offset-pathalso acceptsshape()values, butfill-ruleis not valid there.- For
offset-path, use a path definition appropriate for motion paths rather than fill-based boundary shapes.
Install dependencies:
npm installRun development server:
npm run devBuild for production:
npm run buildPreview the production build:
npm run previewindex.html— app entry HTMLsrc/main.tsx— React app bootstrapsrc/App.tsx— main componentstyle.css— global stylesvite.config.ts— Vite configtsconfig.json/tsconfig.node.json— TypeScript settings