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

              
                <figure>
  <div data-svg-container></div>
  <figcaption>SVG Path Compounds with relative commands</figcaption>
</figure>
              
            
!

CSS

              
                @layer settings, base, svg;
@layer svg {
  figcaption {
    margin-top: 0.6em;
    font-style: italic;
  }
  svg {
    max-width: calc(100vmin - var(--s-body-bezel) * 2);
    box-shadow: 0 0.2em 1em 0 color-mix(in sRGB, var(--c-txt) 10%, var(--c-bg));
  }
}
@layer settings {
  :root {
    --s-body-bezel: 1em;

    color-scheme: light dark;

    --_white: #fff;
    --_gray: #111112;
    --_red: light-dark(#e60000, #ff4242);
    --_aqua: light-dark(#00856f, #09ecc6);
    --_blue: light-dark(#026fe3, #3998fe);
    --_purple: light-dark(#6d00c7, #e733ff);
    --_green: light-dark(#008009, #4dec09);
    --c-txt: light-dark(var(--_gray), var(--_white));
    --c-bg: light-dark(var(--_white), var(--_gray));
  }

  html,
  body {
    margin: 0;
    height: 100dvh;
    box-sizing: border-box;
  }
  figure {
    text-align: center;
    margin: 0;
  }
}
@layer base {
  body {
    color: var(--c-txt);
    background: var(--c-bg);
    padding: var(--s-body-bezel);
    align-content: center;
  }
}

              
            
!

JS

              
                const doc = { w: 100, h: 40 };
const gridStepSize = 10;

const lines = [
  { d: `M10 10 L 10 30 L 30 30`, color: "var(--_red)" },
  { d: `M40 10 l 0 20 l 20 0`, color: "var(--_blue)" },
  { d: `M70 10 l 0 20 L 90 30`, color: "var(--_green)" }
];

function drawPaths() {
  const els = [];
  lines.forEach(({ d, color }) => {
    const path = makeSVGEl("path", {
      d,
      stroke: color,
      "stroke-width": 1.5,
      fill: "none"
    });
    els.push(path);
  });
  return els;
}

/**
 * SVG Example Boilerplate Stuff
 */
const title = "Compound Angular Paths on a grid.";
const gridBuffer = { x: 10, y: 5 };
const width = doc.w + (gridBuffer?.x || 0);
const height = doc.h + (gridBuffer?.y || 0);
const animationControlBtn = document.querySelector("[data-play-pause]");
const animationResetBtn = document.querySelector("[data-reset]");
const container = document.querySelector("[data-svg-container]");
const renderHandleCheckBox = document.getElementById("render-handle");
const gridStrokeWidth = 0.2;
const cutoffCorrection = (gridStrokeWidth / 2) * -1;
const gridColor = "currentColor";

function makeSVG(title, svgContentChildrenArray = []) {
  const svg = makeSVGEl("svg", {
    viewBox: `${cutoffCorrection} ${cutoffCorrection} ${width} ${height}`,
    xmlns: "http://www.w3.org/2000/svg",
    role: "img"
  });

  const titleEl = makeSVGEl("title");
  titleEl.textContent = title;
  svg.appendChild(titleEl);

  const grid = drawGrid();
  svg.appendChild(grid);

  svgContentChildrenArray.forEach((child) => svg.appendChild(child));
  return svg;
}

const svg = makeSVG(title, drawPaths());
container.appendChild(svg);

function drawGrid(
  sW = gridStrokeWidth,
  c = gridColor,
  labelStyle = "font-size:5px;font-family:monospace"
) {
  const totalHorizontalLines = Math.floor(doc.h / gridStepSize);
  const totalVerticalLines = Math.floor(doc.w / gridStepSize);

  const g = makeSVGEl("g", { class: "grid", style: `opacity: 0.8;` });
  const yAxisLabels = makeSVGEl("g", {
    class: "y-axis-labels",
    style: labelStyle
  });
  const xAxisLabels = makeSVGEl("g", {
    class: "x-axis-labels",
    style: labelStyle
  });
  let pathDefinitionString = "";
  for (let i = 0; i < totalHorizontalLines; i++) {
    pathDefinitionString += `M0 ${i * gridStepSize} H${width}`;
    const labelEl = makeSVGEl("text", {
      x: width,
      y: i * gridStepSize,
      dy: "1em",
      dx: "-0.4em",
      fill: c,
      "text-anchor": "end"
    });
    labelEl.textContent = i === 0 ? "y" : i * gridStepSize;
    yAxisLabels.appendChild(labelEl);
  }
  for (let i = 0; i < totalVerticalLines; i++) {
    pathDefinitionString += `M${i * gridStepSize} 0 V${height}`;
    const labelEl = makeSVGEl("text", {
      x: i * gridStepSize,
      y: height,
      dy: "-0.4em",
      dx: "0.2em",
      fill: c
    });
    labelEl.textContent = i === 0 ? "x" : i * gridStepSize;
    xAxisLabels.appendChild(labelEl);
  }
  const path = makeSVGEl("path", {
    d: pathDefinitionString,
    stroke: c,
    "stroke-width": sW,
    fill: "none"
  });
  g.appendChild(path);
  g.appendChild(yAxisLabels);
  g.appendChild(xAxisLabels);
  return g;
}

function makeSVGEl(type, attrs) {
  const el = document.createElementNS("http://www.w3.org/2000/svg", type);
  for (let key in attrs) {
    el.setAttribute(key, attrs[key]);
  }
  return el;
}

              
            
!
999px

Console