Bézier Curves and SVG Paths
Tags: svg, beginners, beziercurve
Published: 2020-05-01 09:39:55

---
title: Bézier Curves and SVG Paths
published: true
description: What are Bézier Curves, how do they work, and how do they relate to SVG Paths
tags: svg, beginners, bezier curve
canonical_url: https://svg-path-visualizer.netlify.app/bezier-curve
---
Bézier Curves are one of the 3 command types (with lines and arcs) of an SVG path. It is the mathematical name for a special type of curves that can be defined with 4 points: the "Start" point, the "End" point, and 2 "Control" points.

Most design tools allow you to draw Bézier curves (sometimes called "Pen tool" as in Photoshop, Illustrator, or Figma - or "Vector tool" as in Sketch) and let you define those 4 points.

![Sketch screencast](https://dev-to-uploads.s3.amazonaws.com/i/kktc3mousdpvw3ybvr2e.gif)

The curve goes from the "Start" point to the "End" point while the "Control" points define its curvature.

The reason why those curves are so popular is because of how "smooth" they look like and how fast and easy they are to compute. You might even have done some curve stitching and already drawn one by hand in the case where the 2 control points are the same (this is a special case of Bézier Curves but we will come back to it later).

![Curve Stitching](https://dev-to-uploads.s3.amazonaws.com/i/oeqzcrjy4qn1yza1ayg5.gif)

## How does it work?

To get a feel of how Bézier Curves work, imagine you are building a segment of a railway track between 2 places 🚂. The direction and the speed of the train at the beginning and the end are a constraint given by the railway controllers in order for the traffic to be good across the line.

![Where shall we go?](https://dev-to-uploads.s3.amazonaws.com/i/kc19qhyuj9z2q0g2i06v.png)

Between the 2 places, the journey needs to be as smooth as possible, which means that the track needs to turn the least possible while respecting the instructions of the controllers.

In our case, that means continuing in the same direction as we arrive while slowly turning to the right.

![Round path](https://dev-to-uploads.s3.amazonaws.com/i/6q6s2m3n17q17aws6h46.png)

If there was no speed constraint at the end (and so no direction), we could turn until we face the end and then go straight towards it. Otherwise, we need to take some leeway to match the direction at the end.

![Straight path](https://dev-to-uploads.s3.amazonaws.com/i/pbncf9hkpus2b13fcirx.png)

## How does it translate to SVG?

### The Curve command

The command associated with a Bézier Curve is `C`. The start point is always a given (the position at the end of the previous command - or (0,0) if it's the first command).

![Curve command example](https://dev-to-uploads.s3.amazonaws.com/i/6tfg7cxzepzjkf5leiix.png)

### The Smooth Curve command

There are also some special cases of Bézier Curves that have shortcut notations in SVG.

A common case is when you have multiple curves one after the other and you want it to smoothly transition between them. To do so, you need to have the first control point of the next curve be the reflection of the second control point of the previous curve. So as long as you specify one, you shouldn't need to specify the other one. That's what the `S` command is for (S for smooth).

![Smooth Curve Command example](https://dev-to-uploads.s3.amazonaws.com/i/qqwfa50z3kv9dy0zuvgc.png)

If you look back at the Sketch screencast, you will notice that we actually define the reflection of the second control point, implicitly preparing for the next curve segment.

### The Quadratic Curve command

Another case is when both control points are superimposed. In that case, you also don't need to specify them both, only one is enough. That what the `Q` command is for (Q for quadratic).

![Quadratic curve command example](https://dev-to-uploads.s3.amazonaws.com/i/3a1qipxivx440j9fxy1e.png)

That's our curve stitching drawing!

### The Smooth Quadratic Curve command

Now, what if we want to continue our quadratic Bézier Curve with another quadratic Bézier Curve? Well, we only have to specify the end point! That what the `T` command is for (T for Smooth Quadratic obviously).

![Smooth Quadratic curve command example](https://dev-to-uploads.s3.amazonaws.com/i/xebza3nrx4b3qrjt04l4.png)

---

This explanation is taken from [SVG Path Visualizer](https://svg-path-visualizer.netlify.app), a tool to visualize and explain how SVG paths work.