大网数据广告活动
Web 标准与前端开发

`prefix` CSS at-rule descriptor

· 52CE 我爱测

The @counter-style rule's **`prefix`** descriptor specifies content that will be added to the beginning of the counter's marker representation.

The @counter-style rule's prefix descriptor specifies content that will be added to the beginning of the counter's marker representation.

When the counter value is negative, the prefix comes before the negative sign and any other <symbol>s added by the @counter-style/negative descriptor.

Syntax

/* <symbol> value: string, image, or identifier */
prefix: "»";
prefix: "Page ";
prefix: url("bullet.png");

Values

The prefix descriptor takes as its value a single <symbol>:

  • <symbol>
    • : Specifies a <symbol> — a <string>, image, or <custom-ident> — that is prepended to the marker representation.

Formal definition

Formal syntax

Examples

Adding a prefix to a counter

In this example, each counter number is prefixed by "Book " (with a space) and followed by a colon (:). The colon is added with the @counter-style/suffix descriptor.

HTML

<ol class="books">
  <li>Flamer, by Mike Curato</li>
  <li>Gender Queer: A Memoir, by Maia Kobabe</li>
  <li>Tricks, by Ellen Hopkins</li>
  <li>The Handmaid's Tale: The Graphic Novel, by Margaret Atwood</li>
  <li>Crank, by Ellen Hopkins</li>
</ol>

CSS

@counter-style books {
  system: numeric;
  symbols: "0" "1" "2" "3" "4" "5" "6" "7" "8" "9";
  prefix: "Book ";
  suffix: ": ";
}

.books {
  list-style: books;
  padding-left: 15ch;
}

Result

Adding_a_prefix_to_a_counter

Specifications

Browser compatibility

See also

  • Other @counter-style descriptors: @counter-style/system, @counter-style/symbols, @counter-style/additive-symbols, @counter-style/negative, @counter-style/suffix, @counter-style/range, @counter-style/pad, @counter-style/speak-as, and @counter-style/fallback
  • list-style, list-style-image, list-style-position
  • symbols(): the functional notation for creating anonymous counter styles
  • CSS counter styles module
  • CSS lists and counters module

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。