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

              
                <svg viewBox="0 0 100 75">
  <path d="M15,35 C15,60 50,60 50,35 50,10 85,10 85,35" id="bezier" fill="none" stroke="hsla(0, 75%, 50%, 0.2)" stroke-width="0.5" />
  <text font-family="Source Sans Pro" font-size="6" fill="hsla(210, 75%, 50%, 0.85)">
    <textPath href="#bezier" id="tp" startOffset="10%">
     Text on an interactive bezier path!
    </textPath>
  </text>
</svg>
<label for="sOffset">Text start offset:</label>
<input type="range" min="0" max="100" value="10" id="sOffset">
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro);
*, *::before, *::after {
  margin: 0;
  padding: 0;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
html {
  font-family: Source Sans Pro, serif;
  min-height: 100%;
}
body {
  background-color: hsl(0, 0%, 10%);
  color: hsl(0, 0%, 85%);
  margin: .5em;
}
svg {
  background-color: hsl(0, 0%, 12%);
  stroke-linecap: round;
}
circle {
  fill: hsla(0, 0%, 100%, 0.02);
  stroke: hsla(120, 0%, 0%, 0.25);
  stroke-width: 0.05;
  -ms-touch-action: none;
  touch-action: none;
}
circle:hover {
  fill: hsla(0, 0%, 75%, 0.25);
}
circle:active {
  fill: hsla(0, 0%, 75%, 0.5);  
}
line {
  stroke: hsla(60, 75%, 50%, 0.1);
  stroke-width: 0.5;
}
              
            
!

JS

              
                var svgEl = document.querySelector("svg");
var pathEl = document.querySelector("#bezier");
var pathElSegList = pathEl.pathSegList;
var evtStartTarget = {};
var pointArray = [{x: 15, y: 35}, {x: 15, y: 60}, {x: 50, y: 60}, {x: 50, y: 35}, {x: 50, y: 10}, {x: 85, y: 10}, {x: 85, y: 35}];

document.querySelector("#sOffset").addEventListener("input", function(ev) {
  document.querySelector("#tp").setAttribute("startOffset", ev.target.value + "%");
});

// draw initial UI
svgEl.appendChild(uiLine(pointArray[0].x, pointArray[0].y, pointArray[1].x, pointArray[1].y, 1));
svgEl.appendChild(uiLine(pointArray[2].x, pointArray[2].y, pointArray[3].x, pointArray[3].y, 2));
svgEl.appendChild(uiLine(pointArray[3].x, pointArray[3].y, pointArray[4].x, pointArray[4].y, 3));
svgEl.appendChild(uiLine(pointArray[5].x, pointArray[5].y, pointArray[6].x, pointArray[6].y, 4));

for (var i = 0; i < pathElSegList.numberOfItems; i++) {
  svgEl.appendChild(uiDot(pathElSegList.getItem(i).x, pathElSegList.getItem(i).y, 3*i));
  if ("x1" in pathElSegList.getItem(i)) {
    svgEl.appendChild(uiDot(pathElSegList.getItem(i).x1, pathElSegList.getItem(i).y1, 3*(i-1)+1));
  }
  if ("x2" in pathElSegList.getItem(i)) {
    svgEl.appendChild(uiDot(pathElSegList.getItem(i).x2, pathElSegList.getItem(i).y2, 3*(i-1)+2));
  }
}

function uiLine(x1, y1, x2, y2, i) {
  var lineEl = document.createElementNS("http://www.w3.org/2000/svg", "line");
  lineEl.setAttribute('x1', x1);
  lineEl.setAttribute('y1', y1);
  lineEl.setAttribute('x2', x2);
  lineEl.setAttribute('y2', y2);
  lineEl.setAttribute('id', "line" + i);
  return lineEl;
}

function uiDot(x, y, i) {
  var circleEl = document.createElementNS("http://www.w3.org/2000/svg", "circle");
  circleEl.setAttribute('cx', x);
  circleEl.setAttribute('cy', y);
  circleEl.setAttribute('r', 2);
  circleEl.addEventListener("mousedown", mdEvent, true);
  circleEl.addEventListener("touchstart", mdEvent, true);
  circleEl.setAttribute("id", "dot" + i);
  return circleEl;
}

// mouse/touch event handling
function mdEvent (evt) {
  evt.preventDefault();
  evtStartTarget = evt.target;
  document.addEventListener("mousemove", mmEvent, true);
  document.addEventListener("mouseup", muEvent, true);
  document.addEventListener("touchmove", mmEvent, true);
  document.addEventListener("touchend", muEvent, true);
}

function mmEvent (evt) {
  var pointIndex = 0;
  evt.preventDefault();
  var p = svgEl.createSVGPoint();
  if(evt.targetTouches) {
    p.x = evt.targetTouches[0].clientX;
    p.y = evt.targetTouches[0].clientY;
  } else {
    p.x = evt.clientX;
    p.y = evt.clientY;
  }
  p = coordinateTransform(p);
  pointIndex = parseInt(evtStartTarget.getAttribute("id").slice(-1), 10);
  pointArray[pointIndex].x = p.x.toFixed(2);
  pointArray[pointIndex].y = p.y.toFixed(2);
  updateUI(pointIndex);
}

function muEvent (evt) {
  evt.preventDefault();
  document.removeEventListener("mousemove", mmEvent, true);
  document.removeEventListener("mouseup", muEvent, true);
  document.removeEventListener("touchmove", mmEvent, true);
  document.removeEventListener("touchend", muEvent, true);    }

// update the ui
function updateUI (index) {
  // draw dots
  evtStartTarget.setAttribute("cx", pointArray[index].x);
  evtStartTarget.setAttribute("cy", pointArray[index].y);
  // draw lines
  switch (index) {
    case 0:
    case 1:
      var lineEl = document.querySelector("#line1");
      lineEl.setAttribute("x1", pointArray[0].x);
      lineEl.setAttribute("y1", pointArray[0].y);
      lineEl.setAttribute("x2", pointArray[1].x);
      lineEl.setAttribute("y2", pointArray[1].y);
      break;
    case 2:
    case 3:
    case 4:
      var lineEl = document.querySelector("#line2");
      lineEl.setAttribute("x1", pointArray[2].x);
      lineEl.setAttribute("y1", pointArray[2].y);
      lineEl.setAttribute("x2", pointArray[3].x);
      lineEl.setAttribute("y2", pointArray[3].y);
      var lineEl = document.querySelector("#line3");
      lineEl.setAttribute("x1", pointArray[3].x);
      lineEl.setAttribute("y1", pointArray[3].y);
      lineEl.setAttribute("x2", pointArray[4].x);
      lineEl.setAttribute("y2", pointArray[4].y);
      break;
    case 5:
    case 6:
      var lineEl = document.querySelector("#line4");
      lineEl.setAttribute("x1", pointArray[5].x);
      lineEl.setAttribute("y1", pointArray[5].y);
      lineEl.setAttribute("x2", pointArray[6].x);
      lineEl.setAttribute("y2", pointArray[6].y);
  }
  // draw bezier path
  pathElSegList[0].x = pointArray[0].x;
  pathElSegList[0].y = pointArray[0].y;
  pathElSegList[1].x1 = pointArray[1].x;
  pathElSegList[1].y1 = pointArray[1].y;
  pathElSegList[1].x2 = pointArray[2].x;
  pathElSegList[1].y2 = pointArray[2].y;
  pathElSegList[1].x = pointArray[3].x;
  pathElSegList[1].y = pointArray[3].y;
  pathElSegList[2].x1 = pointArray[4].x;
  pathElSegList[2].y1 = pointArray[4].y;
  pathElSegList[2].x2 = pointArray[5].x;
  pathElSegList[2].y2 = pointArray[5].y;
  pathElSegList[2].x = pointArray[6].x;
  pathElSegList[2].y = pointArray[6].y;
}

//  https://msdn.microsoft.com/en-us/library/ie/hh535760(v=vs.85).aspx
function coordinateTransform(screenPoint) {
  var CTM = svgEl.getScreenCTM();
  return screenPoint.matrixTransform( CTM.inverse() );
}
              
            
!
999px

Console