axe-core svg-img-alt missing accessible name error
Fixes the axe-core svg-img-alt error by naming meaningful svgs and hiding decorative ones from assistive tech. Use it when axe flags svg elements missing alternative text. Not for decorative svgs that are already correctly hidden.
axe-core svg-img-alt missing accessible name error - how to fix it
TL;DR
Give the svg an accessible name: a title element inside the svg, an aria-label on the svg, or mark it decorative with aria-hidden true. If the svg is the only content of a link or button, the svg needs the name. One line of why: svg with img role is announced like an image, and an image with no name is noise to a screen reader.
The error, verbatim
{
"id": "svg-img-alt",
"impact": "serious",
"help": "svg elements with an img role must have an alternative text",
"nodes": [
{ "target": [".logo-svg"], "failureSummary": "Fix any of the following: Element does not have an accessible name" }
]
}Fix it step by step
Step 1: Reproduce on one page
npx @axe-core/cli https://example.com --rules svg-img-alt --save axe-svg.jsonExpected: Violations array contains svg-img-alt with the svg selectors.
Step 2: Check which svgs are meaningful vs decorative
rg -n --glob '*.{jsx,tsx,vue}' 'svg' src/components | head -30Expected: A list of svg usages to triage: logos and icons that convey meaning need names, decorative flourishes get aria-hidden.
Step 3: Name the meaningful ones, hide the decorative ones
node -e "console.log('edit: add title or aria-label to meaningful svgs, aria-hidden true to decorative ones')"Expected: Placeholder check that you touched the right files, the real verification is the re-scan.
Step 4: Re-scan
npx @axe-core/cli https://example.com --rules svg-img-altExpected: Exit code 0, 0 violations. Screen reader announces the logo name and skips the decorative svgs.
Step 5: Gate the rule in CI
npx @axe-core/cli https://example.com --exit | tail -3Expected: Non-zero exit while any violation remains; add this command to CI so the fix never regresses.
When to use this skill
- Your axe-core report lists this exact rule id under violations
- You are clearing automated WCAG 2.1 AA failures before a release or audit
- A CI a11y gate (pa11y-ci, lighthouse CI, cypress-axe) is red because of this rule
When NOT to use this skill
- The issue only shows up in manual screen-reader testing and axe reports zero violations for the rule
- You are doing a full manual WCAG audit, this skill covers the single automated rule only
- The page is a third-party embed you cannot edit, flag it to the vendor instead
Compatibility
axe-core 4.8+ (rule svg-img-alt, WCAG 1.1.1). Same rule in axe DevTools, pa11y, and lighthouse v10+. Pin the tool version in the lockfile so scans stay reproducible across machines.
Variant phrasings
svg elements with an img role must have alternative text
The help text wording, same fix.
axe logo svg no accessible name
The classic instance: a linked logo svg with no title.
axe DevTools flags the same rule
The browser extension runs the same rule engine; fix once and it clears in every runner.
Why it happens
Inline svgs that carry role img (explicitly or via a link/button context) are treated as images, but unlike img elements they have no alt attribute convention, so authors forget the name entirely. Icon systems that sprite svgs with use elements are the worst offenders: the use shadow content rarely carries a title. Axe only flags svgs with an img role, so purely decorative inline svgs without a role pass silently, which is why teams are surprised when the rule fires on some svgs and not others. The same violation usually repeats on every page built from the same template, so fix the component or template once instead of patching pages. After the fix, re-scan the whole site, not just the one page, to confirm the template-level change cleared them all.
Edge cases
- A title element as the first child of svg is the most robust name across browsers, aria-label on svg works too but test your target browsers.
- svgs referenced by use inherit nothing automatically, put the title in the use instance or an aria-label on the use element.
- If the svg sits inside a button that already has an aria-label, mark the svg aria-hidden true so the name is not announced twice.
- Fix every instance of the rule before moving on; a half-fixed rule across templates re-fails the next full scan.
Provenance
Resolved from the public thread: https://vectle.com/posts/pstP0OWtWVcxPf0UCnkuPZ6g
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.