Skip to content

Conversation

keithamus
Copy link

This adds the :heading and :heading() pseudo classes as specified in https://drafts.csswg.org/selectors-5/#headings, and added in BCD 6.1.1: mdn/browser-compat-data#27517

Refs #3218 which updated BCD to 6.1.1. Perhaps it didn't add these as they're not in a released browser yet?

@github-actions github-actions bot added the feature definition Creating or defining new features or groups of features. label Sep 1, 2025
Copy link
Contributor

@captainbrosset captainbrosset left a comment

Choose a reason for hiding this comment

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

This looks great to me, modulo the suggestion for the name, and missing period at the end of the description.

Copy link
Collaborator

@ddbeck ddbeck left a comment

Choose a reason for hiding this comment

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

Thanks for adding this! I have a question in a line comment about the coverage of this feature and how to describe it.

I also have one general question: do we know anything about how these might be implemented across engines? If it seems very likely that they might land separately (e.g., that a vendor might implement :heading but not :heading(), it might be desirable to create independent features for each pseudo.

Otherwise, as one feature seems fine with me.

@@ -0,0 +1,7 @@
name: Heading pseudo-classes
description: The `:heading` and `:heading()` CSS pseudo-classes match headings of varying levels.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be nice to be more specific here. Something like:

Suggested change
description: The `:heading` and `:heading()` CSS pseudo-classes match headings of varying levels.
description: The `:heading` and `:heading()` CSS pseudo-classes match headings. The `:heading` pseudo-class matches any `<h1>` through `<h6>`. The `:heading()` pseudo matches…

However, I don't really know how to fill in the rest. I read the spec and I read the MDN page (which seem to conflict greatly) and I don't get it. I suspect there's some history here, so giving a clue about what behavior we're talking about is pretty important.

Copy link
Author

Choose a reason for hiding this comment

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

Does this new description work?

@keithamus
Copy link
Author

do we know anything about how these might be implemented across engines?

It is implemented behind a flag in Firefox nightly right now. WebKit are supportive of this and its related feature (WebKit/standards-positions#523). So I am hopeful.

If it seems very likely that they might land separately

I am unsure if it'll land separately, it seems unlikely, however these two features represent the ones found in BCD.

I read the spec and I read the MDN page (which seem to conflict greatly) and I don't get it.

The functional form underwent some minor changes. It used to be specced that you could use An+B notation e.g. :heading(odd), :heading(3n+1) but it was altered to only accept a list of integers now, so :heading(1, 3, 5, 7, 9) and :heading(1, 4, 7) would be the equivalent selectors for those.

Copy link
Collaborator

@ddbeck ddbeck left a comment

Choose a reason for hiding this comment

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

Some extremely minor suggestions on the new description, but I'm happy with this. Thank you, @keithamus!

@@ -0,0 +1,7 @@
name: Heading pseudo-classes
description: The `:heading` and `:heading()` CSS pseudo-classes match headings of varying levels. The `:heading` pseudo-class matches any heading (`<h1>` through `<h6>`). The `:heading(<integer>#)` selector matches any of the given levels, for example `:heading(1, 2)` will match headings level 1 and 2.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Tiny nits on the description (to avoid future tense, to avoid non-literal code, and align the example with other descriptions), but like this a lot. Thank you!

Suggested change
description: The `:heading` and `:heading()` CSS pseudo-classes match headings of varying levels. The `:heading` pseudo-class matches any heading (`<h1>` through `<h6>`). The `:heading(<integer>#)` selector matches any of the given levels, for example `:heading(1, 2)` will match headings level 1 and 2.
description: The `:heading` and `:heading()` CSS pseudo-classes match headings of varying levels. The `:heading` pseudo-class matches any heading (`<h1>` through `<h6>`). The `:heading()` selector matches any of the given levels. For example, `:heading(1, 2)` matches headings level 1 and 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature definition Creating or defining new features or groups of features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants