Skip to content

Commit 3262ca1

Browse files
docs: improve a11y_invalid_attribute warning documentation
Enhance documentation for href validation warnings to better explain accessibility concerns and provide clear alternatives. This addresses confusion from issue #15654. Changes: - Explain why href="#", empty href, and javascript: URLs are problematic - Provide practical alternatives (buttons for actions, valid hrefs for navigation) - Include styling examples for making buttons look like links - Add development placeholder suggestions
1 parent ce4a99e commit 3262ca1

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
docs: improve a11y_invalid_attribute warning documentation
6+
7+
Enhance documentation for href validation warnings to better explain accessibility concerns and provide clear alternatives. This addresses confusion from issue #15654.
8+
9+
- Explain why href="#", empty href, and javascript: URLs are problematic for accessibility
10+
- Provide practical alternatives (buttons for actions, valid hrefs for navigation)
11+
- Include styling examples for making buttons look like links
12+
- Add development placeholder suggestions

packages/svelte/messages/compile-warnings/a11y.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,65 @@ Enforce that elements with an interactive role and interactive handlers (mouse o
189189
190190
Enforce that attributes important for accessibility have a valid value. For example, `href` should not be empty, `'#'`, or `javascript:`.
191191

192+
**Why this matters for accessibility:**
193+
- Screen readers announce links to users, but `href="#"` provides no meaningful destination information
194+
- Users who navigate by links (a common screen reader navigation method) will encounter unhelpful link descriptions
195+
- `href="#"` scrolls to the top of the page when clicked, which can be disorienting
196+
- Opening in a new tab results in the same page or a blank page
197+
- These links cannot be bookmarked or shared
198+
199+
**Common mistakes and their solutions:**
200+
201+
```svelte
202+
<!-- ❌ A11y: '' is not a valid href attribute -->
203+
<a href="">Click me</a>
204+
205+
<!-- ❌ A11y: '#' is not a valid href attribute -->
206+
<a href="#">Click me</a>
207+
208+
<!-- ❌ A11y: 'javascript:void(0)' is not a valid href attribute -->
209+
<a href="javascript:void(0)">Click me</a>
210+
```
211+
212+
**Better alternatives:**
213+
214+
If you need an element that performs an action (not navigation), use a button:
215+
```svelte
216+
<!-- ✅ Correct: Use button for actions -->
217+
<button type="button" on:click={handleClick}>Click me</button>
218+
```
219+
220+
If you need a link that looks like a button, style the button appropriately:
221+
```svelte
222+
<!-- ✅ Style a button to look like a link if needed -->
223+
<button type="button" class="link-style" on:click={handleClick}>
224+
Click me
225+
</button>
226+
227+
<style>
228+
.link-style {
229+
background: none;
230+
border: none;
231+
color: blue;
232+
text-decoration: underline;
233+
cursor: pointer;
234+
padding: 0;
235+
font: inherit;
236+
}
237+
</style>
238+
```
239+
240+
For actual navigation, provide a valid href:
241+
```svelte
242+
<!-- ✅ Correct: Provide meaningful href for navigation -->
243+
<a href="/page">Go to page</a>
244+
<a href="#section">Go to section</a>
245+
```
246+
247+
If you're creating a placeholder link during development:
192248
```svelte
193-
<!-- A11y: '' is not a valid href attribute -->
194-
<a href="">invalid</a>
249+
<!-- ✅ Better: Make it clear this is temporary -->
250+
<a href="/todo" aria-label="Link to be implemented">Coming soon</a>
195251
```
196252

197253
## a11y_label_has_associated_control

0 commit comments

Comments
 (0)