Why can’t I use CSS :before and :after to insert content?
Question
Answer
This is a great question. Although you are correct about some screen readers reading content inserted using :before and :after, it still is not a good practice to insert meaningful content this way. The problem with utilizing :before and :after is when a person needs to disable CSS on a site. Once disabled this inserted meaningful content needs to remain visible and in a place on the page that is logical.
As called out in WCAG Success criteria 1.3.1, Information and relationships that are implied by visual or auditory formatting are preserved when the presentation format changes. Additionally WCAG Success criteria 1.3.2 for meaningful sequence calls says that when the sequence in which content is presented affects its meaning, a correct reading sequence can be programmatically determined.
There is no indication that the WCAG guidelines will be updated to allow for the use of :before and :after for inserting meaningful content, because of the issues noted above around meaningful content not being preserved when CSS is disabled.
Free Tools to Continue Learning
Accessible Web RAMP
Monitor your website and manage your progress towards WCAG conformance.
Accessible Web Academy
Career specific courses to help power up your accessibility knowledge.