Canvas Core Drawing

Beginner
8 min read
Updated: Nov 2026
6 topic guides
Drawing hub

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.

Beginner path.

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:

JavaScript
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 topics

Straight segments and quick rectangles — the first shapes most beginners draw.

TopicDescriptionTutorial
Draw LinesmoveTo, lineTo, stroke, lineWidth, caps, dashes.Open
Draw RectanglesfillRect, strokeRect, clearRect shortcuts.Open

Arcs & curves

3 topics

Circles, arcs, and smooth curves with control points.

TopicDescriptionTutorial
Draw Arcarc() for circles and circular arcs.Open
Draw QuadraticquadraticCurveTo with one control point.Open
Draw BezierbezierCurveTo with two control points.Open

Path workflow

1 topic

Build multi-segment shapes and paint them as one path.

TopicDescriptionTutorial
Draw PathsbeginPath, 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.

Blue line, amber rectangle, teal arc — each uses the core path/shape APIs.

Canvas

line + rect + arc

How to Learn Core Drawing

A practical order for this hub:

  1. Confirm you can get a 2D context from a <canvas> (see the introduction).
  2. Draw a straight line with moveTo / lineTo / stroke.
  3. Add boxes with fillRect and strokeRect.
  4. Draw a circle or arc with arc.
  5. Try one control-point curve, then a Bezier.
  6. Combine segments in one path and paint with fill + stroke.

Frequently Asked Questions

Core drawing means the basic 2D path and shape APIs: lines, rectangles, arcs, curves, and the beginPath / stroke / fill workflow. Everything else (text, shadows, gradients, transforms) builds on these.
Lines, arcs, and curves use a path (beginPath, then stroke or fill). Rectangles also have shortcuts: fillRect, strokeRect, and clearRect, which draw without building a full path.
stroke() paints the outline of the current path. fill() paints the interior. You can use both on the same path. Style them with strokeStyle / fillStyle before you paint.
Start with Draw Lines (moveTo and lineTo), then Draw Rectangles, then Draw Arc. Curves and full path workflows come next once those feel comfortable.
Common causes: forgetting stroke() or fill(), matching colors to the background, never calling beginPath/moveTo, or sizing the canvas only with CSS so the bitmap stretches and looks wrong.
The introduction explains what Canvas is and how getContext works. This hub indexes the shape and path tutorials so you can jump into lines, rectangles, arcs, curves, and paths.

Start with Draw Lines

Open the first core shape guide — syntax, live preview, and examples.

Canvas Draw Lines →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful