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-validateand add an.htmlvalidate.jsonconfig. - Build the site so the HTML output exists.
- Run
html-validateover 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
How to Validate Open Graph and Meta Tags in GitHub ActionsAssert required Open Graph and meta tags exist in GitHub Actions by parsing built HTML with cheerio, failing…
How to Check for Broken Links With lychee in GitHub ActionsFind broken links in docs and HTML in GitHub Actions with the lychee-action, scanning files for dead URLs and…