Scroll · 01 of 34

Fade In

The simplest scroll reveal: content starts transparent and fades in when it enters the viewport. Uses IntersectionObserver to add a class, and CSS handles the transition.

HTML · CSS · JavaScript · No dependencies · MIT

HTML

<!-- Place inside a scrollable page so the section starts off-screen -->
<section class="fade-section">
  <h2>Fade In</h2>
</section>

CSS

.fade-section {
  min-height: 35vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fade-section h2 {
  font-size: 2.5rem;
  color: #f0f0f5;
  opacity: 0;
  transition: opacity 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

.fade-section.in-view h2 {
  opacity: 1;
}

JavaScript

var section = document.querySelector('.fade-section');

new IntersectionObserver(function (entries) {
  entries.forEach(function (entry) {
    // toggle so the animation replays every time it scrolls into view
    entry.target.classList.toggle('in-view', entry.isIntersecting);
  });
}, { threshold: 0.25 }).observe(section);