Canvas Core Drawing

Definition
Core drawing is the foundation of the Canvas 2D API: you open a path, add lines or curves, then stroke() or fill() to paint pixels. Rectangles also have one-shot helpers like fillRect.
This hub indexes the shape tutorials in the Canvas track. Learn what Canvas is on /canvas, then open Draw Lines, Draw Rectangles, Draw Arc, and the curve/path guides below.
Lines → rectangles → arcs → quadratic / Bezier curves → full paths. Each page has a live preview and examples.
Syntax
The shared recipe for almost every core shape:
const canvas = document.getElementById("demo");
const ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.moveTo(40, 40); // start point
ctx.lineTo(200, 40); // straight segment
ctx.strokeStyle = "#2563eb";
ctx.lineWidth = 4;
ctx.stroke(); // paint the outline
// Rectangle shortcut (no path required)
ctx.fillStyle = "#f59e0b";
ctx.fillRect(40, 70, 120, 60); Topics
All core drawing guides in this Canvas tutorial series (6 tutorials).
Lines & boxes
2 topicsStraight segments and quick rectangles — the first shapes most beginners draw.
| Topic | Description | Tutorial |
|---|---|---|
Draw Lines | moveTo, lineTo, stroke, lineWidth, caps, dashes. | Open |
Draw Rectangles | fillRect, strokeRect, clearRect shortcuts. | Open |
Arcs & curves
3 topicsCircles, arcs, and smooth curves with control points.
| Topic | Description | Tutorial |
|---|---|---|
Draw Arc | arc() for circles and circular arcs. | Open |
Draw Quadratic | quadraticCurveTo with one control point. | Open |
Draw Bezier | bezierCurveTo with two control points. | Open |
Path workflow
1 topicBuild multi-segment shapes and paint them as one path.
| Topic | Description | Tutorial |
|---|---|---|
Draw Paths | beginPath, closePath, fill, stroke, and combining shapes. | Open |
Live Preview
Toggle a line, rectangle, and arc on one canvas — the same APIs covered in the topic pages.
How to Learn Core Drawing
A practical order for this hub:
- Confirm you can get a 2D context from a
<canvas>(see the introduction). - Draw a straight line with
moveTo/lineTo/stroke. - Add boxes with
fillRectandstrokeRect. - Draw a circle or arc with
arc. - Try one control-point curve, then a Bezier.
- Combine segments in one path and paint with fill + stroke.
Frequently Asked Questions
Start with Draw Lines
Open the first core shape guide — syntax, live preview, and examples.
8 people found this page helpful
