Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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.


                  <canvas id="canvas" width="500" height="300" style="border: solid 1px #000;box-sizing: border-box;"></canvas>
  <div class="option">
    <div class="color">
      <a href="" class="black" data-color="0, 0, 0, 1"></a>
      <a href="" class="red" data-color="255, 0, 0, 1"></a>
      <a href="" class="blue" data-color="0, 0, 255, 1"></a>
    <div class="bold">
      <a href="" class="small" data-bold="1">小</a>
      <a href="" class="middle" data-bold="5">中</a>
      <a href="" class="large" data-bold="10">大</a>
  <input type="button" value="clear" id="clear">
  <a id="download" href="#" download="canvas.jpg">ダウンロード</a>
  <div id="result"><img src=""></div>
  <script src="//"></script>


    width: 250px;
  .color > a{
    display: inline-block;
    width: 20px;
    height: 20px;
    background-color: #000000;
    background-color: #ff0000;
    background-color: #0000ff;


                    // canvas
    var cnvs = document.getElementById('canvas');
    var ctx = cnvs.getContext('2d');

    // 変数宣言
    const cnvWidth = 500;
    const cnvHeight = 500;
    var cnvColor = "255, 0, 0, 1";  // 線の色
    var cnvBold = 5;  // 線の太さ
    var clickFlg = 0;  // クリック中の判定 1:クリック開始 2:クリック中
    var bgColor = "rgb(255,255,255)";

    // canvasの背景色を設定(指定がない場合にjpeg保存すると背景が黒になる)

    // canvas上でのイベント
      clickFlg = 1; // マウス押下開始
      clickFlg = 0; // マウス押下終了
      // マウス移動処理
      if(!clickFlg) return false;
      draw(e.offsetX, e.offsetY);

    // 描画処理
    function draw(x, y) {
      ctx.lineWidth = cnvBold;
      ctx.strokeStyle = 'rgba('+cnvColor+')';
      // 初回処理の判定
      if (clickFlg == "1") {
        clickFlg = "2";
        ctx.lineCap = "round";  // 線を角丸にする
        ctx.moveTo(x, y);
      } else {
        ctx.lineTo(x, y);

    // 色の変更
    $(".color a").click(function(){
      cnvColor = $(this).data("color");
      return false;

    // 線の太さ変更
    $(".bold a").click(function(){
      cnvBold = $(this).data("bold");
      return false;

    // 描画クリア

    // canvasを画像で保存
      canvas = document.getElementById('canvas');
      var base64 = canvas.toDataURL("image/jpeg");
      document.getElementById("download").href = base64;

    function setBgColor(){
      // canvasの背景色を設定(指定がない場合にjpeg保存すると背景が黒になる)
      ctx.fillStyle = bgColor;