Leaflet icon indicating copy to clipboard operation
Leaflet copied to clipboard

Consider not using default text in `alt` and `title`

Open Malvoz opened this issue 3 years ago β€’ 4 comments

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 if title or alt/desc was 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 descriptive alt/title (as encouraged by our guideline for accessible markers)
  • ❌ Inconsistent names depending on if title or alt was used:
    • If a developer only sets the title to e.g. "Kyiv", a screen reader would announce "Button, marker, Kyiv"
    • If a developer only sets the alt to e.g. "Kyiv", a screen reader would announce "Button, Kyiv"
  • ❌ 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.

Malvoz avatar May 25 '22 07:05 Malvoz

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:

  1. Accessibility: Developers should explicitly define meaningful alt and title texts instead of relying on defaults.
  2. Consistency: Prevents inconsistent screen reader outputs and ensures better localization control.

Next Steps:

  1. Modify Marker.js to default alt and title to empty strings.
  2. Update documentation to emphasize the importance of setting these attributes for accessibility.

SaxenaPrashast avatar Oct 03 '24 16:10 SaxenaPrashast

I would like to add my two cents to this discussion.

  1. 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.
  2. 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
  3. 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.

chcederquist avatar Apr 25 '25 17:04 chcederquist

Hi, I’m new to contributing and I’d like to work on this issue. Can I take it?

LaxmiGodara avatar Oct 04 '25 08:10 LaxmiGodara

My plan is to update the default marker alt from 'Marker' to ' ' and adjust the comment/docs accordingly.

LaxmiGodara avatar Oct 04 '25 08:10 LaxmiGodara