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.


                <div id="container">
  <div id="buttons">
    <button onclick="animateLeft()">Left</button>
    <button onclick="animateRight()">Right</button>
  <div id="circle"></div>


                * {
  box-sizing: border-box;

body {
  background: #FAFBFC;

button {
  margin: 2rem 0;

#container {
  margin: 2rem auto;
  padding: 60px;
  padding-top: 0;
  width: 700px;
  background: #FFF;
  border-radius: 1rem;
  box-shadow: 0 3px 10px rgba(0,0,0,0.1);

#buttons {
  text-align: center;

#circle {
  background: #007DF6;
  border-radius: 50%;
  width: 100px;
  height: 100px;


                const element = document.getElementById('circle');

let currentAnimation;

function move(transformEnd) {
  // pause the current animation, if any
  // get the current transform (our starting point)
  let transformStart = getComputedStyle(element).transform;

  let duration = 1000;
  // calculate target duration based on the running animation
  if (currentAnimation) {
    const timing = currentAnimation.effect.getComputedTiming();

    // duration of the running animation
    const activeDuration = timing.activeDuration;

    // progress between 0 and 1 of the running animation
    const activeProgress = timing.progress;

    // calculate duration so that velocity is constant
    duration -= activeDuration - activeProgress * activeDuration;

  // cancel the current animation, if any

  // start the animation from our calculated start point
  currentAnimation = element.animate([
    { transform: transformStart },
    { transform: transformEnd }
  ], {
    duration: duration,
    easing: 'linear',
    fill: 'forwards'

// some extra state management to prevent retriggering the same animation while it's already running
let animatingRight = false;
let animatingLeft = false;

async function animateRight() {
  if (!animatingRight) {
    animatingLeft = false;
    animatingRight = true;
    await currentAnimation.finished;
    animatingRight = false;

async function animateLeft() {
  if (!animatingLeft) {
    animatingRight = false;
    animatingLeft = true;
    await currentAnimation.finished;
    animatingLeft = false;