Consider not using default text in `alt` and `title`
From discussion in PR https://github.com/Leaflet/Leaflet/pull/8251#discussion_r881053782:
We should consider not using default titles.
Relatedly, I've been thinking of partially reverting https://github.com/Leaflet/Leaflet/pull/7895 to remove the default
alt="Marker", for several reasons (passing accessibility audits by default doesn't encourage unique titles, localization, inconsistent names depending on iftitleoralt/descwas used).
Should we revert the "Marker" alt to empty string? I believe so.
https://github.com/Leaflet/Leaflet/blob/93f681c488ec07690cd4a393056078cf88f3bcff/src/layer/marker/Marker.js#L46-L49
Pro's of "Marker" as default:
- βοΈ Each marker has an accessible name (such that screen reader users can know this is a marker)
Con's of "Marker" as default:
- β Passing accessibility audits for (marker)
role="button"by default doesn't encourage unique and descriptivealt/title(as encouraged by our guideline for accessible markers) - β Inconsistent names depending on if
titleoraltwas used:- If a developer only sets the
titleto e.g. "Kyiv", a screen reader would announce "Button, marker, Kyiv" - If a developer only sets the
altto e.g. "Kyiv", a screen reader would announce "Button, Kyiv"
- If a developer only sets the
- β Localization/translation: If developers don't change the current default, they may unintentionally have mixed languages in their documents (although this is also true for other things such as
aria-labels in zoom controls etc. Related: https://github.com/Leaflet/Leaflet/issues/9092)
Additional consideration
If we revert the "Marker" alt, we should also consider removing the default titles "Circle", "Circle marker", "Polyline", "Polygon", "Rectangle" for vectors in https://github.com/Leaflet/Leaflet/pull/8251#discussion_r881053782. Can be adressed separately.
Proposal: Remove Default Text for Alt and Title Attributes
Description:
I propose removing the default alt: 'Marker' and title attributes from Marker.js. This encourages developers to provide unique, descriptive alt and title texts, improving accessibility and preventing inconsistent screen reader behavior.
Rationale:
- Accessibility: Developers should explicitly define meaningful alt and title texts instead of relying on defaults.
- Consistency: Prevents inconsistent screen reader outputs and ensures better localization control.
Next Steps:
- Modify Marker.js to default alt and title to empty strings.
- Update documentation to emphasize the importance of setting these attributes for accessibility.
I would like to add my two cents to this discussion.
- The alt attribute correctly describes the marker image. If its not there by default, it would be totally undescriptive. It may fail an automated audit, but the lazy developer that never audits won't catch it, and the correctly performed audit (automated + manual testing) would likely catch it, if it is an actual issue. Maybe other avenues for incentivising correct descriptions of markers should be explored before removing the default alt-attribute.
- I would argue that it isn't inconsistent, as the documentation clearly states the default value of alt, and that title is empty by default
- I think that language consistency should be achieved as part of the #9092 , rather than here, as this inconsistency is a specific case of a bigger issue.
Hi, Iβm new to contributing and Iβd like to work on this issue. Can I take it?
My plan is to update the default marker alt from 'Marker' to ' ' and adjust the comment/docs accordingly.