Interactivity

Scroll Behavior

Utilities for controlling the scroll behavior of an element.

Quick reference

Class
Properties
scroll-autoscroll-behavior: auto;
scroll-smoothscroll-behavior: smooth;

Basic usage

Adding smooth scrolling

Use the scroll-smooth utilities to enable smooth scrolling within an element.

  1. <html class="scroll-smooth">
  2. <!-- ... -->
  3. </html>

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:scroll-auto to only apply the scroll-auto utility on hover.

  1. <html class="scroll-smooth hover:scroll-auto">
  2. <!-- ... -->
  3. </html>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:scroll-auto to apply the scroll-auto utility at only medium screen sizes and above.

  1. <html class="scroll-smooth md:scroll-auto">
  2. <!-- ... -->
  3. </html>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.