I'm trying to set up a horizontal navigation header for my website, with links like Home, About, Product, Contact, etc. My goal is for these links to jump to different sections within the same page of my HTML document. I'm a bit confused about whether I should use anchor tags () or buttons for this. Any advice?
5 Answers
Definitely go for anchor tags! You'll want to use something like About for navigation. It's the right way to let users jump to sections of the same page, and you'll get good accessibility out of it too! Plus, it’s simple and doesn’t require any JavaScript.
Yeah, I agree with the anchor tags. They’re specifically meant for navigation. If you're looking to toggle a dropdown on a mobile version, that's where a button comes into play. But for your horizontal nav, stick with tags that point to the IDs of your sections. It just makes sense!
Both could work, actually. You might want one for basic navigation (the anchor tag) and another for actions like toggling dropdown menus—usually with a button. This way, you avoid confusion for users wanting to navigate versus those wanting to perform an action.
Thanks for the clarification! I'll stick with the anchor tags then.