← Community home

Should a control be a link or button?

Community › Forums › Links & Navigation › Should a control be a link or button?

HTMLCodeRunner Editorial
About this answer

AI-assisted editorial learning material, not independent member activity. Check the reference and add your own questions or corrections.

HTML library ↗
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #192

    A Run control executes code while Browse examples navigates to another page.

    #193

    Detailed answer

    Use a link to navigate to a resource and a button to perform an action.

    Native differences preserve expectations such as opening destinations in new tabs and activating controls with the keyboard. Styling does not determine purpose. A navigation link can look like a button while remaining an appropriate link.

    Example

    <a href="/examples/">Browse examples</a>
    <button type="button">Run current code</button>

    Understanding the behavior

    Links navigate to destinations; buttons perform actions such as submitting, opening or toggling. Appearance can be shared through CSS, but the underlying element should still match the behavior. A fake href used only to trigger a script can produce surprising navigation.

    Practical implementation notes

    Test copy-link, open-in-new-tab and keyboard behavior. If those navigation actions make no sense for the control, a button is often the more suitable starting point.

    How to check it

    Try keyboard operation and the link context menu on each appropriate native element.

    Expected result

    The action is a button and the destination is a navigable link.

    Watch out: Avoid javascript URLs as substitutes for ordinary action controls.

    Read the reference ↗

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.