Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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="header">
  <div class="setting">
    <span class="font-small">A</span> <input type="range" value="18" min="18" max="24" class="range-font"> <span class="font-big">A</span>
  </div>
  <div class="setting">
    <span class="color color-day"></span> <input type="range" value="50" min="0" max="100" class="color range-color"> <span class="color color-night"></span>
  </div>
</div>
<div class="container">

  <h1>Working with variables</h1>

  
		<p>CSS variables are entities defined by CSS authors that contain specific values to be reused throughout a document. They are set using custom property notation  and are accessed using the <code>var()</code> function.</p>

		<p>Complex websites have very large amounts of CSS, often with a lot of repeated values. For example, the same colour might be used in hundreds of different places, requiring global search and replace if that colour needs to change. CSS variables allow
			a value to be stored in one place, then referenced in multiple other places. An additional benefit is semantic identifiers. For example <strong><code>--main-text-color</code></strong> is easier to understand than <code>#00ff00</code>, especially if this same color is also used in another context.</p>

		<p>CSS Variables are subject to the cascade and inherit their value from their parent.
		</p>
</div>
              
            
!

CSS

              
                :root {
  --first: 18px;
  --second: 10%;
  --max-width: 600px;
}

body {
  background-color: #2f3441;
  color: #c8c8c8;
  font-family: "Lato", sans-serif;
}

.setting {
  display: inline-block;
  margin-right: 40px;
}

.color {
  width: 15px;
  height: 15px;
  background-color: #fff;
  display: inline-block;
  border: 1px solid #000;
}

.color-night {
  background-color: #000;
  border: 1px solid #fff;
}

.font-small {
 font-size: 80%;
}

.font-big {
 font-size: 110%;
}

input[type="range"] {
  width: 30px;
}

/* Usage of variables */

.header {
  max-width: var(--max-width);
  margin: 10px auto;
  font-size: 20px;
  color: #fff;
}
.container {
  max-width: var(--max-width);
  margin: 20px auto;
  line-height: 2.5em;
  background-color: hsl(192, 50%, calc(100% - var(--second)));

  padding: calc(10px + var(--first));
  color: hsl(100, 10%, var(--second));
}

h1 {
  color: hsl(250, 90%, var(--second));
}

p {
  font-size: var(--first);
  line-height: 1.5em;
}









              
            
!

JS

              
                const font = document.querySelector('.range-font');
const color = document.querySelector('.range-color');
const root = document.querySelector(':root');

font.addEventListener('input', function() {
  root.style.setProperty('--first', `${this.value}px`);
});

color.addEventListener('input', function() {
  root.style.setProperty('--second', `${this.value}%`);
});

              
            
!
999px

Console