HTML Canvas Draw Arc

Beginner
7 min read
Updated: Nov 2026
5 examples
Live preview

Definition

On an <canvas>, ctx.arc() adds a circular arc to the current path. Use a full turn (0 to 2 * Math.PI) for a circle, or a smaller span for a slice.

Angles are in radians, measured from the positive x-axis. After arc(), call stroke() or fill() to paint. Start each separate shape with beginPath().

Baseline · Widely available.

CanvasRenderingContext2D.arc() is a stable Canvas 2D method across modern browsers since about July 2015.

Naming note.

MDN documents the last argument as counterclockwise. Older texts may say anticlockwise — same boolean idea (default false = clockwise).

Syntax

arc.js
ctx.arc(x, y, radius, startAngle, endAngle);
ctx.arc(x, y, radius, startAngle, endAngle, counterclockwise);

arc() only builds the path. Pair it with beginPath(), then stroke() and/or fill().

Parameters

Arguments for arc() (Canvas 2D API):

ParameterDescriptionTry it
x, yCenter of the arc in canvas coordinatesTry it
radiusDistance from center to the arc; must be positiveTry it
startAngleStart angle in radians (0 = positive x-axis / 3 o’clock)Try it
endAngleEnd angle in radians; use 2 * Math.PI for a full circleTry it
counterclockwiseOptional. true = counter-clockwise; default falseTry it

Quick conversions: 90° = Math.PI / 2, 180° = Math.PI, 360° = 2 * Math.PI. Or use degrees * Math.PI / 180.

Global Attributes

The <canvas> tag also supports the Global Attributes in HTML.

Live Preview

Adjust radius and angles, then toggle fill or counter-clockwise travel.

55
6.28

Angles start at 0 (right) and increase clockwise by default.

Canvas

arc(200, 110, 55, 0, 6.28)

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Stroke a Full Circle

Use 0 to 2 * Math.PI, then stroke().

HTML
<canvas id="demo" width="300" height="160" aria-label="Stroked blue circle"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");
  ctx.beginPath();
  ctx.arc(150, 80, 50, 0, 2 * Math.PI);
  ctx.strokeStyle = "#2563eb";
  ctx.lineWidth = 3;
  ctx.stroke();
</script>
Try It Yourself

How It Works

  1. Start a path with beginPath().
  2. Call arc(centerX, centerY, radius, 0, 2 * Math.PI) for a full turn.
  3. Set stroke style (strokeStyle, optional lineWidth).
  4. Paint the outline with stroke().

Example 2 — Fill a Circle

Same arc, but use fill() instead of stroke().

HTML
<canvas id="demo" width="300" height="160" aria-label="Filled green circle"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");
  ctx.beginPath();
  ctx.arc(150, 80, 50, 0, 2 * Math.PI);
  ctx.fillStyle = "#16a34a";
  ctx.fill();
</script>
Try It Yourself

How It Works

  1. Define the circle path with arc(...).
  2. Choose a fill color via fillStyle.
  3. Call fill() to paint the interior.
  4. Optional: call both fill() and stroke() for a filled shape with an outline.

Example 3 — Partial Arc (Semicircle)

Stop at Math.PI (180°) for a half circle outline.

HTML
<canvas id="demo" width="300" height="160" aria-label="Orange semicircle stroke"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");
  ctx.beginPath();
  ctx.arc(150, 90, 55, 0, Math.PI);
  ctx.strokeStyle = "#ea580c";
  ctx.lineWidth = 4;
  ctx.stroke();
</script>
Try It Yourself

How It Works

  1. Keep start at 0 (right side of the circle).
  2. Set end to Math.PI — halfway around clockwise.
  3. Stroke the path to see only that arc (not a closed pie).
  4. Try other ends: Math.PI / 2 (90°), 3 * Math.PI / 2 (270°).

Example 4 — Pie Slice with Degrees

Convert degrees to radians, then close to the center for a wedge.

HTML
<canvas id="demo" width="300" height="160" aria-label="Purple pie slice"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");
  const toRad = (deg) => deg * Math.PI / 180;
  const cx = 150, cy = 80, r = 55;

  ctx.beginPath();
  ctx.moveTo(cx, cy);
  ctx.arc(cx, cy, r, toRad(0), toRad(110));
  ctx.closePath();
  ctx.fillStyle = "#7c3aed";
  ctx.fill();
</script>
Try It Yourself

How It Works

  1. Convert degrees with deg * Math.PI / 180.
  2. moveTo(center) so the fill includes the wedge point.
  3. Draw the arc for the outer curve.
  4. closePath() + fill() seals the slice back to the center.

Example 5 — Counter-Clockwise Travel

Pass true as the sixth argument to reverse direction.

HTML
<canvas id="demo" width="300" height="160" aria-label="Two arcs clockwise and counter-clockwise"></canvas>
<script>
  const ctx = document.getElementById("demo").getContext("2d");

  ctx.beginPath();
  ctx.arc(90, 80, 40, 0, Math.PI / 2, false);
  ctx.strokeStyle = "#2563eb";
  ctx.lineWidth = 4;
  ctx.stroke();

  ctx.beginPath();
  ctx.arc(210, 80, 40, 0, Math.PI / 2, true);
  ctx.strokeStyle = "#dc2626";
  ctx.stroke();
</script>
Try It Yourself

How It Works

  1. Same angles, two directions: both use 0 to Math.PI / 2.
  2. Blue uses false (default clockwise) — short quarter down.
  3. Red uses true — the long way the other direction.
  4. Call beginPath() twice so the strokes stay separate.

Edge Cases & Pitfalls

Most blank arcs come from missing stroke/fill, wrong units, or path state.

units

Radians, not degrees

Passing 90 means ~14 full turns, not 90°. Multiply by Math.PI / 180.

path

Always beginPath() for separate shapes

Without it, arcs connect to previous path points and can look like unexpected lines.

radius

Radius must be positive

Zero draws nothing useful. Negative radius is invalid and may throw IndexSizeError.

paint

arc() alone is invisible

It only updates the path. You must stroke() or fill() afterward.

related

arcTo() is not the same

arcTo() rounds a corner between two lines. Use arc() when you know a center and radius.

Browser Support

ctx.arc() is part of the Canvas 2D API in every modern browser.

✓ Baseline · Widely available

arc()

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support circular arcs and full circles. Internet Explorer 9+ also supports arc().

98% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet All modern
Full support
Internet Explorer 9+
Supported
ctx.arc() Widely supported

Bottom line: Safe to use for circles, arcs, and pie charts everywhere modern Canvas 2D runs.

Key Takeaways

  • Role: arc() adds a circular path; stroke()/fill() paint it.
  • Circle: 0 to 2 * Math.PI with a positive radius.
  • Angles: radians from the positive x-axis; convert degrees when needed.
  • Direction: sixth argument true draws counter-clockwise.

One line: beginPath() → arc(...) → stroke() or fill().

Default CSS Settings

Drawing arcs is a Canvas API concern. The <canvas> element still uses typical user-agent CSS:

default.css
canvas {
  display: inline;
}

Set bitmap size with HTML width/height. CSS-only sizing scales the bitmap and can blur arcs.

Frequently Asked Questions

arc() adds a circular arc (or a full circle) to the current path. You still need stroke() or fill() to paint it on the canvas.
No — they are radians, measured from the positive x-axis. Convert with degrees * (Math.PI / 180).
Use startAngle 0 and endAngle 2 * Math.PI (a full turn). Then call stroke() or fill().
If true, the arc travels counter-clockwise from start to end. If false (default), it travels clockwise.
Common causes: forgetting beginPath(), not calling stroke() or fill(), radius of 0, or identical start and end angles for a tiny slice.
arc() draws around a center with a radius. arcTo() creates a rounded corner between two tangent lines — useful for smooth path joins.

Next: Quadratic Curves

Learn quadraticCurveTo() for smooth bends with one control point.

Canvas Draw Quadratic →

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