<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Marcy Sutton</title>
    <description>The latest articles on Forem by Marcy Sutton (@marcysutton).</description>
    <link>https://forem.com/marcysutton</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F143480%2F47f260f9-e56c-48d2-a003-83e9b00a21c8.jpg</url>
      <title>Forem: Marcy Sutton</title>
      <link>https://forem.com/marcysutton</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/marcysutton"/>
    <language>en</language>
    <item>
      <title>Content-visibility and Accessible Semantics</title>
      <dc:creator>Marcy Sutton</dc:creator>
      <pubDate>Sat, 19 Dec 2020 01:13:05 +0000</pubDate>
      <link>https://forem.com/marcysutton/content-visibility-and-accessible-semantics-2994</link>
      <guid>https://forem.com/marcysutton/content-visibility-and-accessible-semantics-2994</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Updated April 1, 2021:&lt;/strong&gt; The situation as I originally described is no longer an issue, it seems! Read on for more details. The lessons still stand: test in Assistive Technologies, report bugs to browser and AT makers. Makes the world a better place.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;While working with the team at &lt;a href="https://dev.to"&gt;DEV&lt;/a&gt; this past quarter, they requested I review a PR for accessibility on GitHub that introduced a new Chrome-only CSS feature: &lt;code&gt;content-visibility&lt;/code&gt;. I'd missed the announcement of this feature months earlier by Chrome advocates, so my first step was to read up on it to understand the potential accessibility impact.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is &lt;code&gt;content-visibility&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;According to a post on &lt;a href="https://web.dev/content-visibility/" rel="noopener noreferrer"&gt;Web.dev&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;content-visibility&lt;/code&gt; enables the user agent to skip an element's rendering work, including layout and painting, until it is needed. Because rendering is skipped, if a large portion of your content is off-screen, leveraging the content-visibility property makes the initial user load much faster. It also allows for faster interactions with the on-screen content.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This feature is meant to improve page load performance by skipping over content detected as being "off-screen", or outside of the viewport. There are two possible values for &lt;code&gt;content-visibility&lt;/code&gt;: &lt;code&gt;auto&lt;/code&gt; and &lt;code&gt;hidden&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/forem/forem/pull/11560" rel="noopener noreferrer"&gt;Forem PR&lt;/a&gt; from Ben Halpern included &lt;code&gt;content-visiblity: auto&lt;/code&gt;, which marks content as off-screen that will become visible in the viewport through scrolling, telling the browser to skip it in the initial rendering phase. The &lt;code&gt;hidden&lt;/code&gt; value tells the browser to skip content that shouldn't ever automatically render on-screen through scrolling, more akin to CSS &lt;code&gt;display: none&lt;/code&gt; or &lt;code&gt;visibility: hidden&lt;/code&gt; but with extra performance benefits. Potential use cases cited are advanced virtual scrollers and measuring layout.&lt;/p&gt;

&lt;p&gt;Neat. But my spidey accessibility senses went off as soon as I read those words: &lt;strong&gt;off-screen&lt;/strong&gt; and &lt;strong&gt;rendering&lt;/strong&gt;. We use off-screen content in the accessibility world to render content for the purpose of exposing to screen readers, such as visually-hidden headings or &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; elements inside buttons. Screen readers typically utilize the &lt;a href="https://www.smashingmagazine.com/2015/03/web-accessibility-with-accessibility-api/" rel="noopener noreferrer"&gt;Accessibility Tree&lt;/a&gt;, a parallel structure to the DOM that contains only what is rendered on screen and is affected by things like CSS &lt;code&gt;display: none&lt;/code&gt; and &lt;code&gt;aria-hidden: true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;My initial thought was that &lt;code&gt;content-visibility: auto&lt;/code&gt; could pose an access problem on initial load by suppressing part of the page outline from screen readers, so I set out to test it.&lt;/p&gt;

&lt;p&gt;The Web.dev team included a &lt;a href="https://codepen.io/vmpstr/pen/xxZoyMb" rel="noopener noreferrer"&gt;nice demo on Codepen&lt;/a&gt; that I used right away, since a local Forem instance requires a more involved setup to mimic the live &lt;a href="https://dev.to"&gt;Dev.to&lt;/a&gt; site. I noticed the Codepen authors had marked up &lt;code&gt;.story&lt;/code&gt; DIV elements with CSS &lt;code&gt;content-visibility: auto&lt;/code&gt; applied, with headings preceding those DIVs (so therefore outside). They'd possibly anticipated an accessibility issue, but didn't originally write about it in the post*.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F92hw0ysgq2cvyxrvgm2f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F92hw0ysgq2cvyxrvgm2f.png" alt="HTML snippet with an h2 preceding a DIV with the .story class"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A Google search turned up two posts from &lt;a href="https://css-tricks.com/more-on-content-visibility/" rel="noopener noreferrer"&gt;CSS Tricks&lt;/a&gt; and &lt;a href="https://html5accessibility.com/stuff/2020/08/25/short-note-on-content-visibility-hidden/" rel="noopener noreferrer"&gt;Steve Faulkner&lt;/a&gt;, but neither touched on the impacts of &lt;code&gt;content-visibility: auto&lt;/code&gt; on semantic structure. So here I go, writing about it!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;**Update, March 12, 2021:&lt;/em&gt;* Google has updated how &lt;code&gt;content-visiblity&lt;/code&gt; works in Chrome 90 (see below). Una Kravets also notified me she updated the page on &lt;a href="https://web.dev/content-visibility/#a-note-on-accessibility" rel="noopener noreferrer"&gt;Web.dev&lt;/a&gt; to include a note about accessibility.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Accessibility impact on semantic structure
&lt;/h2&gt;

&lt;p&gt;In earlier versions of &lt;code&gt;content-visibility&lt;/code&gt; (Chrome 85-89), headings and other content will be suppressed by &lt;code&gt;content-visibility&lt;/code&gt; if considered off-screen. That meant that content would be hidden on load from the Elements List in NVDA and rotor in Voiceover, impacting the overall page outline and summary read aloud.&lt;/p&gt;

&lt;p&gt;To test this, I moved an h2 in and out of a DIV with &lt;code&gt;content-visibility: auto&lt;/code&gt; applied. When the heading was outside of the DIV like they set it up in the demo, it was rendered. Here's a screenshot of the Elements List in NVDA:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3hepbul1uembnhfc2hs5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3hepbul1uembnhfc2hs5.png" alt="NVDA Elements List showing all headings, including being "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When moved inside of the &lt;code&gt;.story&lt;/code&gt; DIV with &lt;code&gt;content-visibility: auto&lt;/code&gt;, the heading was suppressed by screen readers including NVDA (as expected):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flo8tv7jfdnmxhkw4ibuz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flo8tv7jfdnmxhkw4ibuz.png" alt="NVDA Elements List missing a heading"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This meant that if you were trying out &lt;code&gt;content-visibility&lt;/code&gt; on sections of content including headings and semantic structure, screen reader users wouldn't be able to benefit from that structure on load. This unfortunately degraded accessibility in favor of loading performance until it was fixed, &lt;a href="https://twitter.com/sundress/status/1346685692974284800" rel="noopener noreferrer"&gt;partially due to this post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Based on my testing, I initially recommended keeping headings and landmark elements outside of regions styled with &lt;code&gt;content-visibility: auto&lt;/code&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Without this approach of crafting semantic markup for rendering on load, as originally implemented &lt;code&gt;content-visibility&lt;/code&gt; would negate the purpose of including semantic structure to begin with. It would have required scrolling the page to have a complete and accurate page outline read aloud; likely not what developers would intend by using it! Fortunately this behavior was marked as a bug and fixed.&lt;/p&gt;

&lt;p&gt;From the sounds of it, the Chrome team had some discussions along the way about accessibility in &lt;code&gt;content-visibility&lt;/code&gt; but the production implementation had some issues. I'm glad to see they've fixed it and are &lt;a href="https://twitter.com/sundress/status/1368757783210827784" rel="noopener noreferrer"&gt;improving their QA process according to Alice Boxhall&lt;/a&gt;. It makes me feel for accessibility folks, though. If you don't watch features like a hawk for accessibility, the ball is very often dropped.&lt;/p&gt;




&lt;p&gt;Note: the PR from Forem ended up marking only the footer content with &lt;code&gt;content-visibility: auto&lt;/code&gt; since it's at the bottom of the page and would theoretically benefit from deferred rendering. But one caveat to the Forem usage was the site's infinite scrolling, where users couldn't reach the footer anyway...so whether that content would be accessible on page load in assistive technology was moot. See the &lt;a href="https://github.com/forem/forem/pull/11560#issuecomment-733223791" rel="noopener noreferrer"&gt;PR&lt;/a&gt; for more discussion if you're curious!&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>html</category>
      <category>chrome</category>
    </item>
  </channel>
</rss>
