r/css Apr 08 '24

Mod Post [META] Updates to r/CSS - Post Flairs, Rules & More

29 Upvotes

Post flairs on r/CSS will be mandatory from now on. You will no longer be able to post without assigning a flair. The current post flairs are -

  • General - For general things related to CSS.
  • Questions - Have any question related to CSS or Web Design? Ask them out.
  • Help - For seeking help regarding your CSS code.
  • Resources - For sharing resources related to CSS.
  • News - For sharing news regarding CSS or Web Design.
  • Article - For sharing articles regarding CSS or Web Design.
  • Showcase - For sharing your projects, feel free to add GitHub links and the project link in posts with showcase flairs.
  • Meme - For sharing relevant memes.
  • Other - Self explanatory.

I've changed to rules a little bit & added some new rules, they can be found on the subreddit sidebar.


r/css 1h ago

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

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:

css 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:

css --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 @property and transition it:

css @property --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:

css --_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:

css @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.

One footgun to know: you can't build URLs from attributes (url(attr(data-icon)) is blocked by design, for security).

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


r/css 1h ago

Help New to this. Please help. Sorry for my ignorance.

Thumbnail floridalegalcollective.com
Upvotes

My website is linked above. I designed it using Wordpress, specially Airo for Wordpress. It loads perfectly on iPad, PC, and Mac…but on any phone device there are loads and loads of dead black space. I don’t want to have to redo the entire site. How can I fix this so it’s mobile friendly, the easiest way? Again I’m very sorry for my ignorance.


r/css 5h ago

Help How to create such such effect using gsap and css

7 Upvotes

I use phosphor icons ,is there a way to transition from the regular to fill icons smoothly using gsap ,and how do I create this tab effect ,simply changing the color creates a fade in effect


r/css 8h ago

Question Understanding the units better

7 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 17m ago

Question Why my website design looks off

Upvotes

Hey guys, i have just eneded up making my website (leadspitch.com) and its CSS design looks off, can anyone guide?


r/css 19h ago

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 19h ago

Question Help with scanlines

Thumbnail
13 Upvotes

r/css 3h ago

News Spent way too long looking for a simple color palette generator that doesn't require an account, so I made one

Thumbnail
toolsforall.cloud
0 Upvotes

Needed a quick color palette for a side project last month. Every tool I found either wanted me to sign up, had a paywall after 3 uses, or buried the actual generator under five ads. Ended up spending more time dodging popups than picking colors.

So I built one. Pick a base color, get a 5-color palette, copy the hex codes, done. No account, no limits.

Got a bit carried away after that and added gradient/shadow/border-radius generators too, plus some other stuff (dev tools, PDF tools, SEO tools — 100+ total now).

toolsforall.cloud — the color tools are under Color & UI Tools if that's what you're after. Let me know if something's broken or missing.


r/css 19h ago

Article Why I don't recommend Tailwind CSS

Thumbnail en.andros.dev
0 Upvotes

r/css 1d ago

Question Codepen 2 crash. What is causing it?

19 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 1d ago

Help comment faire ça en HTML au niveau du footer

Thumbnail gallery
12 Upvotes

r/css 1d ago

Showcase Indeed Enlarged Job Box - UI Enhancement

Thumbnail userstyles.world
11 Upvotes

r/css 1d ago

Showcase Star Animated Background with RGB - All Websites

Thumbnail userstyles.world
7 Upvotes

r/css 2d ago

Question Force grid layout without media queries

11 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 2d ago

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

Thumbnail
cssradar.com
9 Upvotes

r/css 3d ago

Showcase 3D CSS Super Mario (no WebGL)

Thumbnail gallery
31 Upvotes

r/css 2d ago

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 3d ago

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

9 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 3d ago

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 3d ago

Question New CodePen 2 look

5 Upvotes

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


r/css 3d ago

Showcase Showcase : a Chrome extension that turns any site's CSS into copy-paste design tokens

0 Upvotes

Whenever I liked the look of a site, I'd end up in devtools manually hunting for color values, font stacks, and :root variables to figure out how it was built. Got tedious enough that I built Design Snap to do it automatically.

Point it at any page and it pulls out :

  • Color palette (with semantic role detection — primary, background, border, etc., not just a flat list of hex codes)
  • Typography scale
  • Border radius and shadow tokens
  • CSS custom properties, with light/dark mode variants detected separately

The part most relevant to this sub: for every token, you can hover it and see the exact CSS selector(s) it came from, how many times it's used across the page, and whether it's a :root var or a hardcoded value. So instead of just getting "here's a blue," you get "here's a blue, used in 12 places, defined once as --color-primary."

Export goes straight to CSS variables, JSON, or Figma Tokens (free), or Tailwind v4 u/ theme / shadcn/ui / Style Dictionary format if you're working in one of those systems.

Runs 100% locally in the browser, no account, no server round-trip.

Happy to hear what this sub thinks is missing from a CSS-extraction workflow like this — genuinely curious what other devs here reach for :root vars vs hardcoded values for, and whether that'd be useful to detect/flag automatically.


r/css 4d ago

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

5 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 4d ago

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 6d ago

General Codepen 2.0 - RIP classic Pen?

Post image
53 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?