Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for The semantics of interaction vs navigation
Thomas Rigby
Thomas Rigby

Posted on

     

The semantics of interaction vs navigation

It is commonplace for designers to style both links and buttons to look like “buttons”. But just because somethinglooks like a button, doesn’t mean itis a<button> .

The general rule is to use<button> to control in-page interaction and<a href="/path/to/link-destination"> to control navigation to a different page.

Examples of where to use a button element include toggling an off-canvas menu or loading more posts. If you are navigating to a different page - use an anchor link.

Never, ever, ever do this:

<buttononClick="function(){ window.location.href = '/path/to/new/page.html' }">  Click me</button>
Enter fullscreen modeExit fullscreen mode

Assistive technologies will announce button and link elements differently and they can be activated in different ways depending on the element - use the wrong one and you run the risk of confusing the user.


The in-page “anchor” link is an exception to this. Always use an<a href="#anchor-link"> tag for that even though the user doesn’t leave the page. This is because it will modify the URL and helps the user find the content.

Again, the same effect can be achieved using JavaScript to manipulate the Browser History API but why would you write extra code to recreate something the browser gives you for free?!

Oh, and if you're missing the "smooth scrolling" that you can add with JavaScript, consider thefairly well-supportedscroll-behavior: scroll; property.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

When I'm not building things for the internet, I take photos of stuff. Code Janitor. 1x Engineer.
  • Location
    Manchester, UK
  • Pronouns
    he/him/his
  • Work
    Senior Developer
  • Joined

More fromThomas Rigby

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp