# template-indent

Rule `unicorn/template-indent`. Fix whitespace-insensitive template indentation.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +28.3% last quarter
- Rank: #1087 by reach, #1342 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/template-indent` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/template-indent.md) |

## Code examples

### Incorrect: the rule reports this

```js
function foo() {
  const sqlQuery = sql`
select *
from students
where first_name = ${x}
and last_name = ${y}
  `;

  const gqlQuery = gql`
                  query user(id: 5) {
                    firstName
                    lastName
                  }
                `;

  const html = /* HTML */ `
        <div>
            <span>hello</span>
        </div>
  `;
}
```

### Correct: the rule accepts this

```js
function foo() {
  const sqlQuery = sql`
    select *
    from students
    where first_name = ${x}
    and last_name = ${y}
  `;

  const gqlQuery = gql`
    query user(id: 5) {
      firstName
      lastName
    }
  `;

  const html = /* HTML */ `
    <div>
        <span>hello</span>
    </div>
  `;
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/template-indent": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/single-line-block-comment-style](https://lintradar.dev/rules/unicorn/single-line-block-comment-style.md): Enforce a consistent style for single-line block comments.
- [unicorn/require-spread-parentheses](https://lintradar.dev/rules/unicorn/require-spread-parentheses.md): Require parentheses around complex spread arguments.
- [unicorn/prefer-type-literal-last](https://lintradar.dev/rules/unicorn/prefer-type-literal-last.md): Require type literals to be last in union types.
- [unicorn/prefer-then-catch](https://lintradar.dev/rules/unicorn/prefer-then-catch.md): Prefer `.then().catch()` over `.then(…, …)` for error handling.
- [unicorn/prefer-smaller-scope](https://lintradar.dev/rules/unicorn/prefer-smaller-scope.md): Prefer declaring variables and type aliases in the smallest possible scope.
- [unicorn/prefer-single-object-destructuring](https://lintradar.dev/rules/unicorn/prefer-single-object-destructuring.md): Prefer a single object destructuring declaration per local const source.

---

Web page: https://lintradar.dev/rules/unicorn/template-indent. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
