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.


                <div id="container">
  <div id="text">Lorem ipsum <b>dolor</b> sit amet, <small>consectetuer adipiscing elit</small>.</div>
  <div id="shadings"></div>


body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  background-color: #cae9ff;

body {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  font-size: 3.5vw;

#shadings {
  height: 1.5em;
  padding-bottom: 0.25em;

#text {
  whitespace: pre;
  display: inline;
  width: fit-content;

small {
  font-size: 0.6em;

#shadings {
  position: relative;
  mix-blend-mode: multiply;
  transition: 0.5s ease-in-out transform;

#shadings div {
  position: absolute;
  height: 1em;
  background-color: #00fff5;
  left: 0;

#shadings div:nth-child(2n) {
  background-color: #3cdbd3;

#shadings div:last-child {
  position: relative;
  opacity: 0;

#container:hover #shadings {
  transform: translateY(-1em);



 * A generator that recursively find all text nodes in a subtree rooted at el.
function* recursivelyFindTextNode(el: Node): Generator<Node> {
  if (el.nodeType === Node.TEXT_NODE) {
    yield el;
  } else if (el.nodeType === Node.ELEMENT_NODE) {
    for (let i = 0; i < el.childNodes.length; i++) {
      yield* recursivelyFindTextNode(el.childNodes[i]);

function measure(el: Node): number[] {
  const result: number[] = [];
  const range = document.createRange();

  // expand all text nodes found.
  const nodes = [...recursivelyFindTextNode(el)];

  for (const textNode of nodes) {
    const textLength = [...textNode.textContent].length;
    for (let i = 0; i < textLength; i++) {
      range.setEnd(textNode, i);
      const rect = range.getBoundingClientRect();
      if (rect.width !== 0) result.push(rect.width);

  // Get the total length of the text
  range.setEndAfter(nodes.length > 0 ? nodes[nodes.length - 1] : el);
  const rect = range.getBoundingClientRect();

  return result;

const el = document.getElementById("text");
const cont = document.getElementById("shadings");
const lengths = measure(el);

for (const l of lengths) {
  const d = document.createElement("div"); = `${l}px`;

// text width placeholder
const d = document.createElement("div"); = `${lengths[lengths.length - 1]}px`;