---
title: "Check HTML for WCAG 2.2 AA and export SARIF in Go"
url: https://recursiveai.org/onehtml/go/cookbook/check-wcag-22-aa-and-export-sarif/
description: "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."
version: "1.1.1"
---

# Check HTML for WCAG 2.2 AA and export SARIF in Go

**onehtml-go** is a free, open-source HTML parser for Go from Recursive AI, with CSS selectors, computed styles, lossless editing and accessibility checks. MIT or Apache-2.0, no dependencies.

[pkg.go.dev](https://pkg.go.dev/recursiveai.org/go/onehtml) · [GitHub](https://github.com/recursive-ai-oss/onehtml-go) · [Docs](https://recursiveai.org/onehtml/go/docs/) · [Download example (.zip)](https://recursiveai.org/onehtml/go/cookbook/check-wcag-22-aa-and-export-sarif/check-wcag-22-aa-and-export-sarif.zip)

Use the WCAG 2.2 AA profile and `WriteSARIF` to report findings in CI. A scan can’t prove conformance. SARIF is a JSON format for analysis results that tools like [GitHub code scanning](https://docs.github.com/en/code-security/concepts/code-scanning/sarif-files) can display.

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

Requires Go 1.24 or later.

```go
package main

import (
	"fmt"
	"os"

	"recursiveai.org/go/onehtml"
	v "recursiveai.org/go/onehtml/accessibility/validation"
)

func main() {
	src, err := os.ReadFile("page.html")
	if err != nil {
		panic(err)
	}
	doc, err := onehtml.ParseBytes(src)
	if err != nil {
		panic(err)
	}
	profile := v.WithProfile(v.ProfileWCAG22AA)
	report, err := v.Check(doc, profile)
	if err != nil {
		panic(err)
	}
	file, err := os.Create("accessibility.sarif")
	if err != nil {
		panic(err)
	}
	err = report.WriteSARIF(file,
		v.WithExportURL("page.html"))
	closeErr := file.Close()
	if err != nil {
		panic(err)
	}
	if closeErr != nil {
		panic(closeErr)
	}
	for result := range report.WithOutcome(v.Failed) {
		fmt.Println(result.RuleID)
	}
	fmt.Println("Wrote accessibility.sarif")
}
```

If `page.html` is missing, the file read fails before any SARIF is written. The program prints confirmed failures; open `accessibility.sarif` for locations and review items too.

Paste the code above into main.go, run `go mod init example` and `go get recursiveai.org/go/onehtml`, then `go run .`; or unzip [the example](https://recursiveai.org/onehtml/go/cookbook/check-wcag-22-aa-and-export-sarif/check-wcag-22-aa-and-export-sarif.zip) and `go run .`.

Save this input as `page.html` next to `main.go` if you’re pasting the code. It’s already in the zip.

```html
<!doctype html>
<html lang="en">
<title>Shop</title>
<main>
  <h1>Shop</h1>
  <button></button>
</main>
</html>
```

`go run .` prints:

```text
button-name
Wrote accessibility.sarif
```

## Variations

To fail CI on a confirmed accessibility issue, add this at the end of `main`, after the report is closed. The sample exits with status 1 after printing `button-name button`. `result.Target.Name()` gives the element name, `button`.

```go
for result := range report.WithOutcome(v.Failed) {
    fmt.Println(result.RuleID, result.Target.Name())
    os.Exit(1)
}
```

## Related recipes

- [Edit HTML attributes without reformatting in Go](https://recursiveai.org/onehtml/go/cookbook/edit-html-attributes-without-reformatting/)
- [Get computed CSS styles without a browser in Go](https://recursiveai.org/onehtml/go/cookbook/compute-css-style-without-browser/)

## The short answer

Parse the HTML, call `validation.Check` with `validation.WithProfile(validation.ProfileWCAG22AA)`, and pass a file to `report.WriteSARIF`. Upload that file to a SARIF-capable CI viewer or save it as a build artifact. Treat confirmed failures and items that need human review separately.

## How do I check a website for WCAG?

Run the checker on the HTML your build actually serves, not just the template that produces it. Template expansion may decide whether a button gets a name or whether a page gets a title. This example reads the generated input from disk, so it checks exactly the bytes in `page.html`. The [WCAG 2.2 standard](https://www.w3.org/TR/WCAG22/#cc2) defines Level AA in terms of all applicable Level A and AA criteria. The profile picks relevant library rules; it does not turn that rule set into exhaustive coverage of the standard.

For example, the checker can report that the sample’s button has no accessible name. It also marks whether the title is descriptive as a review item: seeing the word “Shop” in a title does not establish that it adequately describes the page. To cover the rest of the experience, use [W3C’s evaluation guidance](https://www.w3.org/WAI/test-evaluate/) and test the rendered page, including keyboard use and the states users encounter after interacting with it. onehtml-go does not run scripts or render the page.

## How do I report accessibility failures in CI with SARIF?

Use the checked file’s path as the artifact URI. `WithExportURL("page.html")` labels the result with that path; for a real build, use a path your viewer can resolve. This report marks `button-name` as `kind: fail` and points to `page.html`, line 6, column 3. It also contains `kind: review` items at `level: none`, so a panel that only shows errors can miss work you still need someone to review. Passed and inapplicable items are omitted by default.

Writing the file and enforcing your CI policy are separate steps. Write and close the file first, then use `report.WithOutcome(validation.Failed)` to decide the job’s exit status, as in the variation. Configure the artifact step to run even after a failed check, so the report is available when the build that produced it goes red. If you review ambiguous cases manually, do not silently treat the absence of `Failed` outcomes as a clean accessibility evaluation.
