---
title: "onehtml Go cookbook"
url: https://recursiveai.org/onehtml/go/cookbook/
description: "10 onehtml-go recipes, each with complete code."
version: "1.1.1"
---

# onehtml Go cookbook

## HTML and selectors

- [Parse HTML and query CSS selectors in Go](https://recursiveai.org/onehtml/go/cookbook/parse-html-and-query-css-selectors/index.md): Parse an HTML document in Go, select matching elements with a CSS selector, and read their text without launching a browser or running JavaScript.
- [Extract links and link text from HTML in Go](https://recursiveai.org/onehtml/go/cookbook/extract-links-and-anchor-text/index.md): Extract each anchor’s href and link text from HTML in Go, including nested text, and resolve relative hrefs against a base URL when needed.

## CSS styles

- [Get computed CSS styles without a browser in Go](https://recursiveai.org/onehtml/go/cookbook/compute-css-style-without-browser/index.md): Compute an element’s CSS styles in Go from HTML, stylesheets, and viewport settings, without running JavaScript or laying out the page.

## HTML parsing

- [Detect HTML character encoding in Go](https://recursiveai.org/onehtml/go/cookbook/detect-html-character-encoding/index.md): Detect an HTML page’s starting character encoding from its byte order mark, HTTP Content-Type header, or meta charset declaration.
- [Parse an HTML fragment with element context in Go](https://recursiveai.org/onehtml/go/cookbook/parse-html-fragment-in-context/index.md): Parse HTML as the contents of an element in Go. Use a tbody context to read table rows, or derive context from an existing node.

## HTML editing

- [Edit HTML attributes without reformatting in Go](https://recursiveai.org/onehtml/go/cookbook/edit-html-attributes-without-reformatting/index.md): Change an HTML attribute in Go without reformatting your file. Keep untouched bytes, including comments, quotes, and whitespace.

## Computed CSS

- [Read registered CSS custom properties in Go](https://recursiveai.org/onehtml/go/cookbook/register-css-custom-properties/index.md): Read the syntax, initial value, and inheritance flag of CSS @property rules in Go, then see which value a parent and child actually use.
- [Find CSS declarations invalid at computed-value time in Go](https://recursiveai.org/onehtml/go/cookbook/find-invalid-css-computed-declarations/index.md): Report which CSS declarations win the cascade but fail after var() substitution, with the affected element, the original value, and the selector.
- [Resolve CSS ch and ex units in Go](https://recursiveai.org/onehtml/go/cookbook/resolve-css-ch-ex-with-font-metrics/index.md): Supply x-height and zero-glyph advance with onehtml-go’s WithFontMetrics, then read CSS ch and ex lengths in pixels without loading a browser.

## Accessibility

- [Check HTML for WCAG 2.2 AA and export SARIF in Go](https://recursiveai.org/onehtml/go/cookbook/check-wcag-22-aa-and-export-sarif/index.md): Run automated WCAG 2.2 AA checks on an HTML file in Go, then export the failures and items for human review as SARIF for CI.
