Course contentsShow
← Web Development
Lesson 1447 of 2,98226. Code Quality ToolsFree lesson

HTMLHint: Setup and Configuration

Install and configure HTMLHint, set up .htmlhintrc, and integrate it with your build process to automatically check HTML files.

HTMLHint: Setup and Configuration

You'll learn how to install HTMLHint, configure its rules, and integrate it into your build process to catch HTML errors before they reach production.

What is HTMLHint?

HTMLHint is a static analysis tool that scans your HTML files for common mistakes, accessibility issues, and best practice violations. Think of it as ESLint for HTML—it reads your markup and warns you about problems like unclosed tags, missing alt attributes, or deprecated elements before users encounter broken pages.

Installing HTMLHint

Install HTMLHint as a development dependency in your project:

npm install --save-dev htmlhint

Creating a Configuration File

HTMLHint uses a .htmlhintrc file in your project root to define which rules to enforce:

{
  "tagname-lowercase": true,
  "attr-lowercase": true,
  "attr-value-double-quotes": true,
  "doctype-first": true,
  "tag-pair": true,
  "spec-char-escape": true,
  "id-unique": true,
  "src-not-empty": true,
  "alt-require": true
}

Each rule can be true (error), false (disabled), or configured with specific options.

Running HTMLHint

Check your HTML files manually:

npx htmlhint "src/**/*.html"

Build Process Integration

Add HTMLHint to your package.json scripts to run automatically:

{
  "scripts": {
    "lint:html": "htmlhint \"src/**/*.html\"",
    "build": "npm run lint:html && vite build"
  }
}

Now HTMLHint validates your markup every time you build, preventing bad HTML from shipping to production.

Key Takeaway: HTMLHint automatically catches HTML errors by reading a .htmlhintrc configuration file and running checks during development or build time, just like ESLint does for JavaScript.