惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
I
InfoQ
B
Blog RSS Feed
D
Docker
GbyAI
GbyAI
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
F
Fortinet All Blogs
P
Proofpoint News Feed
Microsoft Azure Blog
Microsoft Azure Blog
人人都是产品经理
人人都是产品经理
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
M
MIT News - Artificial intelligence
C
Check Point Blog
Vercel News
Vercel News
云风的 BLOG
云风的 BLOG
博客园 - Franky
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
Last Week in AI
Last Week in AI
L
LangChain Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Link or Button, that is the question.
Mica · 2026-06-22 · via DEV Community
Cover image for Link or Button, that is the question.

Mica

What is a Link?

Definition

A link is an interactive element that redirects the user to a new location which can be another section inside the current page, modifying the URL with a # parameter, or a new page. It can be used to download a file. Once activated, it takes the user to the URL set in its href. The browser records that navigation in its history, so the user can return to the previous page using the back button.

Semantic

The elements needs the attribute href with a valid URL or an IDREF pointing to a section inside the current page to have the semantic value of a link, otherwise it will be considered as generic.

<a href="/URL">
  Go to main page
</a>

Keyboard Interaction

It can only be activated by pressing the key Enter. If the key Space is pressed while the focus is on the link, the page will scroll down.

Screen Reader Interaction

Screen Readers, generally, announce the links in the following way: Link, [accessible name of the link]. It is extremely important to provide a descriptive and correct accessible name to the element.

Bad Practice

It is completely unnaceptable, a bad practice and goes against the native behavior of the element, forcing it to behave as a button by doing the following:

<a href="javascript:void(0)" onclick="openModal()">
  Open Menu
</a>

<a href="#" role="button" onclick="button()">
  Link with role button
</a>

If you need to do this, it means that you need a link.

What is a button?

Definition

A button is an interactive element that dispatches an action inside the page where it is located. It does not redirect the user to another place or location nor modifies the url. The actions that are being dispatched can be: open a modal, play a video, post a comment, etc.

Semantic

The button needs the attribute type with a value according to its action:
- type="button": it is used when the button does not have a default behavior.
- type="submit": it is used when the button sends information to a server.
- type="reset": it is used to reset all the values of an input or inputs to its initial value.

<button type=”button” onclick="openModal()">
  Open Modal
</button>

Keyboard Interaction

It can only be activated by pressing the keys Enter or Space.

Screen Readers Interaction

Screen Readers, generally, announce buttons in the following way: "Button, [Accessible Name of the button]". It is extremely important to provide a descriptive and correct accessible name to the element.

Bad Practice

It is completely unnaceptable, a bad practice and goes against the native behavior of the element, forcing it to behave as a link by doing the following:

<button onclick="window.location.href='/'">
  Go to homepage
</button>

If you need to do this, it means that you need a link.

Which one should I use: link or button?

  • Do you need an expandable section? use a <button> with the state aria-expanded and the focus should stay put.
  • Do you need to jump to a section on the same page? use an <a href="#section">. There is no page load, updated the url, lands the user at a destination.
  • Do you need to load more items into the current list? use a <button> and when the items load, the focus should be placed in the first item of the new items.
  • Do you need to redirect the user to a new location to read more about something? use an <a href="/destination">.
  • Do you need to open a menu? use a <button> with the states aria-haspopup and aria-expanded.
  • Do you need to play or pause a video? use a <button>.
  • Do you need to dowload a file? use a <a> with the attribute download.
  • Do you need a card that leads to a detail page? use a <a> stretched ::after.

Focus Style for Interactive Elements

It is vital for keyboard and screen reader users to have a visual and logic focus on interactive elements. Never do outline: none without providing a focus style:

a:focus-visible,
button:focus-visible {
  outline: 4px solid #0066ff;
  outline-offset: 4px;
}