Skip to content
WordPressRule: svg-img-alt•Reviewed Oct 2026

Provide accessible text for SVG images with role img in WordPress

SVGs with `role="img"` must contain an accessible label or `<title>` element.

What's wrong

Screen readers announce an unlabelled SVG with `role="img"` as an empty graphic without context.

Who it affects

Screen reader users miss branding, icons representing payment methods, or rating stars.

How to fix on WordPress

Include a `<title>` tag inside inline SVG assets or specify `aria-label="Description"` on the SVG tag.

Code example

Problematic Code
PHP
<svg role="img" class="star-rating">...</svg>
Recommended Accessible Code
PHP
<svg role="img" class="star-rating" aria-label="<?php echo esc_attr( sprintf( __( 'Rating: %s out of 5 stars', 'textdomain' ), $rating ) ); ?>">
  <path d="..."></path>
</svg>

How to check your fix

Test with a screen reader to confirm the SVG announces the descriptive title rather than remaining silent.

Check if your site has this issue

Scan any public store page free against WCAG 2.2 AA in 30 seconds.

Your session has ended

Sign in again to carry on. Anything you typed on this page is kept.

Signed in another way? Use another method (opens a new tab)