
Validate your SSR/SSG HTML automatically to catch hydration and accessibility issues before they ship.
Key features
- Zero-configuration required
- Helps reduce hydration errors
- Detects common accessibility mistakes
This module configures html-validate to automatically validate Nuxt server-rendered HTML (SSR and SSG) to detect common issues with HTML that can lead to hydration errors, as well as improve accessibility and best practice.
Quick start
Install
Terminal
npx nuxi@latest module add html-validator
Configure Nuxt
defineNuxtConfig({
modules: ['@nuxtjs/html-validator']
})
export default {
buildModules: ['@nuxtjs/html-validator']
}
export default {
// Install @nuxtjs/html-validator as a dependency instead of devDependency
modules: ['@nuxtjs/html-validator']
}
html-validator won't be added to your production bundle — it's only used in development and at build/generate time.Configuration
@nuxtjs/html-validator exposes four options:
usePrettierenables prettier printing of your source code to show errors in-context.
Consider not enabling this if you are using TailwindCSS, as prettier will struggle to cope with parsing the size of your HTML in development mode.
logLevelsets the verbosity to one ofverbose,warningorerror. It defaults toverbosein dev, andwarningwhen generating.
Use this option to turn off console logging for the
No HTML validation errors found for ... message.failOnErrorwill throw an error after runningnuxt generateif there are any validation errors with the generated pages.
Useful in continuous integration.
optionsallows you to pass inhtml-validateoptions that will be merged with the default configuration.
You can find more about configuring
html-validatehere.Defaults
nuxt.config.ts
{
htmlValidator: {
usePrettier: false,
logLevel: 'verbose',
failOnError: false,
/** A list of routes to ignore (that is, not check validity for). */
ignore: [/\\.(xml|rss|json)$/],
options: {
extends: [
'html-validate:document',
'html-validate:recommended',
'html-validate:standard'
],
rules: {
'svg-focusable': 'off',
'no-unknown-elements': 'error',
// Conflicts or not needed as we use prettier formatting
'void-style': 'off',
'no-trailing-whitespace': 'off',
// Conflict with Nuxt defaults
'require-sri': 'off',
'attribute-boolean-style': 'off',
'doctype-style': 'off',
// Unreasonable rule
'no-inline-style': 'off'
}
}
}
}
You're good to go!
Every time you hard-refresh (server-render) a page in Nuxt, you will see any HTML validation issues printed in your server console.
