diff --git a/.changeset/improve-a11y-href-docs.md b/.changeset/improve-a11y-href-docs.md new file mode 100644 index 0000000000..88e992b5de --- /dev/null +++ b/.changeset/improve-a11y-href-docs.md @@ -0,0 +1,12 @@ +--- +"svelte": patch +--- + +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. + +- Explain why href="#", empty href, and javascript: URLs are problematic for accessibility +- Provide practical alternatives (buttons for actions, valid hrefs for navigation) +- Include styling examples for making buttons look like links +- Add development placeholder suggestions \ No newline at end of file diff --git a/packages/svelte/messages/compile-warnings/a11y.md b/packages/svelte/messages/compile-warnings/a11y.md index a299fa53bc..9c07feadc7 100644 --- a/packages/svelte/messages/compile-warnings/a11y.md +++ b/packages/svelte/messages/compile-warnings/a11y.md @@ -189,9 +189,65 @@ Enforce that elements with an interactive role and interactive handlers (mouse o Enforce that attributes important for accessibility have a valid value. For example, `href` should not be empty, `'#'`, or `javascript:`. +**Why this matters for accessibility:** +- Screen readers announce links to users, but `href="#"` provides no meaningful destination information +- Users who navigate by links (a common screen reader navigation method) will encounter unhelpful link descriptions +- `href="#"` scrolls to the top of the page when clicked, which can be disorienting +- Opening in a new tab results in the same page or a blank page +- These links cannot be bookmarked or shared + +**Common mistakes and their solutions:** + +```svelte + +Click me + + +Click me + + +Click me +``` + +**Better alternatives:** + +If you need an element that performs an action (not navigation), use a button: +```svelte + + +``` + +If you need a link that looks like a button, style the button appropriately: +```svelte + + + + +``` + +For actual navigation, provide a valid href: +```svelte + +Go to page +Go to section +``` + +If you're creating a placeholder link during development: ```svelte - -invalid + +Coming soon ``` ## a11y_label_has_associated_control