CSS offset-path Reference Guide

Just a guy who loves to write code and watch anime.
Search for a command to run...

Just a guy who loves to write code and watch anime.
No comments yet. Be the first to comment.
Qualities that make outstanding builders.

Bipedal vs quadrupedal: how many legs This is about the number of legs the creature walks on. Bipedal. Two legs. Humans, ostriches, T-rex, kangaroos, most fantasy humanoids. Quadrupedal. Four legs. Do

Intro You hear "lerp" and "smoothstep" everywhere in game dev. They sound like math jargon. They're not. Both are small tools that do the same job: smoothly move from one value to another. The problem

What is Kinematics Kinematics is the math field. It's the study of how things move without worrying about forces (which would be dynamics). FK and IK are the two branches: forward kinematics and inver

Intro Textures are usually the biggest cost in a 3D scene. Memory, bandwidth, and load time all get eaten by them. Resizing them is the obvious lever. There's more. This post is about the less obvious

offset-path = places any element along a curved path (like a train on tracks) offset-distance = controls position along the path (0% = start, 100% = end)
.element {
offset-path: path("M0 0 Q100 50 200 0"); /* curved path */
offset-distance: 0%; /* position on path */
transition: offset-distance 1s; /* animate movement */
}
.element.active {
offset-distance: 100%; /* move to end */
}
Defines the path using SVG path syntax
offset-path: path("M50 50 Q150 0 250 50"); /* quadratic curve */
offset-path: path("M0 0 L100 0 L100 100 L0 100 Z"); /* square path */
Position along the path (percentage)
offset-distance: 0%; /* start of path */
offset-distance: 50%; /* middle of path */
offset-distance: 100%; /* end of path */
Which part of element touches the path
offset-anchor: center; /* element center on path */
offset-anchor: top left; /* element top-left on path */
offset-anchor: 10px 10px; /* custom point */
How element rotates along path
offset-rotate: auto; /* follows path direction (default) */
offset-rotate: 0deg; /* no rotation */
offset-rotate: 90deg; /* fixed rotation */
/* Uses SVG coordinate system */
rect {
offset-path: path("M20 20 Q80 20 80 80");
offset-anchor: 0 0; /* default: top-left corner */
}
Coordinates: SVG viewBox units
Default anchor: Top-left corner (0,0)
Path origin: SVG coordinate system
/* Uses pixel coordinates from element position */
.button {
offset-path: path("M0 0 Q150 0 300 200");
offset-anchor: center; /* default: center */
}
Coordinates: Pixels relative to element's current position
Default anchor: Center of element
Path origin: Element's top-left corner
.element {
offset-path: path("M0 0 Q100 -50 200 0");
offset-distance: 0%;
transition: offset-distance 2s ease;
}
.element:hover {
offset-distance: 100%;
}
.element {
offset-path: path("M100 50 A50 50 0 1 1 100 51"); /* circle */
offset-distance: 0%;
animation: loop 3s infinite linear;
}
@keyframes loop {
to {
offset-distance: 100%;
}
}
.element {
offset-path: path("M50 100 Q150 50 250 100 Q350 150 450 100");
offset-distance: 0%;
}
.button {
offset-path: path("M0 0 Q50 -30 100 0");
offset-distance: 0%;
transition: offset-distance 0.3s ease;
}
.button:active {
offset-distance: 100%;
}
.spinner {
offset-path: path("M50 25 A25 25 0 1 1 50 26");
animation: spin 1s infinite linear;
}
@keyframes spin {
to {
offset-distance: 100%;
}
}
.cd-wrapper {
offset-path: path("M32 32C96.5 -25.5 132.865 26.0836 140 192");
offset-distance: 0%;
transition: all 0.5s;
}
.cd-wrapper[aria-pressed="true"] {
offset-distance: 100%;
width: 192px;
height: 192px;
}
/* Line */
path('M0 0 L100 100') /* from (0,0) to (100,100) */
/* Quadratic curve */
path('M0 0 Q50 -50 100 0') /* control point at (50,-50) */
/* Cubic curve */
path('M0 0 C25 -25 75 -25 100 0') /* two control points */
/* Arc */
path('M0 0 A50 50 0 0 1 100 0') /* arc with radius 50 */
/* Complex shape */
path('M50 0 Q100 25 50 50 Q0 25 50 0') /* diamond shape */
/* SVG element - uses SVG coordinates */
circle {
offset-path: path("M20 20 Q80 20 80 80");
}
/* DOM element - uses pixels from current position */
.div {
offset-path: path("M0 0 Q60 0 120 60");
}
/* Default anchors are different! */
/* SVG: top-left, DOM: center */
/* Fix by being explicit */
.element {
offset-anchor: center; /* or whatever you want */
}
/* This goes right */
path('M0 0 L100 0')
/* This goes left (backwards!) */
path('M100 0 L0 0')
/* Good - animates offset-distance */
.element {
transition: offset-distance 1s;
}
/* Avoid animating offset-path itself */