Back to Snippets
CSS / TailwindCSS

CSS Smooth Scroll

Enable smooth scrolling behavior with CSS and scroll-snap for sections.

cssscrollsmoothbehavior
text-emerald-400">"text-gray">/* Global smooth scrolling */
html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px; text-emerald-400">"text-gray">/* Account for fixed navbar */
}

text-emerald-400">"text-gray">/* Scroll snap for full-page sections */
.snap-container {
  height: 100vh;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
}

.snap-section {
  height: 100vh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

text-emerald-400">"text-gray">/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  .snap-container {
    scroll-snap-type: none;
  }
}

How to Use

Add scroll-behavior: smooth to html for smooth anchor link navigation. Use scroll-padding-top to offset for fixed headers. The scroll-snap classes create a full-page section-snapping experience.

Related Technology

Tailwind CSS

Have a Project in Mind?

Let's discuss how we can bring your idea to life. From initial concept to production-ready product — we've got you covered.

or book a free call