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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

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


                <svg xmlns="" id="mysvg" viewBox="0 0 1000 1000" preserveAspectRatio="xMidYMid meet">

  <g id="transform1" transform="scale(4)">
    <rect x="50" y="50" width="100" height="100" rx="10" />
    <text x="100" y="100" text-anchor="middle" dominant-baseline="middle">scale(4)</text>
  <g id="transform2" transform="scale(2) rotate(10 350 350) skewY(5)">
    <rect x="300" y="300" width="100" height="100" rx="10" />
    <text x="350" y="350" text-anchor="middle" dominant-baseline="middle">scale(2)</text>


<div id="output">
  <h1>DOM to SVG Co-ordinates</h1>
  <strong>DOM client X,Y:</strong> <span id="clientX"></span> <span id="clientY"></span>
  <strong>SVG X,Y:</strong> <span id="svgX"></span> <span id="svgY"></span>
  <strong>target X,Y:</strong> <span id="targetX"></span> <span id="targetY"></span>
  <strong>add target:</strong> <span id="targetID"></span>
  <strong>add X,Y:</strong> <span id="addX"></span> <span id="addY"></span>


                *, *:before, *:after {
  box-sizing: border-box;
  padding: 0;
  margin: 0;

html {
  height: 100%;

body {
  height: 100%;
  font-family: Lato, helvetica, sans-serif;
  font-size: 100%;
  padding: 0;
  margin: 0;
  color: #333;
  background-color: #fff;
  overflow: hidden;

#mysvg {
  display: block;
  width: auto;
  height: 100%;
  margin: 0;
  background: radial-gradient(ellipse at center, #fefefe 0%, #cbeeff 100%);
  border: 5px solid #333;
  touch-action: none;

@media (max-aspect-ratio: 1/1) {

  #mysvg {
    width: 100%;
    height: auto;


#mysvg rect {
  fill: #069;

#mysvg circle {
  stroke-width: 3;
  stroke: #f00;
  fill: #ff0;

#mysvg text {
  fill: #fff;

#output {
  position: fixed;
  display: grid;
  grid-template-columns: auto 3em 3em;
  gap: 0.2em;
  bottom: 10px;
  right: 10px;
  padding: 0.2em;
  background-color: rgba(255,255,255,0.9);
  border-radius: 5px;
  pointer-events: none;

#output strong, #output span {
  text-align: right;
  font-variant-numeric: tabular-nums;

h1 {
  font-size: 1.1em;
  grid-column-start: span 3;

#targetID {
  grid-column-start: span 2;


                // initialize
  svg = document.getElementById('mysvg'),
  NS = svg.getAttribute('xmlns'),
  out = {};

'clientX,clientY,svgX,svgY,targetX,targetY,targetID,addX,addY'.split(',').map(s => {
  out[s] = { node: document.getElementById(s), value: '-' }

// events
svg.addEventListener('pointermove', getCoordinates);
svg.addEventListener('pointerdown', getCoordinates);
svg.addEventListener('pointerdown', createCircle);

// update co-ordinates
function getCoordinates(event) {

  // DOM co-ordinate
  out.clientX.value = event.clientX;
  out.clientY.value = event.clientY;

  // SVG co-ordinate
  const svgP = svgPoint(svg, out.clientX.value, out.clientY.value);
  out.svgX.value = svgP.x;
  out.svgY.value = svgP.y;

  // target co-ordinate
  const svgT = svgPoint(, out.clientX.value, out.clientY.value);
  out.targetX.value = svgT.x;
  out.targetY.value = svgT.y;



// add a circle to the target
function createCircle(event) {

  // circle clicked?
  if ( === 'circle') return;

  // add circle to containing element
    target ='g') || ||,
    svgP = svgPoint(target, event.clientX, event.clientY),
    cX = Math.round(svgP.x),
    cY = Math.round(svgP.y),
    circle = document.createElementNS(NS, 'circle');

  circle.setAttribute('cx', cX);
  circle.setAttribute('cy', cY);
  circle.setAttribute('r', 30);


  // output information
  out.targetID.value = || target.nodeName;
  out.addX.value = cX;
  out.addY.value = cY;


// translate page to SVG co-ordinate
function svgPoint(element, x, y) {

  var pt = svg.createSVGPoint();
  pt.x = x;
  pt.y = y;
  return pt.matrixTransform(element.getScreenCTM().inverse());


// output values
function updateInfo() {

  for (p in out) {
    out[p].node.textContent = isNaN(out[p].value) ? out[p].value : Math.round(out[p].value);