JavaScript Scroll Element To Top With Header Offset


    JS:
    function scroll2Top(el, header_height) {
        const element = document.getElementById(el);
        const elementPosition = element.getBoundingClientRect().top;
        const offsetPosition = elementPosition - header_height;
        window.scrollBy({ top: offsetPosition, behavior: "smooth" });
    } 

    HTML:
    <h2 id="browse-brands" onclick="scroll2Top('browse-brands', 75)">Browse Brands</h2>