How to draw a circle in JavaScript?

Following is the code to draw a circle in JavaScript −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   .circleCanvas {
      border: 3px solid #110101;
<h1>Draw a circle in JavaScript</h1>
<canvas class="circleCanvas" width="400" height="200"></canvas><br />
<button class="Btn">CLICK HERE</button>
<h3>Click on the above button to create a circle in the above canvas element</h3>
   let canvasEle = document.querySelector(".circleCanvas");
   let BtnEle = document.querySelector(".Btn");
   BtnEle.addEventListener("click", () => {
      var circle = canvasEle.getContext("2d");
      circle.arc(180, 100, 90, 0, 2 * Math.PI);


The above code will produce the following output −

On clicking the ‘CLICK HERE’ button −

Updated on: 21-Jul-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started