JS.VUE.HTML.QUOTES

Enforce quotes style of HTML attributes

You can choose quotes of HTML attributes from:

  • Double quotes: <div class="foo">
  • Single quotes: <div class='foo'>
  • No quotes: <div class=foo>

This rule enforces the quotes style of HTML attributes.

Rule Details

This rule reports the quotes of attributes if it is different to configured quotes.

{'vue/html-quotes': ['error']}

Copy
<template>
  <!-- GOOD -->
  <img src="./logo.png">

  <!-- BAD -->
  <img src='./logo.png'>
  <img src=./logo.png>
</template>

Options

Default is set to double.

Copy
{
  "vue/html-quotes": [ "error", "double" | "single", { "avoidEscape": false } ]
}

String option:

  • "double" (default) ... requires double quotes.
  • "single" ... requires single quotes.

Object option:

  • avoidEscape ... If true, allows strings to use single-quotes or double-quotes so long as the string contains a quote that would have to be escaped otherwise.

"single"

{'vue/html-quotes': ['error', 'single']}

Copy
<template>
  <!-- GOOD -->
  <img src='./logo.png'>

  <!-- BAD -->
  <img src="./logo.png">
  <img src=./logo.png>
</template>

"double", { "avoidEscape": true }

{'vue/html-quotes': ['error', 'double', { avoidEscape: true }]}

Copy
<template>
  <!-- GOOD -->
  <img title='a string containing "double" quotes'>

  <!-- BAD -->
  <img title='foo'>
  <img title=bar>
</template>

Further Reading

  • Style guide - Quoted attribute values (https://vuejs.org/style-guide/rules-strongly-recommended.html#quoted-attribute-values)

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/