document.querySelectorAll('a[href^="#"]').forEach(link => { link.addEventListener('click', function(e) { const target = document.querySelector(this.hash); if (target) { e.preventDefault(); const headerOffset = 120; // adjust to your header height const elementPosition = target.getBoundingClientRect().top; const offsetPosition = elementPosition + window.scrollY - headerOffset; window.scrollTo({ top: offsetPosition, behavior: "smooth" }); } }); });