@awmottaz/prettier-plugin-void-html

中文文档
2.3.0发布于 2026/09/11MITES Module零依赖近 30 天下载 5070

Prettier plugin to print void HTML elements without self-closing syntax

原始使用文档
文档目录8 节
  1. Notice of project status
  2. Package summary
  3. Installation
  4. What this plugin does
  5. Compatibility
  6. Prettier
  7. Languages
  8. Void elements

prettier-plugin-void-html

Notice of project status

Updated on 10 Sep, 2026

I am softening the "maintenance mode" status of this project that I have had in place for a while. To be clear, I am not suddenly going to spend a bunch more time on this project. Rather, I would like to affectionately dub this plugin "feature complete".

The goals of this plugin are modest: augment the Prettier formatter so that "self-closing" tag syntax (/>) is never emitted in HTML code. If the affected tag is a void element, then this will remove the slash character. If the affected element is not a void element, then its closing tag is inserted. [^1]

[^1]: I have seen some arguments that it should not behave this way since this changes the semantics of the document. I am considering adding a config option for this. If you're interested in this, please create a new issue to let me know.

To that end, this plugin is functionally complete. I will not add support for other HTML-like languages (Vue has been a common request), nor will I add new features (with the one caveat noted in the footnote). You are welcome to fork this project to add those things if you wish.

All that remains for this project is to keep fixing bugs and support new versions of Prettier as they're released. I intend to do so indefinitely.

Contrary to what I have previously said, I will not offer to transfer ownership of this repository to anyone. I will retain ownership [^2], and I will do my best to support it as my availability and energy allows.

[^2]: I am, however, considering a migration away from GitHub as my values no longer align with the direction this platform seems to be moving.

I have been lucky to receive some high-quality contributions from strangers, whether that's giving detailed bug reports, fixing those bugs, or adding test coverage when new versions of Prettier are released. I am very thankful to those people! And please, keep them coming. This is what open source is all about, and your contributions help the thousands of projects (🤯) that download this plugin each month. Again, thank you.

— 🫶 Tony

Package summary

This is a Prettier plugin to format void HTML elements using the void tag syntax instead of self-closing syntax. Additionally, if self-closing syntax is used on non-void elements, then they will be "unwrapped" so that both the opening and closing tags are present.

Installation

This package is hosted on NPM. Install with your package manager of choice. NPMX seems to provide instructions for a lot of them.

This package is usually installed as a dev dependency. It assumes a Node.js runtime, and as a plugin for Prettier it assumes that you have a supported version of prettier already installed.

npm install -D @awmottaz/prettier-plugin-void-html

Next, add the plugin to your Prettier config file.

{
  "plugins": ["@awmottaz/prettier-plugin-void-html"]
}

What this plugin does

With the plugin installed and active, Prettier will format your HTML source code with the following augmentations to Prettier's default formatting:

  • Void elements are printed using a plain > symbol to close the tag
  • Non-void elements, if authored with a self-closing tag />, will be "unwrapped" so that the closing tag is explicitly included.
<!-- original source -->
<meta charset="UTF-8">
<label for="my-input">Type something</label>
<input id="my-input" type="text" name="my-input">
<div />

<!-- Prettier's default formatting without this plugin -->
<meta charset="UTF-8" />
<label for="my-input">Type something</label>
<input id="my-input" type="text" name="my-input" />
<div />

<!-- Prettier's formatting with this plugin -->
<meta charset="UTF-8">
<label for="my-input">Type something</label>
<input id="my-input" type="text" name="my-input">
<div></div>

Compatibility

Prettier

This package is tested against all versions of Prettier starting with v3.0.0 and up to the latest version at the time of publishing. See test.js for the exact versions that are tested and CHANGELOG.md for support by plugin version.

Note that the peerDependencies of this package allow installing newer patch versions of Prettier that may not be included in this list. This is for pragmatic reasons so that you can upgrade patched releases of Prettier without waiting for this package to update.

However, please note this disclaimer from the Prettier installation page:

Install an exact version of Prettier locally in your project. This makes sure that everyone in the project gets the exact same version of Prettier. Even a patch release of Prettier can result in slightly different formatting, so you wouldn’t want different team members using different versions and formatting each other’s changes back and forth.

If you wish to use a version of Prettier that is not supported by this package, then you will need to add an overrides rule. For example, to use an older version of Prettier:

{
  "overrides": {
    "@awmottaz/prettier-plugin-void-html": {
      "prettier": ">=2.8.8"
    }
  }
}

If you do this, please consider contributing to prettier-plugin-void-html by adding tests for that version or opening an issue. I am happy to expand support, but I also need to be pragmatic of my time.

Languages

This plugin supports the HTML language, only (the "html" parser).

Support for other languages such as Svelte or Vue requires using an entirely different parser and is outside the scope of this plugin.

If you want the features provided by this package in another language, I recommend submitting feedback to the other projects that handle formatting those languages.

Void elements

https://developer.mozilla.org/en-US/docs/Glossary/Void_element

The following elements are recognized by this plugin as void elements:

  • area
  • base
  • br
  • col
  • embed
  • hr
  • img
  • input
  • link
  • meta
  • param
  • source
  • track
  • wbr

版本与发布记录

@awmottaz/prettier-plugin-void-html 共发布 19 个版本,首次发布于 2023/09/23;过去 12 个月发布了 6 个版本。

版本发布日期距今
2.3.0latest2026/09/111 个月前
2.2.12026/08/013 个月前
2.2.02026/07/293 个月前
2.1.02026/03/058 个月前
2.0.02025/12/0611 个月前
1.10.02025/12/0311 个月前

关于 @awmottaz/prettier-plugin-void-html 的常见问题

@awmottaz/prettier-plugin-void-html 是什么?

Prettier plugin to print void HTML elements without self-closing syntax

如何安装 @awmottaz/prettier-plugin-void-html?

在项目目录运行 npm install @awmottaz/prettier-plugin-void-html,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:prettier(3.0.0 - 3.9.x)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@awmottaz/prettier-plugin-void-html 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/awmottaz__prettier-plugin-void-html 是否存在。

@awmottaz/prettier-plugin-void-html 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@awmottaz/prettier-plugin-void-html 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js 22 || 24 || 26。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@awmottaz/prettier-plugin-void-html 可以商用吗?

@awmottaz/prettier-plugin-void-html 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@awmottaz/prettier-plugin-void-html 的下载量有多少?

根据 npm 官方下载统计,@awmottaz/prettier-plugin-void-html 在 2026/10/07 – 2026/11/05 这 30 天内被下载 5,070 次,日均约 169 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@awmottaz/prettier-plugin-void-html 还在维护吗?

最新版本 2.3.0 发布于 2026/09/11(1 个月前);至今共发布 19 个版本,其中过去 12 个月发布了 6 个;首次发布于 2023/09/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。