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.


Save Automatically?

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 id="contents"></div>


                body {
  margin: 0;
  padding: 0;

#contents {
  width: 100vw;
  height: 100vh;


                // Canvas追加
const target = document.getElementById('contents')      // 追加先
const CreateCanvas = document.createElement('canvas')   // canvas element作成
CreateCanvas.setAttribute('id', 'canvas')               // canvas に id 付与
target.appendChild(CreateCanvas)                        // 追加

function draw() {
  // 追加先のサイズ取得
  let Cwidth = target.clientWidth
  let Cheight = target.clientHeight

  // Canvas サイズ設定
  CreateCanvas.width = Cwidth
  CreateCanvas.height = Cheight               

  // Canvas・コンテキスト取得
  const canvas = document.getElementById('canvas')
  const ctx = canvas.getContext('2d')

  // Canvasの中央取得
  let CenterW = Cwidth/2
  let CenterH = Cheight/2
  // 矩形の塗りつぶし描画
  ctx.fillStyle = 'rgba(42, 54, 59, 0.8)'
  ctx.fillRect(CenterW - 210, CenterH - 110, 400, 200)

  // 輪郭描画の色指定 / 矩形の輪郭描画
  ctx.strokeStyle = 'rgba(232, 74, 95, 0.8)'
  ctx.strokeRect(CenterW - 190, CenterH - 90, 400, 200)

  // 領域の消去
  ctx.clearRect(CenterW - 170, CenterH - 70, 400, 200) 

// 画面リサイズ時再描画
window.onresize = draw

// 初回描画