Question Details

No question body available.

Tags

r accessibility r-leaflet

Answers (1)

Accepted Answer Available
Accepted Answer
July 14, 2025 Score: 4 Rep: 12,311 Quality: Expert Completeness: 80%

This post suggests setting the aria-label inside the HTML-DOM will be picked up by screenreaders. And indeed, when I installed Nv-Access and navigated to the leaflet page created by the following code, it reads out aria-label when hovering over the map. This says further "(Note: it's necessary to include role="img" on the div in order to conform to the requirement that aria-roledescription is only used on elements with an implicit or explicit ARIA role (div elements do not have an implicit ARIA role, so one is provided explicitly using the role attribute).". this suggests that the alt attribute only works for images: but a leaflet map is an interactive widget which does load images but not in the real sense of the tag but as tiles and resides within a container (div). I guess you render your quarto to HTML, so this code should work for your usecase.

library(leaflet)

leaflet() %>% addTiles() %>% setView(lng = -3.7, lat = 40.4, zoom = 5) %>% htmlwidgets::onRender(" function(el, x) { el.setAttribute('role', 'img'); el.setAttribute('aria-label', 'Interactive Leaflet map with Spain in the center.'); } ")