Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                <!DOCTYPE html>
<html>

<head>
  <title>Drawing Lines</title>
  <style type="text/css">
    canvas {
      border: dotted 1px black;
    }
  </style>
  <link rel="stylesheet" href="../style.css" />
  <script>
    window.addEventListener("load", function() {
      var theCanvas = document.getElementById('Canvas1');
      if (theCanvas && theCanvas.getContext) {
        var ctx = theCanvas.getContext("2d");
        if (ctx) {
          // draw lines of varying widths
          for (var i = 0; i < 10; i++) {
            ctx.beginPath();
            ctx.lineWidth = i + 1;
            ctx.moveTo(25, 25 + i * 15);
            ctx.lineTo(475, 25 + i * 15);
            ctx.stroke();
          }
        }
      }
      // demonstrate the lineCap endings
      var theCanvas = document.getElementById('Canvas2');
      if (theCanvas && theCanvas.getContext) {
        var ctx = theCanvas.getContext("2d");
        if (ctx) {
          // draw the guidelines
          ctx.strokeStyle = "green";
          ctx.lineWidth = 1;
          ctx.beginPath();
          ctx.moveTo(50, 20);
          ctx.lineTo(50, 180);
          ctx.moveTo(450, 20);
          ctx.lineTo(450, 180);
          ctx.stroke();
          // draw lines using each lineCap;
          ctx.lineWidth = 25;
          ctx.strokeStyle = "black";
          ctx.lineCap = "butt";
          ctx.beginPath();
          ctx.moveTo(50, 50);
          ctx.lineTo(450, 50);
          ctx.stroke();
          ctx.lineCap = "round";
          ctx.beginPath();
          ctx.moveTo(50, 100);
          ctx.lineTo(450, 100);
          ctx.stroke();
          ctx.lineCap = "square";
          ctx.beginPath();
          ctx.moveTo(50, 150);
          ctx.lineTo(450, 150);
          ctx.stroke();
        }
      }
      // Show the lineJoin variations
      var theCanvas = document.getElementById('Canvas3');
      if (theCanvas && theCanvas.getContext) {
        var ctx = theCanvas.getContext("2d");
        if (ctx) {
          ctx.lineWidth = 15;
          ctx.strokeStyle = "black";
          ctx.lineJoin = "round";
          ctx.beginPath();
          ctx.moveTo(25, 150);
          ctx.lineTo(75, 50);
          ctx.lineTo(125, 150);
          ctx.stroke();
          ctx.lineJoin = "bevel";
          ctx.beginPath();
          ctx.moveTo(175, 150);
          ctx.lineTo(225, 50);
          ctx.lineTo(275, 150);
          ctx.stroke();
          ctx.lineJoin = "miter";
          ctx.beginPath();
          ctx.moveTo(325, 150);
          ctx.lineTo(375, 50);
          ctx.lineTo(425, 150);
          ctx.stroke();
        }
      }
      // Show the lineDash variations
      var theCanvas = document.getElementById('Canvas4');
      if (theCanvas && theCanvas.getContext) {
        var ctx = theCanvas.getContext("2d");
        if (ctx) {
          ctx.lineWidth = 15;
          ctx.strokeStyle = "black";
          ctx.setLineDash([5, 10]);
          ctx.beginPath();
          ctx.moveTo(50, 50);
          ctx.lineTo(450, 50);
          ctx.stroke();
          ctx.setLineDash([15, 5]);
          ctx.beginPath();
          ctx.moveTo(50, 100);
          ctx.lineTo(450, 100);
          ctx.stroke();
          ctx.setLineDash([]);
          ctx.beginPath();
          ctx.moveTo(50, 150);
          ctx.lineTo(450, 150);
          ctx.stroke();
        }
      }
    });
  </script>
</head>

<body>
  <h1>Drawing Lines</h1>
  <div id="content">
    <p>This example will draw several styles of lines. This one shows basic line width</p>
    <canvas id="Canvas1" width="500" height="200">Your browser does not support canvas.</canvas>

    <p>This example shows different settings for lineCap</p>
    <canvas id="Canvas2" width="500" height="200">Your browser does not support canvas.</canvas>

    <p>This example shows different settings for lineJoin</p>
    <canvas id="Canvas3" width="500" height="200">Your browser does not support canvas.</canvas>

    <p>This example shows different settings for lineDash</p>
    <canvas id="Canvas4" width="500" height="200">Your browser does not support canvas.</canvas>
  </div>
</body>

</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console