CSS to speech: alternative text for CSS-generated content

Sara Soueidan · 2025年9月17日

AI 摘要 AI 生成,可能有误

本文解释了通过 ::before 和 ::after 伪元素插入的 CSS 生成内容如何被纳入元素的可访问名称计算中,以及为什么有意义的 CSS 图像、图标和 Unicode 字符需要描述性的替代文本,而装饰性内容则应对屏幕阅读器隐藏。文章介绍了 CSS 生成内容模块第 3 级(CSS Generated Content Module Level 3)的语法,该语法允许作者在 content 属性中的斜杠后提供替代文本(装饰性内容可使用空字符串作为替代文本),并指出除 Internet Explorer 等较旧的浏览器外,目前的浏览器支持已非常完善。作者分享了跨浏览器和屏幕阅读器(如 VoiceOver)的测试结果,观察到没有替代文本的 CSS 图像会被排除在无障碍树之外,而有替代文本的图像能被正确朗读;此外还存在一些小问题,例如 NVDA 不会朗读 Chrome 中 CSS 图像的替代文本,以及 Safari 仅在启用 VoiceOver 时才显示损坏的 CSS 图像的替代文本。

Changelog

  • Despite the fact that Chrome exposes the alt text of a CSS image as part of the accessible name of the element it is used on, James Scholes shared that the alt text is not announced by NVDA, which means that screen reader users using this popular browser-screen reader combination will miss out on meaningful information.
  • Removed the phrase that said that implied that CSS psuedo-elements are not exposed the same way that HTML elements are exposed in the accessibility tree. Chrome and Firefox now do expose pseudo-elements in the accessibility tree.
  • 继续阅读全文

    为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

    更多来自 Sara Soueidan

    The CSS caret-* properties and custom caret accessibility

    AI 摘要This article examines the CSS caret-* properties (caret-color, caret-animation, and caret-shape) and the accessibility considerations surrounding the caret, an often-overlooked focus indicator for editable text and caret browsing mode. It explains how caret browsing enables precise keyboard navigation of web pages, and how operating systems like macOS and Windows provide accessibility settings for caret blinking, thickness, and visibility that browsers honor inconsistently. The author urges caution when applying custom caret styles, since the caret may be the only focus indicator some keyboard or pointer users receive.

    My top picks for Interop 2027

    AI 摘要The author shares their ranked picks for Interop 2027, a yearly project aiming to improve cross-browser interoperability of key web platform features, using Firefox's community ranking page. Their top choices—the HTML focusgroup attribute and the ariaNotify() API—reflect their preference for features that improve both accessibility/user experience and developer experience, followed by other picks like heading-related HTML attributes, Interest Invokers, and various CSS properties. The author notes that features cannot be downvoted, only ranked or left unranked, and concludes by linking to blog posts where other web developers shared their own rankings.

    🎥 New (Video) Podcast: "Navigating the World of Web Accessibility with Sara Soueidan", with Kevin Powell

    AI 摘要The author and Kevin Powell finally recorded a nearly two-hour video podcast about navigating the world of web accessibility, covering topics like HTML semantics, ARIA, screen readers, the accessibility tree, how CSS affects accessibility, and the author's Practical Accessibility course. They also chatted about shared personal interests such as cooking, fermentation, and nutrition. The author invites front-end designers and developers curious about accessibility to watch or listen and share their feedback.

    CSS-only scrollspy effect using scroll-marker-group and :target-current

    AI 摘要The article explains how to create a CSS-only scrollspy effect using the new scroll-target-group property combined with the :target-current pseudo-class, which automatically highlights navigation links (like a table of contents) when their target sections are scrolled into view—no JavaScript required. It describes how applying scroll-target-group to a container of HTML anchors promotes them to scroll markers, letting the browser determine and style the active link. The author also covers accessibility considerations, including WCAG contrast requirements for active link styling and using aria-current to convey the active state to screen reader users.

    Are 'CSS Carousels' accessible?

    AI 摘要The article critically examines the accessibility of the newly announced 'CSS Carousels,' a set of CSS-only scrolling UI patterns built with new pseudo-elements like ::scroll-marker and ::scroll-button defined in the CSS Overflow Module 5 specification. Despite claims that carousel accessibility best practices are handled by the browser, the author's inspection of examples reveals significant accessibility and usability concerns, largely because these interactive pseudo-elements are not real DOM elements and the features are still experimental (currently only available in Chrome Canary behind a flag). The post aims to raise accessibility awareness so developers do not adopt these features prematurely and create confusing experiences for assistive technology users.