-
Notifications
You must be signed in to change notification settings - Fork 27
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
[css-values-5] attr()
support extended capabilities
#521
Comments
I like to use |
Here's another use case: images with a spaced out gradient The markup for an image would be just
Then in the CSS, this would do the trick for the image with the spaced out "gradient" (actually very blurred) border:
No browser currently supports this and it's not just because of The current cross-browser solution feels needlessly complicated. First, when I generate the HTML, add a
Then in the CSS, I need all of this:
And this doesn't even include the
I'm intrigued! This looks very good in theory and I'd love to be able to use something like this for inputs! For example, for But one thing that confuses me is that I don't see the If |
@thebabydino Solid feedback all around. Examples like that greatly help to express this feature like this. Thank you!! Re the
I would certainly appreciate any support you'd show to either of those proposals as well. Thank you 🙂 |
In addition I would add, inline styles aren't very good for security and CSP perspective. |
This was my first thought, too. Range is a pain to style, currently: https://codepen.io/webstrand/pen/bGLXdPR
Traditionally, I'm not sure I'd be a fan of adding special cases for |
@webstrand I agree; I don't think we should introduce any special cases using If you're interested, take a peek at the other two proposals I mentioned, namely this one: [css-values-5]
|
Another concrete example, an icon component that should be sized in
|
@jacobrask Great example. I've done something similar for custom progress bars: <div class="progress-wrapper">
<progress min=0 max=100 value=75></progress>
</div> progress[min][max][value] {
.progress-wrapper:has(&) {
--percentage: calc((var(--value) - var(--min)) / (var(--max) - var(--min)) * 100%);
height: 100vh;
width: 100vw;
background: linear-gradient(to right, red var(--percentage), white var(--percentage));
}
.progress-wrapper:has(&) & {
display: none;
}
/* min */
.progress-wrapper:has(&[min="0"]) { --min: 0; } /* ... */
.progress-wrapper:has(&[min="100"]) { --min: 100; }
/* max */
.progress-wrapper:has(&[max="0"]) { --max: 0; } /* ... */
.progress-wrapper:has(&[max="100"]) { --max: 100; }
/* value */
.progress-wrapper:has(&[value="0"]) { --value: 0; } /* ... */
.progress-wrapper:has(&[value="100"]) { --value: 100; }
} |
attr()
support extended capabilitiesattr()
support extended capabilities
Thank you for proposing We wanted to let you know that this proposal was not selected to be part of Interop this year. As of the deadline, the specifications for For an overview of our process, see proposal selection. Thank you again for contributing to Interop 2024! Posted on behalf of the Interop team. |
@bkardell What features from the official specification are not complete enough to move forward with this feature? The spec is complete and has been for years. This feature has been suggested for the past few consecutive years via interop and otherwise. More notably, this issue garnered more attention and praise and engagement than any other interop issue proposed, which I believe should be weighed heavily when considering proposed features for interop. One of the primary functions of proposing issues for interop is to give the community the ability to vote on which issues they desire to see implemented in the web platform most. The results clearly show that this is a top priority if not THE top priority. |
@brandonmcconnell you're right that there's a lot of developer demand for this, that is very clear. The issue with the spec isn't really that it's "not yet complete enough to allow interoperable implementations", but that there are security issues that at least the Chrome team believes are serious enough to need solving before shipping. That is the topic of w3c/csswg-drafts#5092, and we now have a sketch of a solution that might work. I am going to follow up on that work so that the security issues can be resolved. (I did take a look while we were evaluating proposals too, but there just wasn't enough time to fix it there and then.) |
@foolip (cc @tabatkins) Given the recent progress and resolutions in w3c/csswg-drafts#5092, and the exceeding demand on this interop proposal the past two consecutive years (#86 & #521), could we reconsider including it in this year's interop effort, as the blocker is now removed? |
We can't, as part of Interop 2024. Interop choices and tests are carefully chosen so that we have measurable goals that don't significantly change during the year... But don't be too disheartened by that answer: It doesn't mean teams can't all prioritize it independently -- in my opinion, another benefit of the Interop project is just that it gets us collectively thinking/talking about priorities... So, it's totally possible if the situation regarding specs is resolved, that it might get interoperable support in the same year without actually being a part of the Interop project. |
@bkardell Thanks, that's understandable 🙂 |
Description
The attr() CSS function is used to retrieve the value of an attribute of the selected element and use it in the stylesheet. It can also be used on pseudo-elements, in which case the value of the attribute on the pseudo-element's originating element is returned. (MDN)
Specification
CSS Values and Units Module Level 5
# attr-notation
Open Issues
attr()
support extended capabilities (Interop 2023) #86 (not open, but a related issue from Interop 2023)Tests
The below list of tests was generated using
wpt-find
(wpt-find -mlc 'attr('
)Current Implementations
Standards Positions
Browser bug reports
Developer discussions
Some posts in support of
attr()
:X/Twitter
StackOverflow
If you search X/Twitter for "CSS attr" you will see plenty of posts from people excited about and/or curious about the future features of CSS
attr()
. You'd also see many posts echoing one opinion calling theattr()
useless, especially in comparison to CSS custom properties.I'd like to disagree with that sentiment, but… he's right. As the
attr()
function stands today,attr()
is really only useful when trying to pull plain text from attributes to display using a pseudo-element.It's mostly useless, but it doesn't have to be.
With these newer features,
attr()
would be exceedingly useful, not taking the place of CSS custom properties by any means but rather bridging the gap between markup values and CSS values. This would stand as a very productive separation of concerns.Polls & Surveys
No response
Existing Usage
No response
Workarounds
The primary workaround for this is to use CSS custom properties, but this has several drawbacks and only lives in the markup in the form of inline styles. One of the greatest advantages of
attr()
is the ability to utilize the values set on the markup.To achieve this with CSS custom properties, one would need to apply those values twice, once to the attributes for actual markup functionality and again as a CSS custom property for CSS usage. Example:
With
attr()
, we can achieve this more concisely, using attribute values directly:Accessibility Impact
Tightly coupled code can lead to inconsistencies due to human/developer-error when updates are made. The DRY coding principle would reasonably apply here.
Privacy Impact
This issue focuses on security concerns using
attr()
, but there are already good ideas re how to circumvent those issues, the primary of which would be whitelisting: w3c/csswg-drafts#5092Other
No response
The text was updated successfully, but these errors were encountered: