
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a smooth scrolling effect with CSS?
To create a smooth scrolling effect with CSS, the code is as follows −
Example
<!DOCTYPE html> <html> <head> <style> html { scroll-behavior: smooth; } * { box-sizing: border-box; } body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; margin: 0px; padding: 0px; } #firstSection { height: 100vh; background-color: rgb(119, 77, 219); color: white; padding: 20px; } #secondSection { height: 100vh; color: white; background-color: rgb(42, 128, 168); padding: 20px; } a { text-decoration: none; font-size: 20px; font-weight: bold; color: yellow; } </style> </head> <body> <h1>Smooth Scroll Example</h1> <div id="firstSection"> <h2>Section 1</h2> <p>Click on the link to see the "smooth" scrolling effect.</p> <a href="#secondSection">Click Here to Smooth Scroll to Section 2 Below</a> </div> <div id="secondSection"> <h2>Section 2</h2> <a href="#firstSection">Click Me to Smooth Scroll to Section 1 Above</a> </div> </body> </html>
Output
The above code will produce the following output −
On clicking the smooth scroll text we will scroll to section 2 smoothly −
- Related Questions & Answers
- Smooth Scrolling with Pure CSS
- How to create a "parallax" scrolling effect with CSS?
- How to Create a Parallax Scrolling Effect in CSS
- How to create a transition effect with CSS?
- How to create fading effect with CSS
- How to create an overlay effect with CSS?
- How to create image overlay hover effect with CSS?
- Create a transition effect on hover pagination with CSS
- How to create image overlay icon effect on hover with CSS?
- How to create a typing effect with JavaScript?
- Create a small-caps effect for CSS
- How to create an image overlay zoom effect on hover with CSS?
- Flip Effect with CSS
- Wave effect with CSS?
- How to Create a Parallax Effect using HTML, CSS, and JavaScript?
Advertisements