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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div class="contain">
  <div class="range">
    <label for="range">Drag to change parent font-size:</label>
    <input type="range" name="" id="range" min="10" max="40" />
    <span class="current"></span>

<div class="item">
  <p>This hero section items could be resized easily by changing the parent font size</p>
  <div class="hero">
    <h2>This is title for this hero section</h2>
    <p>And this paragraph is a sub title, as you know I'm writing an article about using <code>em</code> unit to build dynamic components

    <a href="#">Read about hero</a>
              $browser-context: 16; // Default
$color-brand: #4a90e2;

body {
	font-family: 'Arial';

.contain {
	max-width: 1000px;
	margin-left: auto;
	margin-right: auto;
	padding-left: 1em;
	padding-right: 1em;

.range {
  padding-top: 2em;
  margin-bottom: 2em;
  label {
    display: block;
    margin-bottom: 10px;

@function em($pixels, $context: $browser-context) {
  @return #{$pixels/$context}em;

/* Sass function credit:
https://css-tricks.com/snippets/sass/px-to-em-functions/ */

/*** Demo Code ***/

.hero {
	background: #ececec;
	padding: 1.5em;
  > * {
    outline: 1px solid grey;
    background: lightgrey;

	p {
		margin: 0;
		padding: 0;

	h2 {
		margin-bottom: 0.25em;
		font-size: 1.75em;

	p {
		margin-bottom: 1em;
		max-width: em(450);
		font-size: 1.25em;

	a {
		display: inline-block;
		background: $color-brand;
		color: #fff;
		padding: 0.7em 1.5em;
		text-decoration: none;
              var slider = document.querySelector('#range');
    item = document.querySelector('.item'),
    current = document.querySelector('.current'),
    style = window.getComputedStyle(item, null).getPropertyValue('font-size'),
    fontSize = parseFloat(style);

current.innerHTML = fontSize + "px";

range.addEventListener('input', function() {
  var newValue = this.value + "px";
  item.style.fontSize = newValue;
  current.innerHTML = newValue;
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.