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

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

              
                <section id="demo">
  <figure id="parent" data-title="#parent">
    <p>This is a demonstration of unitless line-height. Try setting the `line-height` unit of the `figure` element to use `em`s, and adjusting the `font-size` value of the `ul` element. Notice how the computed `line-height` value remains unchanged, inherited from the parent.</p>
    <figure id="child" data-title="#child">
      <p>Now try removing the unit from the `line-height` from the `figure` element, and adjusting the `font-size` value of the `ul` element. Notice how the computed `line-height` is changed in relationship to the `font-size`.</p>
    </figure>
  </figure>
</section>

<section id="config">
<pre><code>#parent {
  <label>line-height: <input id="p_lh_n" type="number" max="3" min="0.5" step="0.5" value="1"/></label><select id="p_lh_u">
      <option value=""></option>
      <option value="em">em</option>
  </select> <span class="comment">// <span id="p_lh">16px</span>;</span>
}

#child {
  <label>font-size:   <input id="c_fs_n" type="number" max="2" min="0.5" step="0.1" value="1"/>em;</label>
  <span class="comment">// line-height: <span id="c_lh">16px</span>;</span>
}</code></pre>
</section>

              
            
!

CSS

              
                #parent {
  line-height: 1;
}
#child {
  font-size: 1em;
}


//////////////////
// Demo Styling

figure {
  position: relative;
  margin: 0 auto;
  padding: 1rem;
  border: 1px solid #ccc;
  max-width: 800px;
  
  p {
    position: relative;
    z-index: 1;
  }

  &::before {
    content: attr(data-title);
    position: absolute;
    top: 0;
    transform: translateY(-50%);
    font-family: monospace;
    background: #fff;
    padding: 0.5em;
    margin: 0 -0.5em;
  }
}

pre {
  display: flex;
  code {
    margin: auto;
  }
}

.comment { color: #ccc; }

input, select { font: inherit; }

#config {
  padding: 0.5rem;
  font-size: 0.8em;
  line-height: 0.8;
  flex: 0 0 auto;
  height: min-content;
}

#demo {
  flex-grow: 1;
}

.changed {
  animation: fade 0.5s linear;
}

@keyframes fade {
  0% { color: red; }
  to { color: inherit; }
}

* { box-sizing: border-box; }

// Center using flexbox
body {
  height: 100vh;
  display: flex;
  flex-flow: column;
}

body > * {
  margin: auto;
  width: 100%;
  overflow-y: scroll;
  padding: 1rem;

  &:not(:first-child) {
    border-top: 1px solid#ccc;
  }
}

:root {
  font: caption;
  font-size: inherit;
}
              
            
!

JS

              
                let $=(s,o=document)=>o.querySelector(s);
parent = $('#parent');
child = $('#child');

function reanimate(e, c){
  e.classList.remove(c);
  // Magic
  void e.offsetWidth;
  e.classList.add(c);
}

function updateComputedLineHeight(){
  var p_lh = window.getComputedStyle(parent).getPropertyValue("line-height"),
      c_lh = window.getComputedStyle(child).getPropertyValue("line-height");
  if ($('#p_lh').textContent != p_lh) {
    $('#p_lh').textContent = p_lh;
    reanimate($('#p_lh'), 'changed');
  }
  if ($('#c_lh').textContent != c_lh) {
    $('#c_lh').textContent = c_lh;
    reanimate($('#c_lh'), 'changed');
  }
}

function setParentLineHeight(){
  parent.style.lineHeight = $('#p_lh_n').value + $('#p_lh_u').value;
  updateComputedLineHeight();
}

$('#p_lh_n').addEventListener('change', setParentLineHeight);
$('#p_lh_u').addEventListener('change', setParentLineHeight);

function setChildFontSize(){
  child.style.fontSize = $('#c_fs_n').value + "em";
  updateComputedLineHeight();
}

$('#c_fs_n').addEventListener('change', setChildFontSize);

              
            
!
999px

Console