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

              
                <div class="container container--spaced">
  <label>Using relative Pixel values</label>
  <div class="test">
    <div class="imagebox">image</div>
    <h1>Lorem ipsum dolor sit amet, consectetur adipisici elit.</h1>

    <p>Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna
      aliqua. Nec dubitamus multa iter quae et nos invenerat. Idque Caesaris facere voluntate liceret: sese habere.
      Inmensae subtilitatis, obscuris et malesuada fames. Morbi odio eros, volutpat ut pharetra vitae, lobortis sed
      nibh.</p>
  </div>
</div>

<div class="container container--centered">
  <span class="help">Change your browser's default font size in the settings to see a difference here.</span>
</div>
<hr>

<div class="container container--spaced">
  <label>Using absolute Pixel values</label>
  <div class="test use-px">
    <div class="imagebox">image</div>
    <h1>Lorem ipsum dolor sit amet, consectetur adipisici elit.</h1>

    <p>Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna
      aliqua. Nec dubitamus multa iter quae et nos invenerat. Idque Caesaris facere voluntate liceret: sese habere.
      Inmensae subtilitatis, obscuris et malesuada fames. Morbi odio eros, volutpat ut pharetra vitae, lobortis sed
      nibh.</p>
  </div>
</div>


              
            
!

CSS

              
                // PX to REM conversion function
@function rem($pixels) {
  // Divide the pixel value by 16 (default font size)
  // Mulitplication by 1rem is needed to set the correct unit for the resulting value
  @return ($pixels / 16) * 1rem;
}

// HTML and Body styling
html {
  // Set 16 px as the base font size, currently the default in all browsers
  // 100% = 1em = 1rem = 16px = 12pt
  font-size: 100%;
  font-family: sans-serif;
}

body {
  // Set the base font size of the body to 16px = 1rem
  font-size: 1rem;
}

// Typo styles
p {
  font-size: rem(18);

  .use-px & {
    // Use a fixed value of 18px for the element
    font-size: 18px;
  }
}

h1 {
  font-size: rem(35);
  margin: rem(10) 0 0;

  .use-px & {
    font-size: 35px;
    margin: 10px 0 0;
  }
}

// Dimension and spacing styles
.test {
  padding: rem(15);

  .use-px & {
    padding: 15px;
  }
}

.imagebox {
  width: rem(150);
  height: rem(150);
  margin-left: rem(50);
  margin-bottom: rem(20);

  .use-px & {
    width: 150px;
    height: 150px;
    margin-left: 50px;
    margin-bottom: 20px;
  }
}


//===========================================================================
// Styles without function for the font sizing, just to make things look nice
.container {
  position: relative;
  margin: 0 auto;
  padding: 0 rem(10);
  max-width: rem(1000);

  &--spaced {
    margin-top: rem(50);
    margin-bottom: rem(50);
  }

  &--centered {
    text-align: center;
  }
}

label {
  font-size: rem(9);
  text-transform: uppercase;
  font-weight: bold;
  color: #0078ff;
}

.test {
  background: #f5f5f5;

  &:after {
    content: "";
    clear: both;
    display: table;
  }
}

.imagebox {
  display: flex;
  justify-content: center;
  align-items: center;
  float: right;
  background: #ddd;
  color: #888;
}

hr {
  width: 100%;
  margin: 0;
  background: none;
  border: 0;
  border-bottom: 2px dashed #eee;
}

.help {
  display: block;
  transform: translateY(calc(100% - #{rem(3)}));
  font-size: rem(9);
  font-weight: bold;
  color: #999;
  line-height: 1;
}

              
            
!

JS

              
                
              
            
!
999px

Console