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

Linting HTML in Templates and Components

Apply HTML linting to template files in frameworks, handling template syntax, dynamic attributes, and component boundaries.

Linting HTML in Templates and Components

You'll learn how to apply HTML linting to framework template files where HTML mixes with dynamic syntax and component boundaries.

The Challenge of Template-Based HTML

Linting standalone HTML files is straightforward, but modern frameworks like Vue, React (JSX), Angular, and Svelte embed HTML inside templates with special syntax—curly braces, directives, custom components, and dynamic attributes. Standard HTML linters don't understand <MyComponent :prop="value" v-if="show"> or <div className={styles.box}>.

Think of it like trying to proofread a letter written in two languages at once. You need a linter that speaks both HTML and your framework's template language.

Configuring Linters for Template Syntax

Most frameworks provide specialized plugins or parsers:

  • Vue: Use eslint-plugin-vue which understands .vue single-file components
  • React/JSX: ESLint with eslint-plugin-react parses JSX as JavaScript
  • Angular: Angular's CLI includes template linting via @angular-eslint
  • Svelte: eslint-plugin-svelte handles .svelte files

These plugins know to ignore framework-specific syntax (v-for, @click, {#if}) while still validating the underlying HTML structure.

What Gets Checked

Even in templates, linters verify:

  • Valid HTML nesting (no <p> inside <p>)
  • Required attributes (alt on images)
  • Accessibility standards (ARIA roles, label associations)
  • Proper closing tags
  • Component prop naming conventions

They ignore or specially handle:

  • Dynamic attribute bindings
  • Template expressions
  • Component boundaries (custom elements)
  • Framework directives

Configuration Example

In .eslintrc for Vue:

{
  "extends": ["plugin:vue/recommended"],
  "rules": {
    "vue/html-self-closing": "error",
    "vue/max-attributes-per-line": ["error", { "singleline": 3 }]
  }
}

Key Takeaway: Framework-specific ESLint plugins let you lint HTML within templates by understanding both the HTML structure and the framework's special syntax, catching errors while respecting dynamic features and component boundaries.