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

              
                <header class="header">
  <div class="header__title">
    <h1>
      <code>brightness()</code>
    </h1>
  </div>
  <div class="header__reference">
    <ul class="reference-list">
      <li><a class="reference-list__link" href="https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/brightness">MDN reference</a></li>
      <li><a class="reference-list__link" href="https://caniuse.com/#feat=css-filters">caniuse Support</a></li>
    </ul>
  </div>
</header>

<main>
  <div class="example">
    <p>
      In this example, brightness is set to <code>50%</code> using a CSS Custom Property. By moving the range slider to either the left or right, you can increase or decrease the brightness effect applied to the photo.
    </p>
    
    <div class="controls">
      <label class="controls__label" for="brightness">Brightness:</label>
      <input class="controls__input" type="range" id="brightness" min="0" max="100" value="50">
    </div>

    <div class="example__demo example__brightness">
      <img class="drink" alt="A Manhattan cocktail placed on a wooden table in a low-lit room." src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/11907/jakub-dziubak-gj7BLlSzIFs-unsplash.jpg"/>
    </div>
  </div>
  
  <aside>
    <p>
      <small>Photo by <a href="https://unsplash.com/photos/gj7BLlSzIFs">Jakub Dziubak</a> on <a href="https://unsplash.com/">Unsplash</a>.</small>
    </p>
  </aside>
</main>
              
            
!

CSS

              
                // Demo
:root {
  --brightness: 50%;
}

.drink {
  filter: brightness(var(--brightness));
}


// Pen Setup
.example__brightness {
  background-color: var(--color-cinder);
  padding: 2rem 2rem 1.75rem 2rem;
  
  img {
    height: auto;
    width: 100%;
  }
}

.controls {
  display: flex;
  flex-direction: column;
  margin-top: var(--size-epsilon);
}

.controls__label {
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.controls__input {
  margin-top: 0.5rem;
}

              
            
!

JS

              
                // Credit: 
// Update CSS Variables with JS
// Wes Bos
// https://codepen.io/wesbos/pen/adQjoY

const rangeSlider = [].slice.call(document.querySelectorAll('#brightness'));

// Listen for changes
rangeSlider.forEach(input => input.addEventListener('change', handleUpdate));
rangeSlider.forEach(input => input.addEventListener('mousemove', handleUpdate));

function handleUpdate(e) {
  // Append '%' to the end of the `blur` custom property
  const suffix = (this.id === 'base' ? '' : '%');
  document.documentElement.style.setProperty(`--${this.id}`, this.value + suffix);
}

              
            
!
999px

Console