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

              
                <div class="message">
  Your Browser does not support Scroll-Driven Animations!
</div>

<header>
  <h1>Scroll-Driven Animations - Timeline</h1>
</header>
<main>
  <article class="timeline">
    <section class="timeline-group">
      <div class="timeline-event">
        <figure role="group">
          <img src="https://images.unsplash.com/photo-1519681393784-d120267933ba?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2070&q=80" alt="mountains">
        </figure>
        <h2>Lorem Ipsum</h2>
        <p></p>
      </div>
      <div class="timeline-point" aria-hidden="true">
        <span>
        </span>
      </div>
      <div class="timeline-date">
        <p><time datetime="2023-07-07">July 7</time></p>
      </div>
    </section>
    <section class="timeline-group">
      <div class="timeline-event">
        <figure role="group">
          <img src="https://images.unsplash.com/photo-1519681393784-d120267933ba?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2070&q=80" alt="mountains">
        </figure>
        <h2>Lorem Ipsum</h2>
        <p></p>
      </div>
      <div class="timeline-point" aria-hidden="true">
        <span>
        </span>
      </div>
      <div class="timeline-date">
        <p><time datetime="2023-07-07">July 7</time></p>
      </div>
    </section>
    <section class="timeline-group">
      <div class="timeline-event">
        <figure role="group">
          <img src="https://images.unsplash.com/photo-1519681393784-d120267933ba?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2070&q=80" alt="mountains">
        </figure>
        <h2>Lorem Ipsum</h2>
        <p></p>
      </div>
      <div class="timeline-point" aria-hidden="true">
        <span>
        </span>
      </div>
      <div class="timeline-date">
        <p><time datetime="2023-07-07">July 7</time></p>
      </div>
    </section>
    <section class="timeline-group">
      <div class="timeline-event">
        <figure role="group">
          <img src="https://images.unsplash.com/photo-1519681393784-d120267933ba?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2070&q=80" alt="mountains">
        </figure>
        <h2>Lorem Ipsum</h2>
        <p></p>
      </div>
      <div class="timeline-point" aria-role="presentation">
        <span>
        </span>
      </div>
      <div class="timeline-date">
        <p><time datetime="2023-07-07">July 7</time></p>
      </div>
    </section>
    <section class="timeline-group">
      <div class="timeline-event">
        <figure role="group">
          <img src="https://images.unsplash.com/photo-1519681393784-d120267933ba?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2070&q=80" alt="mountains">
        </figure>
        <h2>Lorem Ipsum</h2>
        <p></p>
      </div>
      <div class="timeline-point" aria-role="presentation">
        <span>
        </span>
      </div>
      <div class="timeline-date">
        <p><time datetime="2023-07-07">July 7</time></p>
      </div>
    </section>
    <section class="timeline-group">
      <div class="timeline-event">
        <figure role="group">
          <img src="https://images.unsplash.com/photo-1519681393784-d120267933ba?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2070&q=80" alt="mountains">
        </figure>
        <h2>Lorem Ipsum</h2>
        <p></p>
      </div>
      <div class="timeline-point" aria-role="presentation">
        <span>
        </span>
      </div>
      <div class="timeline-date">
        <p><time datetime="2023-07-07">July 7</time></p>
      </div>
    </section>
  </article>
</main>
<footer>
  Thanks!
</footer>
              
            
!

CSS

              
                :root {
  --timeline-line-color: #7f8c8d;
}

body {
  --background: #efefef;
  --body-font-size: clamp(1.13rem, calc(1.08rem + 0.22vw), 1.25rem);

  background: var(--background);
  font-size: var(--body-font-size);
}

header,
footer {
  background: var(--timeline-line-color);
  display: grid;
  height: 50dvh;
  place-content: center;
  text-align: center;
}

.timeline {
  container: timeline-container / inline-size;

  &-group {
    display: grid;
    gap: 1rem;
    grid-template-areas:
      "point date"
      "point event";
    margin-inline: 1rem;

    @container timeline-container (min-width: 80ch) {
      grid-template-areas: "date point event";
      grid-template-columns: 8fr 1fr 8fr;
      place-content: center;

      &:nth-child(even) {
        grid-template-areas: "event point date";

        .timeline-date {
          --translation: -100px;
          justify-content: flex-start;
        }

        .timeline-event {
          --translation: -100px;
          margin-inline-start: auto;
        }
      }
    }
  }

  &-event {
    --border-radius: 0.5rem;
    --box-shadow: 0px 12.5px 10px rgba(0, 0, 0, 0.035),
      0px 100px 80px rgba(0, 0, 0, 0.07);
    --easing: cubic-bezier(0.34, 1.56, 0.64, 1);
    --range-start: contain 30%;
    --range-end: contain 50%;
    --translation: 100px;

    grid-area: event;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);

    > :not(figure) {
      padding-inline: 1rem;
    }

    @container timeline-container (min-width: 80ch) {
      margin-block: 2rem;
      width: min(100% - 1rem, 30cqw);
      position: relative;
    }

    @media (prefers-reduced-motion: no-preference) {
      @supports (animation-timeline: view(block)) {
        opacity: 0;
        animation: slide-in var(--easing) both;
        animation-timeline: view(block);
        animation-range: var(--range-start) var(--range-end);
        transform-origin: center center;
        transform: translateX(var(--translation));
      }
    }

    figure {
      margin: 0;
      width: 100%;
      aspect-ratio: 16/9;
      overflow: hidden;
      border-top-right-radius: var(--border-radius);
      border-top-left-radius: var(--border-radius);
      img {
        display: block;
        height: 100%;
        width: 100%;
        object-fit: cover;
        object-position: center;
      }
    }
  }

  &-point {
    display: grid;
    grid-area: point;
    place-content: center;
    position: relative;
    width: 100%;

    span {
      --point-size: 50px;
      --point-color: #34495e;
      --easing: cubic-bezier(0.34, 1.56, 0.64, 1);
      --range-start: contain 30%;
      --range-end: contain 50%;
      --translation: 100px;

      align-items: center;
      aspect-ratio: 1;
      height: var(--point-size);
      background: var(--point-color);
      border-radius: 100%;
      display: flex;
      flex-direction: column;

      @media (prefers-reduced-motion: no-preference) {
        @supports (animation-timeline: view(block)) {
          animation: scale-up var(--easing) both;
          animation-timeline: view(block);
          animation-range: var(--range-start) var(--range-end);
          transform-origin: center center;
        }
      }
    }

    &::after {
      background: var(--timeline-line-color);
      content: "";
      display: block;
      height: 100%;
      position: absolute;
      left: calc(50% - (10px / 2));
      margin-inline: auto;
      width: 10px;
      top: 0;
      z-index: -1;
    }
  }

  &-date {
    --range-start: contain 30%;
    --range-end: contain 50%;
    --translation: -100px;

    grid-area: date;

    @container timeline-container (min-width: 80ch) {
      --translation: -100px;

      align-items: center;
      display: flex;
      justify-content: flex-end;
    }

    @media (prefers-reduced-motion: no-preference) {
      @supports (animation-timeline: view(block)) {
        animation: fade-in linear both;
        animation-timeline: view(block);
        animation-range: var(--range-start) var(--range-end);
        opacity: 0;
        transform: translateY(var(--translation));
      }
    }
  }
}

@keyframes slide-in {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes scale-up {
  0% {
    scale: 1;
  }
  75% {
    scale: 1.2;
  }
  100% {
    scale: 1;
  }
}

@keyframes fade-in {
  75% {
    opacity: 0;
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.message {
  background: yellow;
  font-size: 1.5rem;
  padding-inline: 2rem;
  padding-block: 3rem;
  > * {
    width: 60ch;
  }
  @supports (animation-timeline: view()) {
    display: none;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console