cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

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

            
          
!
            
              /* 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;
  }
}


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

Console