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.


                <div class="container">
  <canvas id="canvas" width="640" height="480"></canvas>


                body {
  background: #333;
  color: #fff;

canvas {
  position: absolute;
  top: 0;
  left: 0;
  max-width: 100%;
  max-height: 100%;
  background: #000;

.container {
  position: relative;
  max-width: 640px;
  margin: 0 auto;

.container:before {
  display: block;
  padding-top: 75%;
  content: "";


                const canvas = document.getElementById("canvas"),
  ctx = canvas.getContext("2d");

const dpr = window.devicePixelRatio || 1,
  width = canvas.width,
  height = canvas.height;

// Canvasをピクセル比で拡大
canvas.width *= dpr;
canvas.height *= dpr;
// CSSで元のサイズに戻す = width + "px"; = height + "px";

ctx.transform(dpr, 0, 0, -dpr, 0, height * dpr);

ctx.fillStyle = "#fff";

let x = 80,
  y = 240, // 円の位置
  vx = 60, // X方向の速さ [px/s]
  lastTime; // 前回の呼び出し時間 [ms]

const tick = (time) => {
  if (!lastTime) lastTime = time;
  const dt = (time - lastTime) / 1000; // 経過時間 [s]

  // 位置を変更
  x += vx * dt;

  // 画面の消去
  ctx.clearRect(0, 0, canvas.width, canvas.height);

  // 点の描画
  ctx.arc(x, y, 25, 0, Math.PI * 2);

  lastTime = time;