Skip to content
Latchkey

How to Check HTML Validity in GitHub Actions

html-validate parses your markup and reports invalid nesting, unclosed elements, and disallowed attributes.

Point html-validate at your built HTML files. It exits non-zero on any error so malformed markup fails CI.

Steps

  • Install html-validate and add an .htmlvalidate.json config.
  • Build the site so the HTML output exists.
  • Run html-validate over the output glob.

Config

.htmlvalidate.json
// .htmlvalidate.json
{
  "extends": ["html-validate:recommended"]
}

Workflow

.github/workflows/ci.yml
jobs:
  html-validity:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: npm ci && npm run build
      - run: npx html-validate 'dist/**/*.html'

Gotchas

  • For framework templates, validate the rendered HTML output, not the raw template files.
  • The Nu Html Checker (vnu) is an alternative when you want the same engine the W3C validator uses.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →