Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


  <canvas style="touch-action: none;" id="canvas1" ></canvas>
  Click and hold or press and hold to draw in the space above.
  <button onclick="clear_canvas()">Clear</button>






                // credits to tbuckley@ that provided the first implementation.

const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d", {desynchronized: true, alpha: false});

function getPoint(e) {
  const rect = canvas.getBoundingClientRect();
  return { x: e.clientX - rect.left, y: e.clientY - };

let point;
canvas.addEventListener("pointerdown", (e) => {
  point = getPoint(e);
canvas.addEventListener("pointermove", (e) => {
  if (!point)
  const events = e.getCoalescedEvents();
  events.forEach((e) => {
    const new_point = getPoint(e);
    ctx.moveTo(point.x, point.y);
    ctx.lineTo(new_point.x, new_point.y);
    point = new_point;

canvas.addEventListener("pointerup", (e) => {
  point = null;

const angle = screen.orientation.angle % 360;
// = `rotateZ(${angle}deg)`;
width = window.innerWidth * 0.9;
height = window.innerHeight * 0.8;
if (angle % 180 == 90) {
  canvas.width = height;
  canvas.height = width;
} else {
  canvas.width = width;
  canvas.height = height;
function clear_canvas() {
  ctx.fillStyle = 'white';
  ctx.fillRect(0, 0, width, height);
  // Don't use here ctx.clearRect() in combination with 
  // chrome://flags/#tint-gl-composited-content because clearRect() uses 
  // a transparent fill, and we'd be seeing the background.