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

              
                <aside>Fixed child of <code>body</code></aside>

<main>
<h1>Testing a Root Container</h1>
<div class="controls">
  <fieldset>
    <legend>HTML element (root)</legend>
    <div>    
      <label for="root-container">
        container-type
      </label>
      <select name="root-container" id="root-container">
        <option value="revert" selected>normal</option>
        <option value="inline-size">inline-size</option>
        <option value="size">size</option>
      </select>
    </div>
    <div>    
      <label for="root-overflow">
        overflow
      </label>
      <select name="root-overflow" id="root-overflow">
        <option value="revert" selected>normal</option>
        <option value="auto">auto</option>
      </select>
    </div>
    <div>    
      <label for="root-height">
        height
      </label>
      <select name="root-height" id="root-height">
        <option value="revert" selected>normal</option>
        <option value="100">100%</option>
      </select>
    </div>
  </fieldset>
  <fieldset>
    <legend>BODY element</legend>
    <div>    
      <label for="body-overflow">
        overflow
      </label>
      <select name="body-overflow" id="body-overflow">
        <option value="revert" selected>normal</option>
        <option value="auto">auto</option>
      </select>
    </div>
    <div>    
      <label for="body-height">
        height
      </label>
      <select name="body-height" id="body-height">
        <option value="revert" selected>normal</option>
        <option value="100">100%</option>
      </select>
    </div>
  </fieldset>
</div>

<p>
  It doesn't matter 
  how we select the element in CSS --
  using <code>:root</code>
  or <code>html</code> --
  in either case we are selecting 
  the same element.
  On first glance,
  it seems like a perfect
  'container':
</p>

<ul>
  <li>
    We want it sized
    to the viewport,
    not the contents.
    The extrinsic size
    and expected overflow
    makes it a good candidate for
    two-axis
    <code>size</code> containment.
  </li>
  <li>
    Since it is a direct wrapper
    of a single <code>body</code> element,
    we would get both an outer container
    and an outer element responding to
    container queries --
    without any additional markup.
  </li>
</ul>

<p>
  However,
  this doesn't work as expected,
  and results in two common issues:
</p>
  
<ul>
  <li>
    Positioning of fixed elements
    relative to <code>html</code>
    rather than the viewport
  </li>
  <li>
    Scrollbars failing to propagate 
    to the viewport
  </li>
</ul>
  
<p>
  Play around with the toggles above
  to see how different types of containment,
  and different overflow/height settings
  on <code>html</code> and <code>body</code>
  interact.
</p>

<h2>Spacer Content</h2>

<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>

<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>

<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>
<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>

<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>

<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>

<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>

<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>

<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>

<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>

<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>

<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>

<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>

<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>

<p>
  Just an easy way to trigger overflow.
  Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quibusdam velit, eligendi repudiandae sapiente sequi nobis, ratione tempore necessitatibus, est culpa maiores aliquid veritatis quos aperiam tempora asperiores hic! Id, debitis.
</p>
</main>
              
            
!

CSS

              
                [data-container='size'] {
  container-type: size;
  --color: red;
}

[data-container='inline-size'] {
  container-type: inline-size;
  --stripe: orange;
}

[data-overflow='auto'] {
  overflow: auto;
}

[data-height='100'] {
  height: 100%;
}

aside {
  position: fixed;
  inset-block-start: 0.5em;
  inset-inline-end: 0.5em;
}

@layer defaults {
  * { box-sizing: border-box; }
  
  html {
    font-size: x-large;
    border: 0;
    background: repeating-linear-gradient(
        to bottom right,
        var(--color, var(--stripe, lightcyan)) 0% 1%,
        var(--color, lightcyan) 1% 2%
      ) repeat scroll;
  }
  
  body {
    margin: 0;
  }
  
  main {
    margin: 1em auto;
    background: white; 
    max-width: 60ch;
    padding: 1em;
  }
  
  h1 {
    margin-block-start: 0;
  }
  
  aside {
    padding: 1em;
    background: pink;
    border: medium double;
  }

  .controls {
    border-block: thin dotted;
    padding: 1em;
  }

  .help {
    font-size: smaller;
    margin: 0.5em 0 0;

    &::before {
      content: '(';
    }
    &::after {
      content: ')';
    }
  }
  
}
              
            
!

JS

              
                const targets = {
  root: document.querySelector('html'),
  body: document.querySelector('body')
};

document.querySelectorAll('select').forEach((input) => {
  const inFor = input.id.split('-');
  const target = targets[inFor[0]];
  const attr = inFor[1];
  
  input.addEventListener('input', (e) => {
    target.setAttribute(`data-${attr}`, input.value);
  });
})

              
            
!
999px

Console