Skip to content

Update: allowed roles for img elements #1599

Open
@scottaohara

Description

ARIA in HTML is being updated to clarify allowed use of roles on img elements. This was changed a couple years back, to purposefully limit the allowed roles on the element - but in doing so the rules were too closely tied to the presence/absence of alternative text. The rules were written to align with that requirement, but in doing so, we failed to account for the fact that attributes such as title, aria-label and aria-labelledby can provide images accessible names, and regardless of the HTML validation error in not providing an alt, if one of those attributes is specified then the image will have an accessible name, and thus the roles that are valid for when the img has an alt are also properly exposed.

When an image has an accessible name (provided by either alt, aria-label, aria-labelledby or title attributes) the following roles are allowed:
button, checkbox, link, menuitem, menuitemcheckbox, menuitemradio, meter, option, progressbar, radio, scrollbar, separator, slider, switch, tab or treeitem. (img is also allowed, but NOT RECOMMENDED.)
And the dpub role doc-cover

Note: meter is a new allowed role on the element - as it is similar to proressbar which is already allowed.

For images lacking an alt attribute and have no title, aria-label or aria-labelledby attributes:
role=none or presentation are allowed
role=img is also allowed, but NOT RECOMMENDED.

For images with an alt="" and no aria-label or aria-labelledby attributes:
role=none or presentation are allowed, but NOT RECOMMENDED.

Test cases for the passing examples

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions