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

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

              
                <div class="tools">
  <label for="font-picker-size">Font size</label>
  <input type="range" id="font-picker-size" value="125" min="80" max="300">
  <label for="color-picker-primary">Primary colour</label>
  <input type="color" id="color-picker-primary" value="#b30027">
  <label for="color-picker-contrast">Contrast colour</label>
  <input type="color" id="color-picker-contrast" value="#ffffff">
</div>


<div class="template">
  <div class="primary--fill masthead">
    <h1 class="contrast--text">Using CSS Custom Properties and the CSSOM to create real&#8209time theme previews</h1>
  </div>

  <div class="body">
    <h2 class="primary--text">My themed page title</h2>
    <p>Bacon ipsum dolor amet swine t-bone leberkas, pork belly strip steak tongue shankle bresaola ball tip ribeye ham pork loin ham hock. Pork belly capicola ground round t-bone chicken doner beef ribs tail pork chop tenderloin swine flank ham. Jerky sirloin tongue <a class="primary--text" href="#">spare ribs t-bone</a> shoulder short ribs chuck frankfurter. Shoulder pig capicola landjaeger beef ribs, pork loin short ribs jerky salami cupim. Beef ribs bacon tongue, ribeye short loin turducken swine sirloin porchetta capicola picanha ball tip cupim shank frankfurter. Shank bacon biltong, flank beef turkey porchetta sausage meatloaf pastrami shankle tenderloin spare ribs short ribs pork belly.</p>

    <a class="button primary--fill contrast--text" href="#">Button</a>

    <p>Bresaola bacon shank salami pancetta drumstick andouille shoulder capicola hamburger corned beef prosciutto t-bone chuck. <a class="primary--text" href="#">Biltong sausage boudin, brisket turducken</a> doner venison landjaeger salami picanha tri-tip pork belly spare ribs short ribs. Turkey pork belly shoulder boudin tail, beef pork loin ground round spare ribs ribeye tri-tip landjaeger bresaola. Cow shankle rump tail. Ground round ham hock capicola landjaeger sausage. Ribeye pig meatball, spare ribs pancetta capicola doner salami.</p>

  </div>
</div>

              
            
!

CSS

              
                /* themed properties
---------------------------------------------------- */

:root {
  --theme-contrast: #ffffff;
  --theme-primary: #b30027;
  --theme-font-size: 125%;
  --unsupported-message-display: none;
}


/* themed elements
---------------------------------------------------- */

.template {
  font-size: var(--theme-font-size);
}


.primary--text {
  color: var(--theme-primary);
}
.primary--fill {
  background-color: var(--theme-primary);
}


.contrast--text {
  color: var(--theme-contrast);
}
.contrast--fill {
  background-color: var(--theme-contrast);
}


/* demo styles 
---------------------------------------------------- */

body {
  font: 100% / 1.5 Arial;
  margin: 0;
  padding: 0;
}

p {
  margin: 3em 0;
}

.masthead {
  padding: 12% 2em;
  text-align: center;
  background-image: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,0.3))
}

.body {
  margin: auto;
  max-width: 760px;
  padding: 2em;
}

/* Button styles
---------------------------------------------------- */
.button {
  margin: 0;
  padding: .5em 2em;
  border-radius: .25em;
  text-decoration: none;
  box-shadow: 0 .1em .2em 0em rgba(0,0,0,0.5);
  border-bottom: .15em solid rgba(0,0,0,0.25);
}

.button:hover {
  background-image: linear-gradient(
    rgba(255,255,255,0.3),
    rgba(255,255,255,0.3)
  );
}


/* Toolbox styles
---------------------------------------------------- */
.tools {
  position: fixed;
  background: rgba(225,225,225,.75);
  padding: 1em;
  margin: .5em;
  border-radius: .25em;
  max-width: 20em;
}

.tools > * {
  display: inline-block;
}

.tools label {
  min-width: 9em;
  max-width: 11em;
}


/* Show a message in unsupported browsers
---------------------------------------------------- */
:root::before {
  font: 100%/1.5 Menlo, monospace;
  content: 'NOTE: This browser doesn\'t support CSS Custom Properties';
  text-align: center;
  background: #fc0;
  padding: 1em;
  border-radius: 1em;
  position: fixed;
  left: 50%;
  bottom: 0.5em;
  transform: translate(-50%,-50%);
}

@supports (font-size: var(--theme-font-size)) {
  :root::before {
    display: none;
  }
}


              
            
!

JS

              
                var primaryColorPicker = document.getElementById('color-picker-primary');
var contrastColorPicker = document.getElementById('color-picker-contrast');
var fontSizePicker = document.getElementById('font-picker-size');

function setThemeVar(name, value, unit) {
  var rootStyles = document.styleSheets[0].cssRules[0].style;
  rootStyles.setProperty('--theme-' + name, value + (unit || ''));
}

primaryColorPicker.addEventListener('input', function (e) {
  setThemeVar('primary', e.target.value);
});

contrastColorPicker.addEventListener('input', function (e) {
  setThemeVar('contrast', e.target.value);
});

fontSizePicker.addEventListener('input', function (e) {
  setThemeVar('font-size', e.target.value, '%');
});

setThemeVar('primary', primaryColorPicker.value);
setThemeVar('contrast', contrastColorPicker.value);
setThemeVar('font-size', fontSizePicker.value, '%');


              
            
!
999px

Console