Replace anchor scrolling script by CSS's scroll-behavior

Handling anchor links in Javascript is not necessary anymore since scroll-behavior: smooth; allows smooth scrolling all over your site when clicking anchor links.

Additionally, the current Javascript implementation does not take into account CSS properties like scroll-margin-top or scroll-padding-top, which can cause major issues with user experience when there are fixed or sticky elements on the page (ex.: a fixed header).

Simply replacing the current Javascript implementation by a default setting of scroll-behavior: smooth; on the body element would fix these issues, and remove unneeded Javascript.

  • Émile Perron
  • Jan 26 2022