This page cannot be displayed because your browser does not support scroll-driven animations with CSS.
Open this page in Chrome on desktop.
Or
Watch this summary as a video on YouTube:
Back to HomeThis page cannot be displayed because your browser does not support scroll-driven animations with CSS.
Open this page in Chrome on desktop.
Watch this summary as a video on YouTube:
Back to HomeThis page shows an interactive slide deck that is currently not responsive. Resize your browser window to at least 770px wide and 650px tall.
export const Page = () => (
<html>
<h1>Hi there</h1>
<svg width="100" height="100" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="25" fill="red" />
</svg>
</html>
);
This means you can generate an SVG from React or any other frontend library.
<svg
width="100"
height="100"
viewBox="0 0 200 200"
>
<circle cx="100" cy="100" r="50" />
</svg>
<svg
width="200"
height="200"
viewBox="0 0 200 200"
>
<circle cx="100" cy="100" r="50" />
</svg>
<svg
width="200"
height="200"
viewBox="-100 -100 200 200"
>
<circle r="50" />
</svg>
width
and height
attributes and its coordinate system with the viewBox
attribute. 0,0
. <svg
width="200"
height="200"
viewBox="0 0 200 200"
>
<circle
cx="100"
cy="100"
r="50"
fill="red"
fill="none"
stroke="red"
stroke-width="5"
class="red-circle"
/>
</svg>
.red-circle {
fill: none;
stroke: red;
stroke-width: 2;
}
We can define a circle by setting its center coordinates, cx
and cy
, and
its radius, r
.
To change its color, we can set the fill
attribute. We can use any value
that’s valid in CSS.
To set the border color and width, we can use the stroke
and stroke-width
attributes.
<svg
width="200"
height="200"
viewBox="0 0 200 200"
>
<rect
x="25"
y="50"
width="150"
height="100"
/>
</svg>
x
and y
, and the size with width
and height
. function Diagram() {
const dataPoints = [3, 4, 7, 5, 3, 6];
return (
<svg width="200" height="200">
{dataPoints.map((dataPoint, index) => (
<rect
key={index}
x={42.5 + index * 20}
y={150 - dataPoint * 10}
width="15"
height={dataPoint * 10}
fill="#CD803D"
/>
))}
</svg>
);
}
<path d=". . ." />
path
element. <svg width="100" height="100" viewBox="0 0 100 100">
<path
class="line"
d="M 50, 100 L 150, 100"
d="
M 50, 40 L 150, 40
M 50, 100 L 150, 100
M 50, 160 L 150, 160"
/>
</svg>
.line {
stroke: #333333;
stroke-width: 24;
stroke-linecap: round;
}
d
attribute of a path consists of segments. Here, we have a Move-to and a Line-to segment. We set a coordinate for both. <svg width="200" height="200" viewBox="-15 -15 30 30">
<circle r="6" />
<path id="ray" d="M 0, 11 L 0, 14" />
<use href="#ray" transform="rotate(45)" />
<use href="#ray" transform="rotate(90)" />
<use href="#ray" transform="rotate(135)" />
<use href="#ray" transform="rotate(180)" />
<use href="#ray" transform="rotate(225)" />
<use href="#ray" transform="rotate(270)" />
<use href="#ray" transform="rotate(315)" />
</svg>
#ray {
stroke: black;
stroke-width: 2;
stroke-linecap: round;
}
viewBox
property. path
. id
to this path, reuse it with the use
element, and rotate
it into position. <svg width="200" height="400">
<g id="windmill-head">
<circle r="8" />
<path
id="arm"
d="
M -7 -20
C -7 -10 7 -10 7 -20
L 2 -80
L -2 -80" />
<use href="#arm" transform="rotate(+120)" />
<use href="#arm" transform="rotate(-120)" />
</g>
<path d="M 93 300 L 107 300 L 103 165 L 97 165" />
</svg>
#windmill-head {
translate: 100, 150;
animation: 4s linear infinite rotate;
}
@keyframes rotate {
from {
rotate: 0deg;
}
to {
rotate: 360deg;
}
}
g
element. <svg width="450" height="450" > <path d="M 100 350Start Position Q 225 50Control Point 350 350End Position "
stroke="#fa3838" stroke-width="20" fill="none" /></svg>
The quadratic bezier curve has one control point that defines how to bend the line. Drag the coordinates to see how the code changes.
<svg width="450" height="450" > <path d="M 100 350Start Position C 70 100Control Point 1 380 100Control Point 2 350 350End Position "
stroke="#fa3838" stroke-width="20" fill="none" /></svg>
A cubic bezier curve has two control points, giving you much greater flexibility.
<svg width="450" height="450" > <path d="M 145 174Start Position A 150Radius X 120Radius Y 20Rotation 0Large Arc Flag 0Sweep Flag 288 314End Position "
stroke="#fa3838" stroke-width="20" fill="none" /></svg>
Arcs are one of the most complicated path segments. Click here to read more about them.