Recursive AI

Build an HTML screen-reader reading order in C#

onehtml is a free, open-source HTML library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

Preview HTML as spoken-style steps, not actual screen-reader speech.

Terminal
dotnet add package RecursiveAI.OneHtml.Accessibility

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using RecursiveAI.OneHtml;
using RecursiveAI.OneHtml.Css;
using RecursiveAI.OneHtml.Accessibility;
 
var doc = Document.Parse("""
<main><h1>Account</h1>
<p hidden>Not read</p>
<label for="name">Name</label>
<input id="name" value="Ada"></main>
""");
var styles = DocumentStyles.Create(doc);
var tree = AccessibilityTree.Build(doc, styles);
Console.Write(tree.CreateReadingView().ToText());
Text
main landmark
  heading level 1: Account
  text field: Name, value Ada
end of main landmark

Unzip the example, then dotnet run.

Full program

C#
using RecursiveAI.OneHtml;
using RecursiveAI.OneHtml.Css;
using RecursiveAI.OneHtml.Accessibility;
 
var doc = Document.Parse("""
<main><h1>Account</h1>
<p hidden>Not read</p>
<label for="name">Name</label>
<input id="name" value="Ada"></main>
""");
var styles = DocumentStyles.Create(doc);
var tree = AccessibilityTree.Build(doc, styles);
Console.Write(tree.CreateReadingView().ToText());
var navigation = tree.CreateNavigationLists();
foreach (var heading in navigation.Headings)
    Console.WriteLine($"Heading {heading.Level}: {heading.Name}");
foreach (var landmark in navigation.Landmarks)
    Console.WriteLine($"Landmark: {landmark.Role}");
Text
main landmark
  heading level 1: Account
  text field: Name, value Ada
end of main landmark
Heading 1: Account
Landmark: main

The hidden paragraph is omitted, and the label becomes the input’s accessible name. The full program also prints heading and landmark navigation.

Variations

Headings without a full tree. After doc and styles are created:

C#
var outline = PageOutline.Create(doc, styles);
foreach (var heading in outline.Headings)
    Console.WriteLine($"{heading.Level}: {heading.Name}");
Text
1: Account

Inspect the accessibility tree · Extract text


The short answer

Parse the HTML, compute its styles, build an accessibility tree, then call CreateReadingView(). The result is a sequence of ReadingItem objects rather than a dump of every DOM node. ToText() prints one step per line, with indentation for open containers. Use CreateNavigationLists() on the same tree for headings, landmarks, links, form fields and tables.

This is useful when you need a repeatable reading preview in a C# tool. It is not a recording of speech from an installed screen reader. The reading-view documentation defines the English wording and the tree walk. Keep that distinction when displaying the result to someone reviewing a page.

What is the reading order of a screen reader?

Reading order is the sequence in which someone accesses content. MDN’s reading-order definition describes document source order as the default and explains why a visual layout that diverges from it can create problems.

OneHtml’s reading view walks the accessibility tree depth first in tree order. That generally follows document order, with aria-owns children placed where the tree puts them. It does not sort elements by their screen coordinates. Moving a card visually does not make this output a measurement of the card’s new visual position.

The view contains text steps, announced elements, and container start and end steps. Those distinctions matter: a heading is announced with its level, and a text field is announced with its accessible name and value. Plain text extraction cannot show that structure. Each item also keeps its DOM node and language, so a caller can connect a reading step back to the page.

How do I build a screen-reader reading-order example in C#?

The example above deliberately includes a heading, a hidden paragraph and a labeled control. The hidden paragraph contributes no spoken-style step. The label supplies the input’s name, so the output says “text field: Name, value Ada” rather than treating the label as an unrelated text run.

Adjacent text can merge into one step across silent inline elements such as a span or emphasis. An announced element, a non-inline boundary or a language change ends that run. Names supplied by a label or ARIA stay attached to the relevant control. This makes the sequence useful for checking whether controls appear in a sensible context, not just whether their raw text occurs somewhere.

The heading and landmark lists in the full program are navigation indexes over the same tree. Use them when a UI needs jumps rather than continuous reading. If only those two indexes are needed, the PageOutline variation avoids constructing the full tree. It does not provide the complete reading sequence.

Does CSS order change this reading view?

Treat this output as the documented tree-order model, not a simulation of every browser’s CSS reading-flow behavior. Hidden status and roles affect the tree, while a geometric reordering is not the algorithm used by ReadingView.

The wording is generic English. The nearest declared language is retained on items, but announcements themselves are not translated. Live-region announcements, tooltip speech and virtual-cursor position are outside this view. Review the sequence alongside the rendered page, and use actual assistive technology when the question is how a particular reader behaves. A stable preview can expose a confusing sequence; it cannot establish that the entire page is accessible.

All onehtml recipes