@csstools/postcss-content-alt-text

中文文档
3.0.8发布于 2026/10/30MIT-0TypeScriptES Module近 30 天下载 1324.5万

Generate fallback values for content with alt text

原始使用文档
文档目录4 节
  1. Usage
  2. Options
  3. preserve
  4. stripAltText

PostCSS Content Alt Text PostCSS Logo

npm install @csstools/postcss-content-alt-text --save-dev

PostCSS Content Alt Text generates fallback values for content with alt text following the CSS Generated Content Module.

.foo {
    content: url(tree.jpg) / "A beautiful tree in a dark forest";
}

.bar {
    content: ">" / "";
}

/* becomes */

.foo {
    content: url(tree.jpg)  "A beautiful tree in a dark forest";
    content: url(tree.jpg) / "A beautiful tree in a dark forest";
}

.bar {
    content: ">" ;
    content: ">" / "";
}

Usage

Add PostCSS Content Alt Text to your project:

npm install postcss @csstools/postcss-content-alt-text --save-dev

Use it as a PostCSS plugin:

const postcss = require('postcss');
const postcssContentAltText = require('@csstools/postcss-content-alt-text');

postcss([
    postcssContentAltText(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);

Options

preserve

The preserve option determines whether the original notation is preserved. By default, it is preserved.

postcssContentAltText({ preserve: false })
.foo {
    content: url(tree.jpg) / "A beautiful tree in a dark forest";
}

.bar {
    content: ">" / "";
}

/* becomes */

.foo {
    content: url(tree.jpg)  "A beautiful tree in a dark forest";
}

.bar {
    content: ">" ;
}

stripAltText

The stripAltText option determines whether the alt text is removed from the value.
By default, it is not removed.
Instead it is added to the content value itself to ensure content is accessible.

Only set this to true if you are sure the alt text is not needed.

postcssContentAltText({ stripAltText: true })
.foo {
    content: url(tree.jpg) / "A beautiful tree in a dark forest";
}

.bar {
    content: ">" / "";
}

/* becomes */

.foo {
    content: url(tree.jpg) ;
    content: url(tree.jpg) / "A beautiful tree in a dark forest";
}

.bar {
    content: ">" ;
    content: ">" / "";
}

版本与发布记录

@csstools/postcss-content-alt-text 共发布 19 个版本,首次发布于 2024/07/07;过去 12 个月发布了 9 个版本。

版本发布日期距今
3.0.8latest2026/10/3012 天前
3.0.72026/10/021 个月前
3.0.62026/10/011 个月前
3.0.52026/09/251 个月前
3.0.42026/09/062 个月前
3.0.32026/08/162 个月前

关于 @csstools/postcss-content-alt-text 的常见问题

@csstools/postcss-content-alt-text 是什么?

Generate fallback values for content with alt text

如何安装 @csstools/postcss-content-alt-text?

在项目目录运行 npm install @csstools/postcss-content-alt-text,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:postcss(^8.4)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@csstools/postcss-content-alt-text 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@csstools/postcss-content-alt-text 支持 ESM 还是 CommonJS?

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

@csstools/postcss-content-alt-text 需要什么版本的 Node.js?

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

@csstools/postcss-content-alt-text 可以商用吗?

@csstools/postcss-content-alt-text 使用 MIT-0 许可。声明的许可为 MIT-0,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@csstools/postcss-content-alt-text 的下载量有多少?

根据 npm 官方下载统计,@csstools/postcss-content-alt-text 在 2026/10/11 – 2026/11/09 这 30 天内被下载 13,244,984 次,日均约 441,499 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@csstools/postcss-content-alt-text 还在维护吗?

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