Skip to content
  • Home
  • About Léonie
  • On other websites

Accessibility support for CSS generated content

29 March 2015
  • Code things

The CSS before/after pseudo-selectors can be used to insert content into a page. In some situations this technique is a useful thing to do, but how do browsers and screen readers handle the generated content?

Quick recap: The before/after selectors insert content either before or after an element’s existing content. For example the CSS shown below will insert "bar" immediately after the "Foo" that is already present in the HTML:

Code language
CSS
#a:after { content: 'bar'; }
Code language
HTML
<a href="/" id="a">Foo</a>

The result of which can be seen in this test case. For more information on using these selectors, read Chris Coyer’s introduction to after/before on CSS Tricks.

Accessibility mechanics

CSS generated content isn’t included in the DOM. Ordinarily browsers take information from the DOM to create the accessibility tree, but in this case the generated content is still factored into the accessible name computation for the element.

Accessibility results

Using the test case mentioned before indicates that generated content is accessibility supported in most browsers, and recognised by screen readers accordingly. Internet Explorer is the only browser regularly used with a screen reader that does not expose the generated content as the accessible name for the element. Screen readers depending on MSAA/UIAutomation in IE are therefore unaware of the generated content.

Browser and screen reader support for CSS generated content

Chrome 41 (Android)Chrome 41 (Windows)Firefox 36 (Windows)Internet Explorer 11 (Windows)Safari 8 (OSX)Safari 8.1 (iOS)
Jaws 16N/AYesYesNoN/AN/A
NVDA 2015.1N/AYesYesNoN/AN/A
TalkBackYesN/AN/AN/AN/AN/A
VoiceOverN/AN/AN/AN/AYesYes

With Internet Explorer accounting for about 15% of traffic (in March 2015), there is good reason to consider the viability of using CSS generated content.

There is another more important consideration however * the separation of content and structure from design. Introducing content through the design layer breaks the standards model, and so it should be done only when the generated content does not alter the meaning of the original content. In other words, use CSS generated content to change or supplement the design, but not to create or alter important content on the page.


Tagged with

  • Css
  • Html
  • Screenreaders

Comments

Tags

  • Standards
  • Screen readers
  • HTML
  • ARIA
  • Dinner
  • Linux
  • Apps
  • Windows
  • Lunch
  • Games
  • Philosophy
  • Accompaniments
  • Breakfast
  • Web standards food
  • Pudding
  • JavaScript
  • Schema
  • CSS
  • Web Speech API
  • Drinks
  • SVG
  • WebVR
  • Artificial Intelligence
  • Privacy
  • Voice
  • AI

Categories

  • Web life
  • Code things
  • Recipe book
  • Desktop things
  • Real life
  • Mobile things

Talks

  • 2021
  • 2020
  • 2019
  • 2018
  • 2017
  • 2016
  • 2015
  • 2014
  • 2013
  • 2012
  • 2011

Follow me on:

  • Bluesky
  • Mastodon
  • GitHub
  • LinkedIn

© Léonie Watson Carpe diem