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

              
                <div class="wrapper">
  <div class="stage">
    <span id="prop-name"></span>
    <div id="subject">div</div>
  </div>
  <button id="start">Start Animation</button>
  <div id="output"></div>
</div>
              
            
!

CSS

              
                #subject {
  height: 80px; /* start */
}

@keyframes go {
  to {
    height: 160px; /* end */
  }
}

/* you probably don't need to change anything below */

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  display: grid;
  align-items: center;
  justify-items: center;
  margin: 0;
  color: #f8f9fa;
  background-color: #343a40;
  font: 1.25rem/1 'Roboto', sans-serif;
}

.wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr min-content;
  grid-template-areas:
    'stage output'
    'start output';
  gap: 20px;
  width: min(1200px, 100vw);
  height: min(400px, 100vh);
  padding: 20px;
}

.stage {
  grid-area: stage;
  display: grid;
  align-items: center;
  justify-items: center;
  position: relative;
  padding: 10px;
  background-color: #f8f9fa;
  overflow: hidden;
}

#prop-name {
  position: absolute;
  top: 0;
  left: 0;
  padding: 10px;
  background-color: #495057;
}

/* essentially #subject, but with lower specificity */
[id="subject"] {
  display: grid;
  align-items: center;
  justify-items: center;
  width: 80px;
  height: 80px;
  border: 2px solid #ced4da;
  color: #495057;
}

.animate {
  animation: go 1s linear forwards;
}

#start {
  grid-area: start;
  padding: 10px;
  border: 1px solid #f8f9fa;
  color: #fff;
  background-color: #5c940d;
  font: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

#start:disabled {
  cursor: progress;
}

#output {
  grid-area: output;
  padding: 10px;
  color: #fff;
  background-color: #212529;
  font: 1rem/1.5 'Roboto Mono', monospace;
  white-space: pre;
  overflow: auto;
}
              
            
!

JS

              
                /*
To experiment with a different CSS property:
1. Update the lines marked with "start" and "end" in the CSS.
2. Update `animatedPropName` in the JS below.
3. Run the experiment!

Note: the layout CSS of this codepen itself can bork some animations. For example, animating `float` does nothing because the subject div is positioned via `grid`.
*/

const animatedPropName = 'height';

/* you probably don't need to change anything below */

const start = document.getElementById('start');
const subject = document.getElementById('subject');
const output = document.getElementById('output');
const propName = document.getElementById('prop-name');

start.addEventListener('click', startExperiment);
subject.addEventListener('animationstart', startAnimation);
subject.addEventListener('animationend', endAnimation);

propName.innerText = animatedPropName;

let isAnimating = false;
let startTime;

function startExperiment() {
  // change button
  start.disabled = true;
  start.innerText = 'Animating...';
  
  // clear previous experiment
  subject.classList.remove('animate');
  output.innerText = '';
  
  // begin animation
  addSnapshot('start');
  subject.classList.add('animate');
}

function startAnimation() {
  isAnimating = true;
  startTime = Date.now();
  window.requestAnimationFrame(update);
}

function endAnimation() {
  // wrap things up
  isAnimating = false;
  addSnapshot('end');
  
  // change button
  start.disabled = false;
  start.innerText = 'Restart Animation';
}

function update() {
  if (isAnimating) {
    const elapsedTime = Date.now() - startTime;
    addSnapshot(elapsedTime + 'ms');
    window.requestAnimationFrame(update);
  }
}

function addSnapshot(time) {
  const styles = window.getComputedStyle(subject);
  const propValue = styles.getPropertyValue(animatedPropName);
  output.innerText += time.padStart(5) + ': ' + propValue + '\n';
  
  // scroll output to bottom
  output.scrollTop = output.scrollHeight;
}
              
            
!
999px

Console