Pen Settings



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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


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


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.


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.


                <aside class="sliders">
  <input type="range" id="hue" min="0" max="360" value="220" step="1"> 
  <input type="range" id="saturation" min="0" max="100" value="100" step="1"> 
  <input type="range" id="lightness" min="0" max="100" value="50" step="1">
<main class="buttons">  
  <button class="btn">Primary Color</button> 
  <button class="btn btn--secondary">Secondary Color</button> 


                /* The challenge: 
1) Set text to either black or white depending on the element background lightness
2) Set a border as a darker variation of the base color to improve button visibility, ONLY IF background lightness is higher than the border lightness threshold
3) Automatically generate a secondary color

:root {
  /* theme color variables to use in HSL declarations */
  --hue: 220;
  --sat: 100;
  --light: 50;
  /*the threshold at which colors are considered "light". 
Range: integers from 0 to 100,
recommended 50 - 70 */
  --threshold: 65;
  /*the threshold at which a darker border will be applied.
Range: integers from 0 to 100,
recommended 80+ */
  --border-threshold: 80;

.btn {
/*auxiliary variable for hue manipulation*/
  --h: var(--hue);

  /*sets the background for the base class*/
	background: hsl(var(--h), calc(var(--sat) * 1%), calc(var(--light) * 1%));
  /* 1) Any lightness value bellow the threshold will result in white, any above will result in black*/
  --switch: calc((var(--light) - var(--threshold)) * -100%);
  color: hsl(0, 0%, var(--switch));
/* 2) border as 30% darker only if brightness is above the border threshold */
  --border-light: calc(var(--light) * 0.7%);
  --border-alpha:calc((var(--light) - var(--border-threshold)) * 10);
  border:.2em solid hsla(var(--h), calc(var(--sat) * 1%), var(--border-light), var(--border-alpha));

  /* 3) sets the background color as a 60º rotated hue */
  --h: calc(var(--hue) + 60);

/* just aesthetic styles*/

  background: honeydew;
  max-width: 600px;
  margin: auto;

  width: 100%;

.sliders input{


  padding: 1em; margin: 0.5em;
  font-size: 1.5rem; 
  border-radius: 0.2em;
  box-sizing: border-box;

  color: black;
  margin: 10px;

  content: attr(id);
  text-transform: capitalize;

  counter-reset: hue var(--hue);
  content: counter(hue);

  counter-reset: sat var(--sat);
  content: counter(sat);

  counter-reset: light var(--light);
  content: counter(light);


  JS is used only to set the CSS custom properties used in the base color
  Color changes are calculated in CSS 

const root = document.documentElement;
const inputs = []'input'));

inputs.forEach(input => input.addEventListener('change', handleUpdate));
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));

function handleUpdate(e) {
   if ( === 'hue')'--hue', this.value);
   if ( === 'saturation')'--sat', this.value);
  if ( === 'lightness')'--light', this.value);