Plays once
Heart Drawing Itself
Think of the heart as one long piece of string. CSS moves the string out of view, then slides it back into place.
stroke-dashoffset: var(--path-length);
@keyframes draw {
to {
stroke-dashoffset: 0;
}
}
Unit 6 Teaching Demo
This demo shows two simple ideas: a heart that draws itself and a sun that rotates around the correct center.
Heart is drawing. Sun is rotating.
Plays once
Think of the heart as one long piece of string. CSS moves the string out of view, then slides it back into place.
stroke-dashoffset: var(--path-length);
@keyframes draw {
to {
stroke-dashoffset: 0;
}
}
Repeats continuously
Turn off “Rotate around the sun.” The rays will use the center of the entire SVG instead of the center of the sun.
Green: sun center Red: whole SVG center
transform-box: fill-box;
transform-origin: center;
SVG elements do not always rotate around their own center.
transform-box: fill-box tells the browser to use the sun
rays themselves when finding the center.
Some users prefer less movement. When reduced motion is on, the sun stops and the heart stays visible.
@media (prefers-reduced-motion: reduce) {
.draw-path,
.sun-rays {
animation: none;
}
.draw-path {
stroke-dashoffset: 0;
}
}