OneHtml is a free, open-source .NET 10 HTML parser from Recursive AI, licensed under MIT or Apache-2.0. NuGet · GitHub
dotnet add package RecursiveAI.OneHtml --version 1.6.0In a .NET 10 console project, save this as page.html next to Program.cs:
<a href="/docs/">Docs</a><a href="/articles/">Articles</a>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"));
/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 for working with the resulting tree.
Choose a parser that fits your queries and the HTML you receive. Html Agility Pack 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 or the head-to-head comparison.
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; supply their contents yourself. For an example with a changing viewport, see computed CSS in C#.
Use the accessibility tree for roles and names
Add the accessibility package to compare the DOM, computed style, and accessibility tree in one run:
dotnet add package RecursiveAI.OneHtml.Accessibility --version 1.6.0using 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}");
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 to build an 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 for layout-dependent accessibility decisions; parsing the response HTML alone cannot supply them.