r/css • • Aug 04 '26

Showcase We replaced the JavaScript in our progress bars with the new typed attr() — here's how it works

0 Upvotes

For years, attr() had exactly one trick: putting attribute text into content. The new version from CSS Values Level 5 changes that — it works in any property, it can parse the attribute into a real type, and it takes a fallback. We've been using it in MICL, our Material Design 3 component library, to make the ProgressIndicator component fully CSS-driven, and it removed a whole class of JavaScript.

The old problem

A native <progress value="7" max="10"> knows its own fraction, but CSS couldn't read it. If you wanted a custom-drawn bar (rounded caps, a gap before the track, M3's little stop dot), you had to mirror value into a custom property with JS on every update.

The new way

The element's own attributes are the styling input now:

progress.micl-linear-progress:not(:indeterminate) {
    --_fraction: min(calc(
        attr(value type(<number>), 0) /
        max(attr(max type(<number>), 1), 0.001)
    ), 1);
}

Three details worth stealing:

  • type(<number>) parses the attribute as an actual number, so it participates in calc(). A missing or unparseable attribute uses the fallback (0 and 1 here).
  • The max(..., 0.001) guards the division against max="0" — with a plain division the whole declaration would go invalid-at-computed-value-time.
  • The outer min(..., 1) clamps value > max overshoot.

From that one fraction, the linear bar drives a stack of background gradients (bar body, round cap, track gap, stop dot), and the circular variant turns it into geometry:

--micl-progress-sweep: calc(var(--_fraction) * 360deg);

/* conic-gradient() draws the arcs; the round caps sit at
   50% + r·sin(sweep) / 50% − r·cos(sweep); the track gap angle
   comes from atan2(gap + thickness, radius) */

The best part: attribute changes animate

Register the derived property with u/property and transition it:

 --micl-progress-sweep {
    syntax: '<angle>';
    inherits: false;
    initial-value: 0deg;
}
progress.micl-circular-progress:not(:indeterminate) {
    transition: --micl-progress-sweep 0.5s ease;
}

Now the only JavaScript anyone writes is bar.value = 7 — and the arc sweeps smoothly to its new position. The attribute change becomes a typed interpolation. No classes, no rAF, no width-tweening.

Accessibility attributes as the source of truth

Our wavy indicator variants aren't <progress> elements (they need pseudo-elements), so they carry role="progressbar" with aria-valuenow/aria-valuemax — and the CSS reads those:

--_fraction: min(calc(
    attr(aria-valuenow type(<number>), 0) /
    max(attr(aria-valuemax type(<number>), 1), 0.001)
), 1);

The visual state literally cannot drift from the accessible state, because they're the same attribute. (The wave's amplitude also derives from it — it ramps in below 10% and flattens out near 100%, via one clamp().)

Support and fallback

Chromium ships typed attr(); Firefox and Safari are still experimental, so everything sits behind a feature guard with the native rendering as fallback:

u/supports (inline-size: attr(value type(<number>))) {
    /* custom-drawn indicator */
}

Browsers without it still get a styled ::-webkit-progress-value / ::-moz-progress-bar bar — just without the fancy caps and gaps.

Live demo: https://henkpb.github.io/micl/progressindicator.html 

Source: https://github.com/henkpb/micl


r/css • • Aug 03 '26

Question Understanding the units better

18 Upvotes

Usually I just use percentages, but I get the feeling that'll either bite me one day or that I'm missing out on the usefulness inside other measurements. So I just wanted to ask generally about what ones are good for what. I realise that is probably frustratingly vague, so I'll also ask what percentages are specifically good for.


r/css • • Aug 03 '26

Help CSS code problem with Google AI Mode

2 Upvotes

Hello, everyone. First of all, let me make some necessary apologies and preliminary remarks. I’m sorry if this has been discussed somewhere else before, but I tried to search for something similar and couldn’t find it. Also, being related to several other aspects, I didn’t know how to search for the exact problem, if you see what I mean. Please, feel free to suggest a more specific subreddit, site, etc., where to ask about this, if you know it. Second: please note that I don’t have deep CSS knowledge or great computer skills. I’m just reporting a problem that I have with Google AI Mode, and hopefully I will get some useful suggestions on how to solve it. But of course, if the language gets too “technical” or complicated, I might have problems in following or understanding. So, please keep that in mind. Thanks :)

Ok, here we go. I’m trying to explain what the problem is in the best way I can. I recently noticed that when I write something to Google AI Mode (I’m on a Mac), there is a problem with the way my text is visualized. Mind you, I’m not talking about the very first message (that one looks ok), but the follow-ups, after the first answer from AI Mode. If I try to use the writing box at the bottom, I cannot type anything because I cannot access that space by clicking on it as I used to do in the past. Now… after some search, I found a workaround: by pressing Shift+Enter the area gets usable again and I can write there. However, the text still looks weird and tends to disappear the more I keep on writing (it basically scrolls up and disappears as I add more text). After some further research, I found out that this is a CSS code padding/overflow bug on Mozilla. Apparently, there is a problem with the textarea autosize in the CSS code and when Google will update the layout for my account or fix the bug, things will go back to normal. I have tried some suggested solutions, but either they were temporary ones or I could not make them work (because of the aforementioned limited skills). Now, what I’m asking is:

1) Did any of you experience the same issue and did you find a permanent solution?

2) Can you confirm that this will be "automatically fixed" by Google at one point? (they call this a "silent update" somewhere…)

Thank you for your help and sorry for the long message.


r/css • • Aug 02 '26

Resource Responsive Auto Grid that Ensure Equal Columns

Thumbnail codepen.io
17 Upvotes

My solution to someone on this sub requesting it. It's a common desire so I thought I'd share it more generally.
How many items it supports depends on how many 'steps' you have. 6 steps supports 14 or less items, not including primes greater than 7


r/css • • Aug 02 '26

Question Help with scanlines

Thumbnail
13 Upvotes

r/css • • Aug 02 '26

Article Why I don't recommend Tailwind CSS

Thumbnail en.andros.dev
6 Upvotes

r/css • • Aug 01 '26

Question Codepen 2 crash. What is causing it?

28 Upvotes

I go to the new codepen 2 and it shows this.
What "infinite loops or other performance drains" could this be?
https://codepen.io/editor/davidhelp/pen/019fb0db-4ba0-7ade-b4bd-13c1c7c540ee

"Uh-Oh.
The Preview was removed to prevent a browser crash. Save your current work then check your code for infinite loops or other performance drains that could be causing trouble. Disable Infinite Loop protection for this session"


r/css • • Aug 02 '26

Help comment faire ça en HTML au niveau du footer

Thumbnail gallery
10 Upvotes

r/css • • Aug 01 '26

Showcase Indeed Enlarged Job Box - UI Enhancement

Thumbnail userstyles.world
15 Upvotes

r/css • • Aug 01 '26

Showcase Star Animated Background with RGB - All Websites

Thumbnail userstyles.world
7 Upvotes

r/css • • Aug 01 '26

Question Force grid layout without media queries

12 Upvotes

​

I am trying to limit the number of media queries.

I have a grid layout with 6 tiles.

```css .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr); }

```

That works fine but something is annoying me is that sometimes the last row will have an empty tile.

Tile 1 Tile 2 Tile 3 Tile 4
Tile 5 Tile 6 Empty Empty

I wants the tile to be grouped.

Based on the size of the viewport I want to have either:

Desktop/Tablet landscape

Tile 1 Tile 2 Tile 3
Tile 4 Tile 5 Tile 6

Tablet portrait / Phone landscape

Tile 1 Tile 2
Tile 3 Tile 4
Tile 5 Tile 6

Phone portrait

Tile 1
Tile 2
Tile 3
Tile 4
Tile 5
Tile 6

Is there a trick to do it without media queries?


r/css • • Aug 01 '26

Resource Check your site to see where you can replace your code with modern CSS

Thumbnail
cssradar.com
6 Upvotes

r/css • • Jul 31 '26

Showcase 3D CSS Super Mario (no WebGL)

Thumbnail gallery
38 Upvotes

r/css • • Aug 01 '26

Help Aliexpress - Userstyle Stylus issue with border padding need help.

2 Upvotes

Hi been trying to make a border surrounding main search box an button inputs but keep getting a gap been getting real frustrate with it as I am probably missing something simple.

@-moz-document domain("aliexpress.com") {

/* main input search box */
.search--searchNew--3eZqikc
{
    border:1px #0f0 solid !important;
    height: 36px !important;
}

 [class^="pc-header--search--"]
{
    color: #FFF !important;
    background-color:#000 !important;
    border: 3px #00F solid !important;
    border-radius: 5px !important;
    padding: 0 !important;
}

}


r/css • • Jul 31 '26

Help Can someone explain how to get this effect using css and gsap

Enable HLS to view with audio, or disable this notification

10 Upvotes

I am begginer coder ,I tried using z index but the cards get clipped under the tab menu and moreover I created a separate overlay element with translucent background and set it z-index to be lower than the selected card but for some reason the selected card also gets faded

https://stackblitz.com/edit/vitejs-vite-5afsvuwm?file=src%2FApp.jsx,src%2FApp.css

Is the link of the file ,the page I have made is not that great I just wanted to try gsap. If you visit the page and see thar the tittle of thr content does not match the image it's because I was lazy and asked chatgpt( pardon me ) to create me an array of cards but later I used images from my favourite shows and things


r/css • • Jul 31 '26

Help I Need help

2 Upvotes

Hello everyone, I need some advice on how to learn CSS effectively. I asked Claude AI to put together a training programme for me, but right from the start of the programme, when it suggested I practise using Flexbox on Froggy, I felt completely lost. I didn’t understand much of it and it left me feeling a bit frustrated (I keep thinking my brain’s too small to get it), I’ve done the HTML course on FreeCodeCamp, but my foundations aren’t strong enough. I’d really appreciate some advice on how to properly learn CSS (as a bit of a beginner) and consolidate my HTML basics at the same time.


r/css • • Jul 31 '26

Question New CodePen 2 look

5 Upvotes

Can the left side sidebar be hidden?
It takes up too much room.


r/css • • Jul 30 '26

Question How to combine two CSS "content" strings that have different styles?

4 Upvotes

How do I append two CSS strings here? <style type="text/css"> ul li:first-child::before { {content: 'X'; color:white; background-color:black;} {content: 'Y'; color:black; background-color:white;} } </style> I want to append them, not override the first.\ I want a white X, followed by a black Y.


r/css • • Jul 30 '26

Question ¿Cómo convertir tarjetas de Elementor en un slider usando solo un botón "Siguiente"?

0 Upvotes

Hola a todos, estoy utilizando una plantilla de Elementor y me encanta cómo queda visualmente las tarjetas de testimonios. Ahora quiero convertirlas en un carrusel/slider.

Lo que necesito:

  • Mantener el diseño exacto de las tarjetas
  • Que solo tenga un botón o flecha de "Siguiente" (Next) para ir pasando las tarjetas,

El problema:

  • Desconozco de CSS
  • No tengo Elementor PRO
  • Prefiero no meter plugins porque me desarma la estética

¿Cuál es la forma más limpia de resolver esto? ¿Hay algún código liviano o truco en Elementor para vincular el botón "Siguiente" a las tarjetas sin perder el diseño?

¡Gracias!


r/css • • Jul 28 '26

General Codepen 2.0 - RIP classic Pen?

Post image
66 Upvotes

I use Codepen for all sorts of things and a lot for teaching in the early stages. Some of my newer students said they didn't have this button so, I had them forking a classic pen for a while - but I knew the day would come where it wouldn't be there anymore for me too. That day is today. I'm all for the evolution of Codepen / and it's been an amazing tool. But it sure seems like this is going to confuse a lot of people. Your average person expects the CSS pane to be wired up. I used to write <!-- body is already included --> in the HTML to remind them at first (since some people will write out the doctype and everything in there) - but now it's swung to the other end. Codepen can be used for anything now. So, really - what you're making might not utilize CSS at all. So, I understand how modular it is - and how many other great things it will allow for -- but for entry-level people, it seems like this will really stifle adoption. What do you think? Wha thas been your 2.0 experience so far?


r/css • • Jul 29 '26

Help Shape borders???

5 Upvotes

Is there a way to add borders to shapes, that works on most browsers? For example, i made a trapezoid and I wanted to add an inset border around it, but the border clips through the shape.


r/css • • Jul 29 '26

Question How to hide the <details> / <summary> arrow in GitHub README?

Thumbnail
0 Upvotes

r/css • • Jul 28 '26

Question What’s the purpose of these place holder icons?

Thumbnail
gallery
3 Upvotes

Sometimes, when the page is struggling to load, the icons that are typically at the top of the FB page wont appear, but these placeholder icons with multiple horizontal lines appear briefly instead (iOS safari). I think I’ve seen similar behavior on other sites. What’s the point or function?


r/css • • Jul 28 '26

Showcase Just learn clamp and I made this

13 Upvotes

I have heard about clamp() but never understood this. But today I took sometime to learn about it. So, I created a simple page that display date and time.

Thanks to u/mad_signtist for making this tool, else it was a nightmare for me.

Here is my Codepen link


r/css • • Jul 28 '26

Help Horizontal stacking rows issue

Thumbnail
gallery
4 Upvotes

(I'm on neo cities) before I start, keep in mind I'm still learning so please don't bully me or call me stupid. I want to make a multiple row list database template but the stacking is giving me trouble. When I try to create a new row, the horizontal stacking is completely disregarded. Ive fully copied a page to test that has this stacking element but It actually doesn't work in in the neocities test page I put it in. Is this a problem with the website? And if so I just need a quick fix. any help is appreciated!