Properties that matter:
Visibility
CSS regarding visibility is picked up by screen readers as it is assumed you do not want people interacting with this item if it is not visible. Otherwise an entire section that is hidden from "sighted users" would be visible to screen reader users and offer them a different experience. For example:
display: none
- universal support, if an element has this property it is assumed you do not want anyone seeing it.
visibility: hidden
- same but some really older screen readers may pick this up still
opacity: 0
- not as effective as some screen readers may still pick this up but most will ignore.
visibility: collapse
- use on tables, not sure how well supported it is but it should be interpreted as visibility: hidden
by the browser (and therefore by the accessibility tree)
Size
If something is 0px tall or 0px wide it is not visible. For this reason the same rule is applied that if "sighted users" can't see it then screen reader users do not want to see it either.
Content property
This one is really inconsistent across different browser and screen reader combinations. You may see it in the accessibility tree but it does not mean that it will be used by the screen reader.
The thing is that technically screen readers should read the content.
Now because we as developers have used this for loads of styling tricks they have now improved the content
property to have alt text. It only has 70% browser support at the moment and screen reader support will be even worse but eventually that problem will fix itself.
To get ahead of the curve on this all you need to do is add a slash between the displayed content and the alt text:
.myClass:after{
content: "❤" / "favourited item";
}
CSS positioning
Technically this is kind of the opposite, where CSS is used to change the visual design (and make it logically ordered) but the DOM order is incorrect.
So although this one isn't quite a CSS affecting the accessibility tree item, it is closely related in such a way I thought I would mention it.
If you use CSS grid and change the positions of grid items you may end up with the DOM order being 1,2,3 but the visual order being 2,1,3.
Now if the logical reading order is 2,1,3 that can be super confusing for screen reader users as everything is read in the wrong order.
The same principle applies to float: right
and flex-direction: reverse
.
Negative margins can also cause some issues. For example be careful with margins when trying to visually hide text (when you mentioned about screen reader only text) - some browsers actually tried to correct for negative margins and meant that things were read out of order.
I would suggest reading this answer if you are looking for the current best practice on visually hiding things for screen reader users only!
Conclusion
I think that is it, but there could be others I haven't thought of.
In essence the reason CSS "leaks" into HTML here is because of how CSS affects what content is on the page and one core idea behind accessibility is "provide as similar experience / information as possible to people using assistive technology".
Surprisingly things like transform
, backface-visibility: hidden;
etc. do not seem to have any effect on screen readers, but I couldn't find anything in the spec that says whether they should or they shouldn't affect the accessibility tree and my tests were limited!
Finally I put "sighted users" in quotes as a lot of screen reader users have reasonable vision, some have perfect vision and use one to aid comprehension, it is just easier to compare "sighted" and "non sighted" when explaining the principles.