Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-2025-04-14· OpenAIHugging Face LMArena Human Preference 140K

Using html. I have a one page app. The nav links link to various sections of the page…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Coherecommand-a-03-2025’s answer.
  1. User

    Using html. I have a one page app. The nav links link to various sections of the page with a simple anchor link. e.g. <a href="#gallery-link">Gallery</a> It works, but the transition is instant and jarring. Is there a way to soften the transition?

  2. Assistant

    Yes! You can smoothly scroll to anchor links using a simple CSS property. Modern browsers support the scroll-behavior property, which makes anchor link navigation smooth and pleasant.

    How to do it

    Add this CSS to your stylesheet or inside a <style> tag in your HTML:

    html {
      scroll-behavior: smooth;
    }
    

    That’s it! Now, when you click on any anchor link (like <a href="#gallery-link">Gallery</a>), the page will scroll smoothly to the target section instead of jumping instantly.


    Example

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Smooth Scroll Example</title>
      <style>
        html {
          scroll-behavior: smooth;
        }
        section {
          height: 100vh;
          padding: 2em;
          border-bottom: 1px solid #ccc;
        }
        nav {
          position: fixed;
          top: 0;
          background: #fff;
          width: 100%;
          padding: 1em;
        }
      </style>
    </head>
    <body>
      <nav>
        <a href="#gallery-link">Gallery</a>
        <a href="#about-link">About</a>
      </nav>
      <section id="gallery-link">Gallery Section</section>
      <section id="about-link">About Section</section>
    </body>
    </html>
    

    Browser Support

    • Works in all modern browsers (Chrome, Firefox, Edge, Safari).
    • If you need to support very old browsers (like Internet Explorer), you’d need a JavaScript solution. Let me know if you need that!

    Summary:
    Just add html { scroll-behavior: smooth; } to your CSS, and your anchor links will scroll smoothly!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.