Web development
Choose a link or button for an interaction
Use a link for navigation to another location and a button for an action within the current interface. Native elements provide keyboard and interaction behavior that custom clickable containers must otherwise recreate.
Worked example
HTML example · save as example.html and open in a browser
<a href="/articles/">Browse articles</a>
<button type="button" id="toggle">Show details</button>
<p id="details" hidden>Additional information.</p>
<script>
document.querySelector('#toggle').addEventListener('click', () => {
document.querySelector('#details').hidden = false;
});
</script>How it works
The link has a destination that can be copied or opened in another tab. The button triggers a local state change. Setting type to button prevents accidental form submission if the control is later placed inside a form.
Limits and mistakes
A clickable div lacks the native semantics and keyboard behavior of these controls. The example is a one-way reveal; a true toggle should expose its expanded state and offer a way to hide the content again.
Check the result
Use Tab to reach both controls. Enter should follow the link, and keyboard activation of the button should reveal the details without navigating or submitting a form.
Sources
Reference documentation for the behavior used in this guide: