---
title: "C# HTML parser: DOM, CSS, and accessibility"
url: https://recursiveai.org/onehtml/articles/csharp-html-parser/
description: "Use a C# HTML parser for links and tables, computed CSS for rules like display: none, and an accessibility tree for control names and roles."
date: 2026-11-28
author: OneHtml team
---

# C# HTML parser: DOM, CSS, and accessibility

Use a C# HTML parser for links and tables, computed CSS for rules like display: none, and an accessibility tree for control names and roles.

November 28, 2026 · OneHtml team

OneHtml is a free, open-source .NET 10 HTML parser from Recursive AI, licensed under MIT or Apache-2.0. [NuGet](https://www.nuget.org/packages/RecursiveAI.OneHtml/1.6.0) · [GitHub](https://github.com/recursive-ai-oss/onehtml-csharp/tree/v1.6.0)

*Terminal*

```
dotnet add package RecursiveAI.OneHtml --version 1.6.0
```

In a .NET 10 console project, save this as `page.html` next to `Program.cs`:

*page.html · HTML*

```
<a href="/docs/">Docs</a><a href="/articles/">Articles</a>
```

*Program.cs · .NET 10*

```
using RecursiveAI.OneHtml;
var doc = Document.Parse(File.ReadAllText("page.html"));
foreach (var link in doc.Root.QuerySelectorAll("a[href]"))
    Console.WriteLine(link.GetAttribute("href"));
```

*Output · Console*

```
/docs/
/articles/
```

## Use the DOM for markup and structure

`QuerySelectorAll("a[href]")` finds anchors with an `href` attribute. The output contains their attribute values as written, not resolved URLs. The same kind of query works for `table tr`. A CSS selector used this way matches elements; it does not apply a stylesheet. A parsed HTML tree can also contain elements missing from the source text, such as a `tbody` inserted around rows. See the [table parsing example](https://recursiveai.org/onehtml/cookbook/parse-html-table/) for working with the resulting tree.

Choose a parser that fits your queries and the HTML you receive. [Html Agility Pack](https://html-agility-pack.net/selectors) documents XPath, which may be the deciding factor if you already have a set of XPath queries. If you need browser-style HTML tree construction and CSS selectors, see OneHtml’s [parser and selector documentation](https://recursiveai.org/onehtml/docs/) or the [head-to-head comparison](https://recursiveai.org/onehtml/articles/htmlagilitypack-vs-anglesharp/).

## Compute CSS when the rule, not the tag, decides

In the example below, no `hidden` attribute or inline style marks the Delete button. A stylesheet rule sets its computed `display` to `none`, so the DOM count alone cannot tell you that it is hidden. When styles depend on viewport width or focus, provide that context. OneHtml reads inline and embedded styles, but [does not fetch linked stylesheets](https://github.com/recursive-ai-oss/onehtml-csharp/blob/9c5effd4f753084912f784e2d61c74287b51b94b/docs/cascade.md#style-sources); supply their contents yourself. For an example with a changing viewport, see [computed CSS in C#](https://recursiveai.org/onehtml/cookbook/computed-style-csharp/).

## Use the accessibility tree for roles and names

Add the accessibility package to compare the DOM, computed style, and accessibility tree in one run:

*Terminal*

```
dotnet add package RecursiveAI.OneHtml.Accessibility --version 1.6.0
```

*Program.cs · .NET 10*

```
using RecursiveAI.OneHtml;
using RecursiveAI.OneHtml.Accessibility;
using RecursiveAI.OneHtml.Css;
 
var doc = Document.Parse("""
    <style>.draft { display: none }</style>
    <button aria-label="Save changes">Save</button>
    <button class="draft">Delete</button>
    """);
 
var buttons = doc.Root.QuerySelectorAll("button");
Console.WriteLine($"DOM buttons: {buttons.Count}");
 
var draft = doc.Root.QuerySelector(".draft");
var styles = DocumentStyles.Create(doc);
var display = styles.GetStyle(draft).GetPropertyValue("display");
Console.WriteLine($"Draft display: {display}");
 
var tree = AccessibilityTree.Build(doc, styles);
foreach (var node in tree.Nodes.Where(n => !n.IsIgnored && n.Role == "button"))
    Console.WriteLine($"Accessible button: {node.Name.Value}");
```

*Output · Console*

```
DOM buttons: 2
Draft display: none
Accessible button: Save changes
```

The visible button says “Save,” but its accessible name is “Save changes” because `aria-label` names it. The Delete button is omitted from the accessibility tree because its computed display is `none`. Text extraction or a filter on `aria-hidden` alone would miss those distinctions. Use the [accessibility package](https://www.nuget.org/packages/RecursiveAI.OneHtml.Accessibility/1.6.0) to build an [accessibility tree](https://recursiveai.org/onehtml/articles/accessibility-tree/) for checks such as whether a form control has a name, not as proof that a page is accessible.

## Use a browser when the answer depends on running the page

OneHtml does not execute JavaScript or perform browser layout. If a script adds the buttons after load, get the live DOM from a browser first. If the answer depends on a rendered box or a layout-dependent accessibility role, use browser data under the same viewport and state. OneHtml can accept [rendered facts from a Chrome DOM snapshot](https://github.com/recursive-ai-oss/onehtml-csharp/blob/v1.6.0/docs/accessibility-tree.md#rendered-facts) for layout-dependent accessibility decisions; parsing the response HTML alone cannot supply them.
