×

Hubspot guide to animate on scroll

Hubspot Guide to CSS Animate on Scroll Effects

Modern websites like Hubspot use subtle CSS animate on scroll effects to create engaging, polished pages that feel alive as users move through content. In this guide, you will learn how to recreate scroll-triggered animations similar to those found on the original Hubspot tutorial using clean HTML, CSS, and JavaScript.

Why Use Hubspot-Style Animate on Scroll Effects

Scroll-based animations help draw attention to important sections and improve the user experience when used thoughtfully.

Benefits include:

  • Highlighting key content as a user scrolls
  • Making long pages feel more dynamic and interactive
  • Creating a smoother narrative flow between sections
  • Offering a more modern visual style similar to Hubspot pages

To keep performance high and accessibility intact, these animations should be subtle and triggered only when elements enter the viewport.

Core Concept Behind Hubspot Scroll Animations

At a high level, scroll animation involves three steps:

  1. Mark elements in the HTML that should animate.
  2. Define CSS classes for the initial and animated states.
  3. Use JavaScript to detect when an element enters the viewport and toggle the animation class.

The source example associated with Hubspot uses this simple model to trigger fade-in and slide-in effects as users scroll down the page.

Setting Up HTML for Hubspot-Like Animations

Start by preparing the HTML structure you want to animate. You can apply scroll animations to sections, images, cards, or any content blocks.

Basic HTML Structure Inspired by Hubspot

Wrap each section or block you want to animate in a container with a shared class, and optionally add data attributes to customize behavior:

<section class="feature-section animate-on-scroll" data-animate="fade-up">
  <h2>Feature Title</h2>
  <p>Supporting copy that appears as you scroll.</p>
</section>

<section class="feature-section animate-on-scroll" data-animate="fade-right">
  <h2>Another Section</h2>
  <p>More content with a different animation.</p>
</section>

Key points:

  • animate-on-scroll is the shared class used by JavaScript to find elements.
  • data-animate holds the type of animation to apply.

Creating CSS for Hubspot-Inspired Scroll Effects

The CSS should define both the initial, hidden state and the visible, animated state. This mirrors how Hubspot guides handle transitions.

Initial Hidden State

Use a base class for elements before they appear in the viewport:

.animate-on-scroll {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

This keeps the element slightly shifted and transparent before it is triggered.

Animated States

Next, define variants that respond to the data-animate attribute, similar to the patterns shown in the Hubspot example:

.animate-on-scroll.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.animate-on-scroll.fade-up {
  transform: translateY(20px);
}

.animate-on-scroll.fade-right {
  transform: translateX(-20px);
}

.animate-on-scroll.fade-left {
  transform: translateX(20px);
}

The JavaScript will add both is-visible and the specific animation class (for example, fade-up) when the user scrolls far enough.

Adding JavaScript for Hubspot-Style Scroll Triggering

The original Hubspot tutorial demonstrates a viewport-based trigger. Modern implementations use the Intersection Observer API for better performance, but you can start with a simple scroll listener if needed.

Step-by-Step JavaScript Setup

  1. Select all target elements.
    const animatedElements = document.querySelectorAll('.animate-on-scroll');
  2. Create a helper to check if an element is in the viewport.
    function isInViewport(el) {
      const rect = el.getBoundingClientRect();
      return (
        rect.top <= (window.innerHeight || document.documentElement.clientHeight) * 0.9
      );
    }
  3. Apply animation classes on scroll.
    function handleScrollAnimation() {
      animatedElements.forEach((el) => {
        if (isInViewport(el)) {
          const animationType = el.dataset.animate;
          el.classList.add('is-visible');
          if (animationType) {
            el.classList.add(animationType);
          }
        }
      });
    }
    
    window.addEventListener('scroll', handleScrollAnimation);
    window.addEventListener('load', handleScrollAnimation);

This approach closely follows the behavior you see in the example linked from Hubspot: elements stay hidden until they are nearly visible, then transition smoothly into place.

Using Intersection Observer Like Hubspot-Level Sites

For production-ready performance closer to enterprise setups, you can replace the scroll event listener with Intersection Observer. This method only runs code when elements actually cross a viewport threshold.

Intersection Observer Example

const options = {
  threshold: 0.2
};

const observer = new IntersectionObserver((entries, obs) => {
  entries.forEach(entry => {
    if (entry.isIntersecting) {
      const el = entry.target;
      const animationType = el.dataset.animate;
      el.classList.add('is-visible');
      if (animationType) {
        el.classList.add(animationType);
      }
      obs.unobserve(el);
    }
  });
}, options);

animatedElements.forEach(el => observer.observe(el));

This pattern helps keep animations smooth even on complex pages similar to large Hubspot layouts.

Best Practices for Hubspot-Like Scroll Animations

When implementing these effects, keep the following guidelines in mind:

  • Use animations sparingly. Focus on key sections such as hero areas, feature highlights, and key calls to action.
  • Avoid performance issues. Prefer Intersection Observer over heavy scroll events, especially on Hubspot-scale pages with many elements.
  • Respect accessibility. Ensure important content remains available even if animations fail or JavaScript is disabled.
  • Keep timing consistent. Use similar durations and easing curves across components.

How to Integrate Hubspot-Style Animations Into Your Site

You can gradually roll out these scroll effects without rebuilding your entire design.

Implementation Checklist

  1. Identify key sections that would benefit from a reveal effect.
  2. Add the animate-on-scroll class and optional data-animate attributes.
  3. Include the CSS for initial and animated states.
  4. Wire up JavaScript using either a scroll listener or Intersection Observer.
  5. Test across browsers and devices to match Hubspot-quality behavior.

Further Optimization and Resources

To explore the original patterns and explanations that inspired this walkthrough, review the detailed tutorial on the Hubspot blog about CSS animate on scroll. You can also find professional implementation and optimization help from specialized agencies such as Consultevo, which focus on scalable, SEO-friendly experiences.

By following these steps and keeping performance and accessibility in mind, you can create scroll animations that feel as polished and effective as those seen on established platforms built with the care exemplified by Hubspot.

Need Help With Hubspot?

If you want expert help building, automating, or scaling your Hubspot , work with ConsultEvo, a team who has a decade of Hubspot experience.

Scale Hubspot

“`

Verified by MonsterInsights