The shortest solution is pure CSS: add html { scroll-behavior: smooth; } to your stylesheet. If you need more control, use this JavaScript version.

javascript">document.querySelectorAll( 'a[href^="#"]' ).forEach( function ( link ) {
    link.addEventListener( 'click', function ( e ) {
        var id = this.getAttribute( 'href' );
        if ( id.length < 2 ) {
            return;
        }
        var target = document.querySelector( id );
        if ( ! target ) {
            return;
        }
        e.preventDefault();
        target.scrollIntoView( { behavior: 'smooth' } );
    } );
} );
«
»