Skip to content

[css-values-5] Add number() to coerce string values to numbers #12145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dead-claudia opened this issue May 2, 2025 · 3 comments
Open

[css-values-5] Add number() to coerce string values to numbers #12145

dead-claudia opened this issue May 2, 2025 · 3 comments

Comments

@dead-claudia
Copy link

dead-claudia commented May 2, 2025

There's ident() for identifiers, and #12072 got me thinking it'd pair exceptionally well with counter(), like number(counter(name)).

Concretely, this could also be useful for ordering in some advanced use cases as well.

@dead-claudia
Copy link
Author

Note: while alternative bases may be worth exploring, I'm specifically not proposing that at this stage.

Browsers can optimize number(counter(...)), by the way. It's as simple as just not stringifying the counter.

@tabatkins
Copy link
Member

Are there use-cases for this other than counters? If not, avoiding the second call and just introducing counter-value(), as has been suggested in the past, is probably the right way to go.

(attr() already lets you parse directly into a number, so that's not a use.)

@dead-claudia
Copy link
Author

Are there use-cases for this other than counters? If not, avoiding the second call and just introducing counter-value(), as has been suggested in the past, is probably the right way to go.

(attr() already lets you parse directly into a number, so that's not a use.)

There's no way to grab the content of an element as a number, either: https://drafts.csswg.org/css-content/#content-function. There may be others I'm also missing, as I haven't pored over all the specs in full.

If all of those gained ways to retrieve the same values as numbers with units, then that can replace this proposal.

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

No branches or pull requests

3 participants