Skip to content

Conversation

@chrisdavidmills
Copy link
Contributor

Description

Chrome 140 adds support for counter() and counters() functions in content property alt text. See https://chromestatus.com/feature/5185442420621312. Note that the initial implementation was buggy; it is fixed now, but this functionality only really works in Canary at the moment. See the associated BCD for further details: mdn/browser-compat-data#28763.

This PR adds a bit more information and an example to the content property page, showing how to use counters in content alt text.

I also took this opportunity to mention the fact that you can also use attr() functions in content alt text. I tested it, and it seems to work, but I didn't want to go much deeper on that, as it is not the central purpose of this PR.

Motivation

Additional details

Related issues and pull requests

@chrisdavidmills chrisdavidmills requested a review from a team as a code owner January 6, 2026 13:21
@chrisdavidmills chrisdavidmills requested review from estelle and removed request for a team January 6, 2026 13:21
@github-actions github-actions bot added Content:CSS Cascading Style Sheets docs size/m [PR only] 51-500 LoC changed labels Jan 6, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

Preview URLs

Flaws (176)

URL: /en-US/docs/Web/CSS/Reference/Properties/content
Title: content
Flaw count: 176

  • broken_links:
    • Link /en-US/docs/Web/CSS/CSS_values_and_units/Value_definition_syntax#single_bar is a redirect
    • Link /en-US/docs/Web/CSS/CSS_values_and_units/Value_definition_syntax#single_bar is a redirect
    • Link /en-US/docs/Web/CSS/CSS_values_and_units/Value_definition_syntax#brackets is a redirect
    • Link /en-US/docs/Web/CSS/CSS_values_and_units/Value_definition_syntax#single_bar is a redirect
    • Link /en-US/docs/Web/CSS/CSS_values_and_units/Value_definition_syntax#brackets is a redirect
    • and 163 more flaws omitted
  • macros:
    • Macro cssxref produces link /en-US/docs/Web/CSS/counter-reset which is a redirect
    • Macro cssxref produces link /en-US/docs/Web/CSS/counter-increment which is a redirect
    • Macro cssxref produces link /en-US/docs/Web/CSS/list-style-type which is a redirect
    • Macro cssxref produces link /en-US/docs/Web/CSS/list-style-type which is a redirect
    • Macro cssinfo produces link /en-US/docs/Web/CSS/CSS_cascade/Value_processing which is a redirect
    • and 3 more flaws omitted

(comment last updated: 2026-01-08 12:16:02)

@chrisdavidmills chrisdavidmills changed the title Add information and example for counters in generated content alt text Technical review: Add information and example for counters in generated content alt text Jan 6, 2026
@danielsakhapov
Copy link

LGTM! Thanks for adding this!

@chrisdavidmills chrisdavidmills changed the title Technical review: Add information and example for counters in generated content alt text Editorial review: Add information and example for counters in generated content alt text Jan 7, 2026
Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many screen reader aren't blind. The screen reader should be reading content that is on the page. Empty strings don't need descriptive text, but you would need alt text if the counter were using symbols, such as multiple stars, or a deck of cards, or binary. So we can either use an image that reads "chapter" then provide "chapter" as the alt, or we can use a symbolic counter that needs alt text. https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@counter-style#examples .

I created a counter with a deck of cards once. I've been looking for it to share with you, but haven't found it yet. So submitting, and will ping you if i locate it.

Comment on lines 383 to 390
```css live-sample___alt-counter
li::marker {
content: counter(chapter) ": ";
}

a::before {
content: "" / "Chapter " counter(chapter);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the alt should be alt to actual content, not an empty string. The screenreader user may be sited, so should be hearing what sighted users see. I suggest getting rid of the marker (list-style: none;) then doing something like:

a::before {
  content: url(chapter.png) counter(chapter) / "Chapter " counter(chapter);
}

so the alt is the alt for an image.
if you don't want to create an image, you can use characters like in https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@counter-style#examples or star rating like symbols https://codepen.io/estelle/pen/YzddjJb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good points here. I've figured out an update to the example that uses a book emoji to represent "Chapter". I'll make the updates and push them so you can have a look.

Copy link
Member

@estelle estelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one edit, but looks good and I don't need to re-review.

Edit: let's only merge this when the fix gets merged.

@chrisdavidmills chrisdavidmills merged commit f7f6f16 into mdn:main Jan 8, 2026
7 checks passed
@chrisdavidmills chrisdavidmills deleted the counters-in-content-alt-text branch January 8, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:CSS Cascading Style Sheets docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants