---
title: "Build an HTML screen-reader reading order in C#"
url: https://recursiveai.org/onehtml/cookbook/build-screen-reader-reading-order/
description: "Preview HTML as spoken-style steps, not actual screen-reader speech."
version: "1.6.0"
---

# 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.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneHtml.Accessibility) · [GitHub](https://github.com/recursive-ai-oss/onehtml-csharp) · [Docs](https://recursiveai.org/onehtml/docs/) · [Download example (.zip)](https://recursiveai.org/onehtml/cookbook/build-screen-reader-reading-order/build-screen-reader-reading-order.zip)

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

```shell
dotnet add package RecursiveAI.OneHtml.Accessibility
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
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](https://recursiveai.org/onehtml/cookbook/build-screen-reader-reading-order/build-screen-reader-reading-order.zip), then `dotnet run`.

## Full program

```csharp
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:

```csharp
var outline = PageOutline.Create(doc, styles);
foreach (var heading in outline.Headings)
    Console.WriteLine($"{heading.Level}: {heading.Name}");
```

```text
1: Account
```

## Related recipes

[Inspect the accessibility tree](https://recursiveai.org/onehtml/cookbook/accessibility-tree/) · [Extract text](https://recursiveai.org/onehtml/cookbook/extract-visible-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](https://recursiveai.org/onehtml/docs/reading-view/) 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](https://developer.mozilla.org/en-US/docs/Glossary/Reading_order) 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.
