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

              
                <button class="actual">Not Correct</button>
<button class="expected">Expected</button>
<button class="via-itp">Independent Transforms</button>
<button class="via-variables">CSS Variables</button>
              
            
!

CSS

              
                
.actual, .expected {
  transform: translateY(-150%);
}

/* will (perhaps unintentionally) override the original translate */
.actual:hover {
  transform: scale(.8);
}
/* will (perhaps unintentionally) override the original translate and scale */
.actual:active {
  transform: rotate(-5deg);
}


/* explicitly restates each previous transform function and works as intended */
.expected:hover {
  transform: translateY(-150%) scale(.8);
}
.expected:active {
  transform: translateY(-150%) scale(1) rotate(-5deg);
}
.expected:hover:active {
  transform: translateY(-150%) scale(.8) rotate(-5deg);
}

/* will have similar experience to expected, but organized differently */
.via-variables {
  --y: -150%;
  --scale: 1;
  --rotation: 0deg;
  
  transform: translateY(var(--y)) scale(var(--scale)) rotate(var(--rotation));
}
.via-variables:hover {
  --scale: .8;
}
.via-variables:active {
  --rotation: -5deg;
}

.via-itp {
  
  transition: 
    translate 125ms ease-out,
    scale 125ms ease-out,
    rotate 125ms ease-out;
  translate: 0 -150%;
}
.via-itp:hover {
  scale: .8 .8;
}
.via-itp:active {
  rotate: -5deg;
}




button {
  border: 2px solid hsl(140, 80%, 70%);
  border-radius: 5vmin;
  appearance: none;
  height: 3rem;
  padding: 0 1rem;
  background: hsl(140, 80%, 70%);
  margin: 1rem;
  
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1rem;
  
  transition: transform 125ms ease-out;
}

body {
  height: 100vh;
  background: linear-gradient(to bottom,
    hsl(220, 12%, 12%) calc(50vh - 1px),
    hsl(220, 12%, 32%) calc(50vh - 1px),
    hsl(220, 12%, 32%) calc(50vh + 1px),
    hsl(220, 12%, 12%) calc(50vh + 1px));
  display: flex;
  justify-content: center;
  align-items: center;
}

button:focus {
  outline: 0; /* just for demo clarity for hover v active */
}



/*
.via-variables,
.via-itp {
  background: transparent;
  color: transparent;
}
.active.via-variables,
.active.via-itp {
  background: hsl(140, 80%, 70%);
  color: black;
}
*/
              
            
!

JS

              
                document.querySelector('.via-itp').addEventListener('click', add);
document.querySelector('.via-variables').addEventListener('click', add);

function add(e) {
  e.currentTarget.classList.add('active')
}
              
            
!
999px

Console