---
title: "onehtml"
url: https://recursiveai.org/onehtml/go/docs/overview/
description: "The module README: what onehtml for Go does, how to install it, the quick start and its packages."
version: "1.1.1"
source: https://github.com/recursive-ai-oss/onehtml-go/blob/b6b36a3de36130cf715d83198af600c71d30c3f2/README.md
---

# onehtml

**A pure-Go HTML and CSS library that parses HTML exactly as a browser does, matches Selectors Level 4, computes the CSS cascade, edits a page without disturbing a byte the edit didn't touch, and builds the accessibility tree a browser gives screen readers.** It also checks pages against every WCAG level, from the standard library alone.

## Why onehtml

- **Browser-exact parsing.** The WHATWG tokenizer and tree builder in full, fragments and parse errors included, with the Encoding Standard's detection and decoders. Every node and attribute knows its byte range in the original input.
- **Selectors and cascade.** Selectors Level 4 compiled once and matched without recursion; origins, layers, `@scope`, nesting, `@media`, `var()` and `calc()`, with computed values serialized as `getComputedStyle` gives them. No layout, no painting.
- **Lossless editing.** `Rewrite` splices edits into the original bytes and verifies the result by parsing it again; with no edits the output is byte-identical to the input.
- **Accessibility.** The accessibility tree (WAI-ARIA 1.2, HTML-AAM, Accessible Name and Description 1.2), a reading view and navigation lists, and a checker for WCAG 2.0, 2.1 and 2.2 with suggested fixes and JSON, axe-compatible JSON, SARIF and EARL exports.
- **Safe on hostile input.** No panic and no hang on any bytes; limits are checked before the work they guard, and nothing recurses on input depth.
- **Never fetches, never executes.** The library opens no files and makes no network requests; linked stylesheets come from the caller and scripts are inert text. Standard library only, no cgo, no `unsafe`.

## Install

```
go get recursiveai.org/go/onehtml
```

Go 1.24 or newer.

## Quick start

```go
doc, err := onehtml.Parse(strings.NewReader(`<style>a { color: green }</style>
<nav><a href="https://example.com/">Home</a></nav>`))
if err != nil {
	log.Fatal(err)
}
links, err := doc.Select("nav a[href^='https://']")
if err != nil {
	log.Fatal(err)
}
styles := doc.Style()
for _, a := range links {
	href, _ := a.Get("href")
	fmt.Println(a.TextContent(), href, styles.ComputedStyle(a).Get("color"))
}

res := onehtml.Rewrite(doc, []onehtml.Edit{onehtml.SetAttribute(links[0], "rel", "noopener")})
if !res.Applied() {
	log.Fatal(res.Reasons)
}
fmt.Println(string(res.Document)) // the original bytes, changed only at the edit
```

The same example runs as `Example_quickStart` in the package documentation.

## Where to go

- [`onehtml`](https://pkg.go.dev/recursiveai.org/go/onehtml): parser, DOM, selectors, cascade and editing, with an `Example` for each.
- [`onehtml/accessibility`](https://pkg.go.dev/recursiveai.org/go/onehtml/accessibility): `accessibility.Tree(doc)`, the reading view and navigation lists.
- [`onehtml/accessibility/aria`](https://pkg.go.dev/recursiveai.org/go/onehtml/accessibility/aria): the WAI-ARIA roles, states and properties with their characteristics.
- [`onehtml/accessibility/validation`](https://pkg.go.dev/recursiveai.org/go/onehtml/accessibility/validation): `validation.Check(doc)`, profiles, rules and exports.
- [Conformance](https://recursiveai.org/onehtml/go/docs/conformance/): results against the onehtml conformance kit.
- [Performance](https://recursiveai.org/onehtml/go/docs/performance/): parse and select against x/net/html and cascadia, and floors for the rest.
- [Changelog](https://recursiveai.org/onehtml/go/docs/changelog/) and [security policy](https://github.com/recursive-ai-oss/onehtml-go/blob/b6b36a3de36130cf715d83198af600c71d30c3f2/SECURITY.md).

## Licence

Licensed under either of MIT or Apache-2.0 at your option (`LICENSE-MIT`, `LICENSE-APACHE`). Third-party data is listed in `THIRD-PARTY-NOTICES.md`. Copyright Recursive AI, LLC.
