Skip to content

Add a resetLonghands field to CSS shorthand properties#1872

Open
tidoust wants to merge 1 commit intomainfrom
reset-longhands
Open

Add a resetLonghands field to CSS shorthand properties#1872
tidoust wants to merge 1 commit intomainfrom
reset-longhands

Conversation

@tidoust
Copy link
Member

@tidoust tidoust commented Mar 11, 2026

Via #1851. Some shorthand properties may also reset a number of properties that they don't set. These properties are known as "reset-only sub-properties": https://drafts.csswg.org/css-cascade-5/#reset-only-sub-property

This update adds a resetLonghands field in CSS extracts to shorthands that have reset-only sub-properties, leveraging the list maintained by @cdoublev in:
https://github.com/cdoublev/css/blob/master/lib/properties/shorthands.js

Affected properties:

  • animation (and the legacy -webkit-animation)
  • background
  • border
  • font
  • mask (and the legacy -webkit-mask)

The list needs to be maintained manually, I'm afraid. I don't see any good way to extract the list of reset-only sub-properties automatically for now.

Note: I haven't listed animation-composition as a reset-only sub-property for animation yet, pending clarity on its inclusion, see #1851 (comment). To be determined before this PR is merged!

Via #1851. Some shorthand properties may also reset a number of properties that
they don't set. These properties are known as "reset-only sub-properties":
https://drafts.csswg.org/css-cascade-5/#reset-only-sub-property

This update adds a `resetLonghands` field in CSS extracts to shorthands that
have reset-only sub-properties, leveraging the list maintained by @cdoublev
in:
https://github.com/cdoublev/css/blob/master/lib/properties/shorthands.js

Affected properties:
- `animation` (and the legacy `-webkit-animation`)
- `background`
- `border`
- `font`
- `mask` (and the legacy `-webkit-mask`)

The list needs to be maintained manually, I'm afraid. I don't see any good way
to extract the list of reset-only sub-properties automatically for now.
@tidoust tidoust requested a review from dontcallmedom March 11, 2026 18:33
Copy link
Member

@dontcallmedom dontcallmedom left a comment

Choose a reason for hiding this comment

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

LGTM, with a potential improvement (likely for a separate PR)


const resetLonghands = getResetLonghands(prop, allProperties, propertiesByName);
if (resetLonghands && resetLonghands.length > 0) {
const validResetLonghands = resetLonghands.filter(lh => allProperties.has(lh));
Copy link
Member

Choose a reason for hiding this comment

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

this apply to the existing code, but shouldn't we fail or at least log an error of some sort if not all resetLonghands are valid?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I aligned with the approach that exists for building the longhands field itself for consistency, but I agree that we should fail in both cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants