18 / 24

How to scroll to an id?

Using id in the url: <Link href='/dashboard#settings'>Settings</Link>

Difficulty: 5/10
Topics: hash navigation, client-side routing, SSR scrolling

Scenario Questions

0-2 years experience
  1. 1

    We have a simple Next.js page with several sections each having an id. How would you implement a button that scrolls smoothly to the 'contact' section when clicked?

  2. 2

    If you use a plain anchor tag <a href="#about"> on a Next.js page, what happens during client‑side navigation, and how can you ensure the page scrolls to the target element?

2-5 years experience
  1. 1

    You added a 'Scroll to Top' button using window.scrollTo inside a component, but it doesn't work after navigating to a new route via next/router. What could be causing this, and how would you fix it?

  2. 2

    During a feature rollout, some users report that clicking a link to an in‑page anchor doesn't scroll on mobile Safari. Walk me through how you'd debug and resolve the issue in a Next.js app.

5-8 years experience
  1. 1

    Our application uses dynamic routes and server‑side rendering. We need deep linking to sections inside a page (e.g., /blog/[slug]#comments). How would you design a solution that works both on initial load (SSR) and client‑side navigation, while avoiding layout shift?

  2. 2

    Consider performance: a page has 200 sections with ids and we need to scroll to a specific one on demand. What strategies would you employ in Next.js to keep the scroll operation fast and avoid blocking the main thread?

8+ years experience
  1. 1

    We are migrating a legacy multi‑page site to Next.js, and many external partners rely on hash‑based navigation for documentation pages. What architectural changes would you propose to support reliable hash scrolling, SEO, and analytics across teams?

  2. 2

    How would you build a shared scrolling utility library for all Next.js apps in the organization that handles SSR, hydration, accessibility, and integrates with our routing conventions, while allowing teams to customize smooth‑scroll behavior?

Follow-up Questions

  • What edge cases arise when the page is server‑rendered and the hash is present in the URL?
  • How does Next.js's router affect scroll restoration after back/forward navigation?
  • Can you describe any accessibility considerations when scrolling programmatically?