Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg" width="400" class="original">
  <path d="M47,-60.7C54.8,-49.6,50.7,-28.9,54.8,-9.2C58.8,10.6,71.1,29.3,68.3,44.2C65.4,59.1,47.5,70.2,29.8,72.6C12.1,75,-5.3,68.7,-17.3,59.3C-29.3,49.9,-35.9,37.2,-45.9,24.4C-55.9,11.5,-69.2,-1.5,-70.9,-16.1C-72.7,-30.7,-62.8,-46.9,-49.1,-57C-35.3,-67.2,-17.7,-71.2,1,-72.4C19.6,-73.6,39.3,-71.9,47,-60.7Z" transform="translate(100 100)" />
</svg>

<div class="prose">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed et orci id risus lobortis tincidunt. In quis erat sed nunc euismod facilisis in vitae turpis. Nullam et quam a justo vestibulum commodo. Suspendisse cursus felis quis lectus blandit consequat. Sed ut congue ipsum. Phasellus nec condimentum arcu. Maecenas vitae nisi leo. Pellentesque porta, libero vel placerat scelerisque, elit turpis vulputate purus, rutrum commodo mi erat et diam. Etiam feugiat pulvinar mauris, at maximus tellus porttitor at. Maecenas eu urna pulvinar, dapibus tortor ut, interdum turpis. In pretium ac quam eget euismod. Fusce vel urna a leo aliquam tristique vitae laoreet urna. Ut pharetra aliquet ante non cursus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed et orci id risus lobortis tincidunt. In quis erat sed nunc euismod facilisis in vitae turpis. Nullam et quam a justo vestibulum commodo. Suspendisse cursus felis quis lectus blandit consequat. Sed ut congue ipsum. Phasellus nec condimentum arcu. Maecenas vitae nisi leo. Pellentesque porta, libero vel placerat scelerisque, elit turpis vulputate purus, rutrum commodo mi erat et diam. Etiam feugiat pulvinar mauris, at maximus tellus porttitor at. Maecenas eu urna pulvinar, dapibus tortor ut, interdum turpis. In pretium ac quam eget euismod. Fusce vel urna a leo aliquam tristique vitae laoreet urna. Ut pharetra aliquet ante non cursus. Maecenas eu urna pulvinar, dapibus tortor ut, interdum turpis. In pretium ac quam eget euismod. Fusce vel urna a leo aliquam tristique vitae laoreet urna. Ut pharetra aliquet ante non cursus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed et orci id risus lobortis tincidunt. In quis erat sed nunc euismod facilisis in vitae turpis. Nullam et quam a justo vestibulum commodo. Suspendisse cursus felis quis lectus blandit consequat. Sed ut congue ipsum. Phasellus nec condimentum arcu. Maecenas vitae nisi leo. Pellentesque porta, libero vel placerat scelerisque, elit turpis vulputate purus, rutrum commodo mi erat et diam. Etiam feugiat pulvinar mauris, at maximus tellus porttitor at. Maecenas eu urna pulvinar, dapibus tortor ut, interdum turpis. In pretium ac quam eget euismod. Fusce vel urna a leo aliquam tristique vitae laoreet urna. Ut pharetra aliquet ante non cursus.
</p>
</div>
              
            
!

CSS

              
                svg {
  height: auto;
}

.prose {
  max-width: 800px;
  max-height: 800px;
  overflow: hidden;
}
              
            
!

JS

              
                // Takes an SVG element and returns the inverse, split into two halves
function intoSplit(elem) {
  const viewBox = elem.getAttribute('viewBox');
  const [viewX, viewY, viewWidth, viewHeight] = viewBox.split(' ');
  
  const left = createMaskedClone(elem);
  left.setAttribute('viewBox', [viewX, viewY, viewWidth / 2, viewHeight].join(' '));
  
  const right = createMaskedClone(elem);
  right.setAttribute('viewBox', [viewX, viewY, viewWidth / 2, viewHeight].join(' '));
  const rightGroup = right.querySelector('.inner-children');
  rightGroup.setAttribute('transform', `translate(${-viewWidth / 2} 0)`);
  
  return [left, right];
}

// Clones an SVG element and inverts it
function createMaskedClone(elem) {
  const maskedClone = elem.cloneNode(true);
    
  const viewBox = maskedClone.getAttribute('viewBox');
  const [viewX, viewY, viewWidth, viewHeight] = viewBox.split(' ');
  
  const maskRect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
  maskRect.setAttribute("fill", "white");
  maskRect.setAttribute("width", viewWidth);
  maskRect.setAttribute("height", viewHeight);
  
  const group = document.createElementNS("http://www.w3.org/2000/svg", "g");
  group.setAttribute("class", "inner-children");
        
  const maskId = `mask-${Math.random()}`;
  const mask = document.createElementNS("http://www.w3.org/2000/svg", "mask");
  mask.setAttribute("id", maskId);
  mask.appendChild(maskRect);
  
  // actually moves the childen into the mask
  group.appendChild(...maskedClone.children);
  mask.appendChild(group);
  
  const mainRect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
  mainRect.setAttribute("mask", `url(#${maskId})`);
  mainRect.setAttribute("width", viewWidth);
  mainRect.setAttribute("height", viewHeight);
  
  maskedClone.appendChild(mask);
  maskedClone.appendChild(mainRect);
  
  return maskedClone;
}

// URL-encode an SVG
function getAsMask(svgElem) {
  const markup = svgElem.outerHTML;
  return `url("data:image/svg+xml,${encodeURIComponent(markup)}")`;
}

// The original SVG we're trying to convert
const original = document.querySelector('.original');

const [left, right] = intoSplit(original);
left.setAttribute('style', `float: left; shape-outside: ${getAsMask(left)}`);
right.setAttribute('style', `float: right; shape-outside: ${getAsMask(right)}`);

const prose = document.querySelector('.prose');
prose.firstElementChild.before(left, right);
              
            
!
999px

Console