HTML
CSS
JavaScript
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Scroll Behavior Example</title> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>Smooth Scroll Behavior Example</h1> <nav> <ul> <li><a href="#section1">Go to Section 1</a></li> <li><a href="#section2">Go to Section 2</a></li> <li><a href="#section3">Go to Section 3</a></li> </ul> </nav> <div class="content"> <div id="section1" class="section">Section 1</div> <div id="section2" class="section">Section 2</div> <div id="section3" class="section">Section 3</div> </div> </body> </html>
html { scroll-behavior: smooth; } nav { position: fixed; top: 0; background: white; padding: 10px; width: 100%; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); } .content { margin-top: 60px; } .section { height: 100vh; display: flex; align-items: center; justify-content: center; font-size: 2em; background-color: lightcoral; border: 1px solid #ccc; }
// No JavaScript required for this demo
Scroll Behavior Example
Smooth Scroll Behavior Example
Go to Section 1
Go to Section 2
Go to Section 3
Section 1
Section 2
Section 3