How can you ensure that the page doesn’t scroll when an internal link is clicked?
- Set the target element's position to fixed.
- Use JavaScript to prevent default scrolling.
- Use the noscroll attribute.
- Use the scroll-behavior: smooth; CSS property.
While HTML itself doesn't provide a built-in mechanism to prevent scrolling when an internal link is clicked, you can use JavaScript. By employing the event.preventDefault() method on the click event of the link, you can stop the default action (which is to navigate and scroll to the target element). For example: Link.
Loading...