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

              
                <main>
  <h1>WELCOME TO ANIMATING ELEMENTS</h1>
  <h2>introduction</h2>
  <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Saepe ea tenetur voluptas fugiat quam cumque dicta. Accusantium quod ut fuga natus nobis eos iure sunt, labore eveniet, ad, cupiditate ipsa!
  
  Lorem ipsum, dolor sit amet consectetur adipisicing elit. Alias nihil, facere nisi eligendi ex soluta dicta! A eligendi eveniet accusantium aut voluptatibus voluptates reprehenderit, porro esse ea quis est eius?
  
  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laboriosam quibusdam provident incidunt eveniet voluptatum dignissimos distinctio vero explicabo cupiditate, dolorem ea perspiciatis minus a obcaecati alias itaque nulla maiores saepe.</p>
  
  <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Saepe ea tenetur voluptas fugiat quam cumque dicta. Accusantium quod ut fuga natus nobis eos iure sunt, labore eveniet, ad, cupiditate ipsa!
  
  Lorem ipsum, dolor sit amet consectetur adipisicing elit. Alias nihil, facere nisi eligendi ex soluta dicta! A eligendi eveniet accusantium aut voluptatibus voluptates reprehenderit, porro esse ea quis est eius?
  
  Lorem ipsum dolor sit amet, consectetur adipisicing elit. Laboriosam quibusdam provident incidunt eveniet voluptatum dignissimos distinctio vero explicabo cupiditate, dolorem ea perspiciatis minus a obcaecati alias itaque nulla maiores saepe.</p>
  
  <section>
    <h3>here's the first!</h3>
    <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nulla delectus voluptatem, deleniti iure dignissimos nesciunt similique et rerum assumenda beatae, quod rem pariatur? Porro quo necessitatibus accusamus reiciendis optio deserunt.</p>
    
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. At, corrupti, modi neque nihil placeat hic iusto explicabo odit in voluptate quos, eveniet repudiandae dolorum ipsum? Sapiente quasi ab doloremque voluptate.</p>
    <div class="item first"></div>
  </section>
  
  <section>
    <h3>here's the second!</h3>
    <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nulla delectus voluptatem, deleniti iure dignissimos nesciunt similique et rerum assumenda beatae, quod rem pariatur? Porro quo necessitatibus accusamus reiciendis optio deserunt.</p>
    
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. At, corrupti, modi neque nihil placeat hic iusto explicabo odit in voluptate quos, eveniet repudiandae dolorum ipsum? Sapiente quasi ab doloremque voluptate.</p>
    <div class="item second"></div>
  </section>
  
  <section>
    <h3>here's the third!</h3>
    <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nulla delectus voluptatem, deleniti iure dignissimos nesciunt similique et rerum assumenda beatae, quod rem pariatur? Porro quo necessitatibus accusamus reiciendis optio deserunt.</p>
    
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. At, corrupti, modi neque nihil placeat hic iusto explicabo odit in voluptate quos, eveniet repudiandae dolorum ipsum? Sapiente quasi ab doloremque voluptate.</p>
    <div class="item third"></div>
  </section>
</main>
              
            
!

CSS

              
                body {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Ubuntu", monospace;
  line-height: 1.5;
  color: #333d;
}

main {
  width: 100%;
  max-width: 1024px;
  margin: 2em;
}

h1,
h2,
h3 {
  margin-top: 2em;
  color: blue;
}

h1 {
  margin-top: 0;
  font-size: 4rem;
  text-align: center;
}

.item {
  height: 20em;
  width: 20em;
  margin: 3em auto;
  background-color: navy;
  border-radius: 10px;
  opacity: 0;
}

.animated {
  animation: animate 1s ease-in 1 forwards;
}

@keyframes animate {
  from {
    opacity: 0;
  }
  
  to {
    opacity: 1;
  }
}
              
            
!

JS

              
                const animatingElements = Array.from(document.getElementsByClassName("item"));

document.addEventListener("scroll", (e) => {
  animatingElements.forEach((el) => {
    if(el.getBoundingClientRect().top + 50 < document.documentElement.clientHeight) {
      el.classList.add("animated");
      
    } else {
      return;
    }
  });
});


              
            
!
999px

Console