Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use the native HTML <canvas> element, then get its 2D drawing context with JavaScript. It is blank until you draw into it. To make it drawable with a mouse, pen, or finger, listen for Pointer Events; to keep it sharp on high-density screens, size its backing buffer for the device pixel ratio rather than stretching a small bitmap with CSS.

Create a blank canvas

Add a <canvas> element with explicit intrinsic dimensions and obtain its 2D context. The dimensions determine the canvas’s drawing surface in pixels; CSS controls how large it appears on the page. If you omit the dimensions, the initial canvas size is 300 × 150 pixels. The element starts blank until a script draws into it.

<canvas id="drawing-canvas" width="800" height="500">
  Your browser does not support canvas; use the drawing controls below instead.
</canvas>
<script>
  const canvas = document.getElementById("drawing-canvas");
  const ctx = canvas.getContext("2d");
  if (!ctx) throw new Error("2D canvas is not supported");
  // No drawing calls yet: the canvas is blank and ready for drawing.
</script>

Set width and height as HTML attributes or DOM properties. Avoid setting only CSS dimensions: that scales the rendered surface and can make drawings distorted or blurry. The 2D context can be unavailable, so check the result of getContext("2d") before using it.

Make the canvas drawable with mouse, pen, or touch

Use Pointer Events instead of separate mouse and touch handlers. The same event family supports mouse, pen, and fingertip input. The important coordinate detail is that pointer positions are reported relative to the viewport, while your drawing commands use canvas coordinates. Convert between them using the displayed rectangle and the canvas backing dimensions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Wacom Intuos Small, Wired Graphic Drawing Tablet with Pen + Software
  • Wacom Intuos Small Graphics Drawing Tablet: Enjoy industry leading tablet performance in superior control and precision with Wacom's EMR, battery free technology that feels like pen on paper
  • Works With All Software: Wacom Intuos tablet can be used in any software program to explore new facets of digital creativity; draw, paint, edit photos/videos, create designs, and mark up documents
  • What the Professionals Use: Wacom's industry leading pen technology and pen to paper feeling makes it the preferred drawing tablet of professional graphic designers
  • Software and Training Included: Only Wacom gives you software with every purchase. Register your Intuos tablet and gain access to some of the best creative software and Wacom's online training
  • Wacom is the Global Leader in Drawing Tablet and Displays: For over 40 years in pen display and tablet market, you can trust that Wacom to help you bring your vision, ideas and creativity to life
let drawing = false;

function pointInCanvas(event) {
  const rect = canvas.getBoundingClientRect();
  return {
    x: (event.clientX - rect.left) * (canvas.width / rect.width),
    y: (event.clientY - rect.top) * (canvas.height / rect.height),
  };
}

canvas.addEventListener("pointerdown", (event) => {
  drawing = true;
  canvas.setPointerCapture(event.pointerId);
  const p = pointInCanvas(event);
  ctx.beginPath();
  ctx.moveTo(p.x, p.y);
});

canvas.addEventListener("pointermove", (event) => {
  if (!drawing) return;
  const p = pointInCanvas(event);
  ctx.lineTo(p.x, p.y);
  ctx.stroke();
});

function stopDrawing(event) {
  drawing = false;
  if (event && canvas.hasPointerCapture(event.pointerId)) {
    canvas.releasePointerCapture(event.pointerId);
  }
}
canvas.addEventListener("pointerup", stopDrawing);
canvas.addEventListener("pointercancel", stopDrawing);

Pointer capture keeps a stroke associated with the canvas after the pointer moves beyond its edge. End the stroke on both pointerup and pointercancel; otherwise, an interrupted gesture can leave the app thinking the user is still drawing. The coordinate conversion above accounts for the difference between the canvas’s displayed size and its drawing buffer.

Build a responsive, sharp canvas that keeps strokes on resize

A canvas can look blurry on a high-density screen if its backing bitmap has fewer pixels than the space in which it is displayed. Use window.devicePixelRatio to scale the backing width and height while keeping the intended CSS size. Scale the context by the same ratio so drawing coordinates can remain in CSS pixels.

Rank #2
Sale
XPPen Deco 01 V3 10x6 Drawing Tablet, 16K Battery-Free Stylus, 8 Keys
  • Word-first 16K Pressure Levels: The upgraded stylus features 16,384 levels of pressure sensitivity and supports up to 60 degrees of tilt, delivering smoother lines and shading for a natural drawing experience. With no battery or charging needed, it operates like a real pen, making it easy for beginners to create effortlessly. This functionality helps novice artists develop their skills and explore their creativity without the intimidation of complex tools
  • Designed for Beginners: This drawing pad desinged with 8 customizable shortcuts for both right and left-hand users, express keys create a highly ergonomic and convenient work platform
  • Perfectly Adapted for Android: The XPPen Deco 01 V3 art tablet supports connections with Android devices running version 10.0 and above. It is recommended to download the XPPen Tools Android application, which adapts to your smartphone's screen aspect ratio, ensuring accurate mapping. It also supports mapping on Android screens with different aspect ratios in portrait mode
  • Large Drawing Space, Bigger Bold Inspiration: This expansive drawing pad has10 x 6.25-inch helps you break through the limit between shortcut keys and drawing area
  • Easy Connectivity for Beginners: The Deco 01 V3 offers USB-C to USB-C connectivity, plus adapters for USB C. This ensures easy connection to various devices, allowing beginner artists to set up quickly and focus on their creativity without compatibility concerns. Whether using a laptop, tablet, or desktop, the Deco 01 V3 provides a seamless experience, making it an ideal choice for those just starting their digital art journey

Changing a canvas’s width or height clears its drawing buffer. For a simple blank canvas that is fine; for an editor, keep a stroke model and redraw it after resizing. This example stores stroke points as fractions of the displayed width and height, then redraws them at the new size. That preserves their relative placement when the canvas changes size.

const canvas = document.getElementById("drawing-canvas");
const ctx = canvas.getContext("2d");
if (!ctx) throw new Error("2D canvas is not supported");

const strokes = [];
let activeStroke = null;

function resizeCanvas() {
  const rect = canvas.getBoundingClientRect();
  const dpr = window.devicePixelRatio || 1;
  canvas.width = Math.round(rect.width * dpr);
  canvas.height = Math.round(rect.height * dpr);
  ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  redraw();
}

function normalizedPoint(event) {
  const rect = canvas.getBoundingClientRect();
  return {
    x: (event.clientX - rect.left) / rect.width,
    y: (event.clientY - rect.top) / rect.height,
  };
}

function redraw() {
  const rect = canvas.getBoundingClientRect();
  ctx.clearRect(0, 0, rect.width, rect.height);
  ctx.lineWidth = 3;
  ctx.lineCap = "round";
  ctx.lineJoin = "round";
  for (const stroke of strokes) {
    if (!stroke.length) continue;
    ctx.beginPath();
    ctx.moveTo(stroke[0].x * rect.width, stroke[0].y * rect.height);
    for (const point of stroke.slice(1)) {
      ctx.lineTo(point.x * rect.width, point.y * rect.height);
    }
    ctx.stroke();
  }
}

canvas.addEventListener("pointerdown", (event) => {
  canvas.setPointerCapture(event.pointerId);
  activeStroke = [normalizedPoint(event)];
  strokes.push(activeStroke);
  redraw();
});

canvas.addEventListener("pointermove", (event) => {
  if (!activeStroke) return;
  activeStroke.push(normalizedPoint(event));
  redraw();
});

function finishStroke() {
  activeStroke = null;
}
canvas.addEventListener("pointerup", finishStroke);
canvas.addEventListener("pointercancel", finishStroke);
window.addEventListener("resize", resizeCanvas);
resizeCanvas();

Use CSS to define a responsive display size, for example width: 100% and a maximum width, while retaining a consistent aspect ratio. The script measures the resulting displayed rectangle and sizes the backing buffer accordingly. If an app uses a different sizing method, keep its measurement and drawing coordinate systems in sync.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
HUION Inspiroy H640P 6x4 inch Drawing Tablet 8192 Pen Pressure
  • Customize Your Workflow: The 6 customizable press keys on Huion H640P drawing tablet for pc let you assign your most-used commands—like undo, zoom, brush switch, or save—so you can keep your hands on the tablet and your mind on the art. Whether you're a digital painter switching brushes, or a comic artist zooming in and out, these keys keep your workflow smooth and uninterrupted. Plus, the Huion driver lets you save different shortcut profiles for different apps, so you never have to reconfigure when switching software.
  • Professional Pen Performance: Huion H640P drawing pad for computer comes with the battery-free PW100 stylus that's always ready when inspiration strikes. With 8192 levels of pressure sensitivity, every light sketch, or bold stroke responds naturally to your hand—just like a real pen. The 5080 LPI resolution and 233 PPS report rate deliver lag-free, precise strokes, so you can draw confidently without second-guessing your cursor. The pen side buttons help you switch between pen and eraser instantly.
  • Compact and Portable: Huion H640P computer graphics tablet features a compact, ultra-portable design at just 0.3 inches thin and 0.61 lbs light, so it slides easily into your backpack—perfect for sketching in coffee shops, taking notes in class, or editing on the go between home and studio. The 6x4 inch active area offers enough room for natural pen movements while fitting comfortably on crowded desks, or lecture hall seats.
  • Stable Compatibility: Huion H640P graphic drawing tablet works seamlessly with Mac, Windows, Linux PCs, and Android smartphones/tablets (OS version 6.0 or later). Left-handed friendly, and you just need to flip the tablet and adjust the settings in the driver. Please note: H640P does NOT support iPhone/iPad.
  • Move Beyond the Mouse: Huion Inspiroy H640P is a pen tablet that replaces your mouse for more natural, precise control. Freehand draw, take notes, or even play OSU—everything you do with a mouse, you can do better with a pen. The precise tip makes it ideal for detailed photo editing, graphic design, or signing PDF. Meanwhile, the ergonomic pen grip helps you avoid the strain that comes from hours of using a mouse.

Complete small drawing page with clear, undo, and save

This standalone page combines a responsive canvas with pointer drawing, redraw-on-resize, and ordinary HTML buttons. It uses a retained stroke list so clear, undo, resize, and save have predictable behavior. The controls remain outside the canvas rather than being drawn into its pixels.

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Drawing canvas</title>
<style>
  body { font: 16px sans-serif; margin: 1rem; }
  .drawing-area { max-width: 800px; }
  canvas { display: block; width: 100%; aspect-ratio: 8 / 5; border: 1px solid #777; touch-action: none; }
  .controls { display: flex; gap: .5rem; margin-top: .75rem; }
</style>
<main class="drawing-area">
  <h1>Drawing canvas</h1>
  <p id="canvas-label">Draw in the area below with a mouse, pen, or touch.</p>
  <canvas id="drawing-canvas" width="800" height="500" aria-labelledby="canvas-label">
    Your browser does not support canvas. The drawing area is unavailable.
  </canvas>
  <div class="controls">
    <button id="undo" type="button">Undo</button>
    <button id="clear" type="button">Clear</button>
    <button id="save" type="button">Save PNG</button>
  </div>
</main>
<script>
  const canvas = document.getElementById("drawing-canvas");
  const ctx = canvas.getContext("2d");
  if (!ctx) throw new Error("2D canvas is not supported");
  const strokes = [];
  let activeStroke = null;

  function resizeCanvas() {
    const rect = canvas.getBoundingClientRect();
    const dpr = window.devicePixelRatio || 1;
    canvas.width = Math.round(rect.width * dpr);
    canvas.height = Math.round(rect.height * dpr);
    ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
    redraw();
  }
  function point(event) {
    const rect = canvas.getBoundingClientRect();
    return { x: (event.clientX - rect.left) / rect.width,
             y: (event.clientY - rect.top) / rect.height };
  }
  function redraw() {
    const rect = canvas.getBoundingClientRect();
    ctx.clearRect(0, 0, rect.width, rect.height);
    ctx.strokeStyle = "#111";
    ctx.lineWidth = 3;
    ctx.lineCap = "round";
    ctx.lineJoin = "round";
    for (const stroke of strokes) {
      if (!stroke.length) continue;
      ctx.beginPath();
      ctx.moveTo(stroke[0].x * rect.width, stroke[0].y * rect.height);
      for (const p of stroke.slice(1)) ctx.lineTo(p.x * rect.width, p.y * rect.height);
      ctx.stroke();
    }
  }
  canvas.addEventListener("pointerdown", (event) => {
    canvas.setPointerCapture(event.pointerId);
    activeStroke = [point(event)];
    strokes.push(activeStroke);
    redraw();
  });
  canvas.addEventListener("pointermove", (event) => {
    if (!activeStroke) return;
    activeStroke.push(point(event));
    redraw();
  });
  function endStroke(event) {
    activeStroke = null;
    if (event && canvas.hasPointerCapture(event.pointerId)) {
      canvas.releasePointerCapture(event.pointerId);
    }
  }
  canvas.addEventListener("pointerup", endStroke);
  canvas.addEventListener("pointercancel", endStroke);
  document.getElementById("undo").addEventListener("click", () => {
    strokes.pop(); activeStroke = null; redraw();
  });
  document.getElementById("clear").addEventListener("click", () => {
    strokes.length = 0; activeStroke = null; redraw();
  });
  document.getElementById("save").addEventListener("click", () => {
    const output = document.createElement("canvas");
    output.width = canvas.width;
    output.height = canvas.height;
    const out = output.getContext("2d");
    if (!out) return;
    out.drawImage(canvas, 0, 0);
    output.toBlob((blob) => {
      if (!blob) return;
      const link = document.createElement("a");
      link.href = URL.createObjectURL(blob);
      link.download = "drawing.png";
      link.click();
      URL.revokeObjectURL(link.href);
    }, "image/png");
  });
  window.addEventListener("resize", resizeCanvas);
  resizeCanvas();
</script>
</html>

The save action exports the current pixels as a PNG file. If you add controls such as color choice or brush width, keep those as real form controls and apply their values while drawing or redrawing. If the drawing represents meaningful information, offer an alternative way to inspect or enter that information; a canvas’s pixels are not semantic HTML content.

Rank #4
4 Pack LCD Writing Tablet for Kids, 8.5 Inch Colorful Doodle Board Drawing Tablet, Educational Learning Toys Birthday Gifts for Boys Girls Age 3 4 5 6 7 8
  • 4 Pack for More Fun: Apply the newest flexible liquid crystal technology, brighter and clearer than most LCD writing tablet. Take pressure-sensitive technology, you can draw lines of different thicknesses through different pressure levels. Package includes 4 pack lcd writing tablet (Blue, Light blue, Green and Pink), free children's imagination and creativity.
  • 8.5 Inch Colorful Lcd writing Tablet: TQU kids LCD doodle board is a creative education and learning toy, perfect support for drawing, writing, spelling, math, remark, and notes which can let your kids freely release their natural instincts. With erase button on the front and lock switch. You can draw and erase easily by pressing the button on the front of the board. The pen fits snug on top of tablet and it will not come loose.
  • Easy to use and Durable: The LCD writing tablet for kids is easy to use, just use the stylus to write, draw, scribble, doodle anything you want. Press the erase button to clear the screen in one second. Or press the lock key to save the screen contents. Our magic reusable drawing tablet is built in a button battery.
  • Safe & Portable Toddler Travel Toys: Great for quiet, take-along entertainment. It’s an easy way to color on the go without lugging a bunch of stuff in the car or to a restaurant or church.
  • Perfect Gift Idea: The multi-functional LCD writing tablet is a great gift choice for kids. It can be an educational toy for preschoolers. A perfect parent-pick gift for 3 4 5 6 7 8 year old girls and boys on back to school, homeschool, birthday, Easter, Children's Day, Thanksgiving Day, Christmas and any occasion.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose the right canvas model and input approach

Decision Good fit Trade-off
Native 2D canvas or WebGL Use 2D for straightforward drawing and pixel-based output. WebGL is oriented toward GPU rendering; it adds complexity when the task is only simple 2D strokes.
Fixed intrinsic size or responsive high-DPI Use fixed dimensions for a fixed-size drawing surface; use a DPR-scaled buffer when its display size responds to layout or high-resolution screens. Changing intrinsic dimensions clears pixels. A responsive editor needs a redrawable model or saved bitmap.
Pointer input or broader access Pointer Events cover mouse, pen, and touch input. Canvas pixels do not provide semantic controls. Provide keyboard-accessible HTML controls and an alternative where the drawing’s meaning matters.
Immediate raster strokes or retained strokes Directly drawing each stroke is simplest for a disposable surface. A retained stroke model enables redraw after resize and supports undo; it requires storing points and replaying them.

Troubleshoot common canvas problems

  • The canvas is blank, but nothing happens when I draw. Confirm that the script finds the intended canvas, that getContext("2d") returned a context, and that pointer handlers are attached to that element. Check that the drawing flag or active stroke is set on pointer down and cleared on pointer up or cancel.
  • The stroke is offset or has the wrong scale. Compare viewport coordinates from clientX/clientY with the canvas’s displayed rectangle and backing dimensions. Convert coordinates rather than using event coordinates as canvas pixels directly.
  • The drawing looks stretched or blurry. Do not rely on CSS-only resizing of a differently sized backing bitmap. Set intrinsic dimensions to match the displayed dimensions, accounting for devicePixelRatio, and scale the drawing context consistently.
  • The drawing disappears after the window resizes. Assigning canvas width or height clears the drawing buffer. Store strokes or another representation and redraw after resizing; a blank-only canvas needs no preservation logic.
  • Touch scrolls the page instead of drawing. For a drawing surface, set an appropriate touch-action policy in CSS, such as touch-action: none, and test the intended page interaction on touch devices.
  • Undo, keyboard use, or assistive technology is missing. Canvas pixels are not regular HTML controls. Add labeled buttons and other HTML controls, ensure they work with a keyboard, and provide an alternative for meaningful drawing content.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server, not a drawing-canvas library: it can capture a page containing your canvas, but it does not create the interactive drawing surface or replace the implementation above. If your goal is to capture the page, a single GET request returns an image or PDF. See the ScreenshotNeo documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://your-site.example/drawing -o shot.webp

Before capture, it can accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and other MCP clients.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo’s free plan.

Best Value
Sale
XPPen Artist 13.3 Pro V2 Drawing Tablet with Screen, 16K, Full-Laminated
  • PLEASE NOTE:XPPen Artist13.3 Pro drawing tablet Need to connect with computer,you need to use it with your computer or laptop, the 3 in 1 cable is included
  • Drawing Tablet with Screen: Tilt Function- XPPen Artist 13.3 Pro supports up to 60 degrees of tilt function, so now you don't need to adjust the brush direction in the software again and again. Simply tilt to add shading to your creation and enjoy smoother and more natural transitions between lines and strokes
  • Graphics Tablets: High Color Gamut- The 13.3 inch fully-laminated FHD Display pairs a superb color accuracy of 88% NTSC (Adobe RGB≧91%,sRGB≧123%) with a 178-degree viewing angle and delivers rich colors, vivid images, and dazzling details in a wider view. Your creative world is now as powerful as it is colorful
  • Drawing Pad: One is enough- The sleek Red Dial on the display is expertly designed with creators in mind, its strategic placement allows for natural drawing postures. With just one wheel, you can effortlessly zoom in and out, adjust brush sizes, and flip the canvas—all tailored to suit the habits of everyday artists. The 8 customizable shortcut keys allow you to personalize your setup, streamlining your workflow and enhancing creative efficiency
  • Universal Compatibility & Software Support:supports Windows 7 (or later), Mac OS X 10.10 (or later), Chrome OS 88 (or later), and Linux systems. Fully compatible with major creative software including Photoshop, Illustrator, SAI, and Blender 3D. Register your device to access additional programs like ArtRage 5 and openCanvas for expanded creative possibilities.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.