r/css

▲ 600 r/css+2 crossposts

Switch favicon based on color scheme

If you've always wanted to switch your favicon based on dark/light mode, here's how to do it. I bet you already know that! 😊

Bonus: If you use an SVG favicon, you can use media queries within it to achieve the same "effect".

u/wanoo21 — 9 days ago
▲ 41 r/css

Tiny CSS feature that helps reduce repeated color values

Was exploring some CSS tricks recently and found currentColor.

It automatically uses the element’s current text color for other properties.

button {
  color: tomato;
  border: 2px solid currentColor;
}

So instead of repeating the same hex value everywhere, the border just follows the text color automatically. Pretty useful for buttons, icons, SVGs, hover states, theme systems

Small feature, but makes CSS feel cleaner.

reddit.com
u/riti_rathod — 17 hours ago
▲ 0 r/css+1 crossposts

Got tired of writing hover:, group: repeatedly in Tailwind, so I made this

I kept ending up with Tailwind class strings that looked like this:

className="px-4 py-2 rounded hover:bg-blue-500 hover:text-white hover:shadow-lg focus:ring-2 focus:ring-offset-2 focus:outline-none active:scale-95"

After doing this repeatedly across components, I made a tiny utility called tw-variant to group variant prefixes automatically.

Example:

import { tv } from "tw-variant"

const buttonStyles = tv({
  base: "px-4 py-2 rounded font-medium transition-all",
  hover: "bg-blue-500 text-white shadow-lg",
  focus: "ring-2 ring-offset-2 outline-none",
  active: "scale-95",
  dark: "bg-gray-900 text-white"
})

Generated output:

"px-4 py-2 rounded font-medium transition-all hover:bg-blue-500 hover:text-white hover:shadow-lg focus:ring-2 focus:ring-offset-2 focus:outline-none active:scale-95 dark:bg-gray-900 dark:text-white"

Why I made it:

  • reduces repeated hover: / focus: / dark: prefixes
  • keeps Tailwind class strings easier to read
  • works with any Tailwind variant
  • tiny + zero dependencies
  • full TypeScript support

Works nicely alongside clsx, cn, or tailwind-merge.

import clsx from "clsx"

className={clsx(
  tv({
    hover: "shadow-lg",
    focus: "ring-2",
    dark: "bg-gray-900"
  }),
  isDisabled && "opacity-50"
)}

Install:

npm install tw-variant

Github: https://github.com/kushalxcoder/tw-variant
NPM: https://www.npmjs.com/package/tw-variant

Would genuinely love feedback/suggestions/improvements.

u/Electronic-Stick7492 — 2 days ago
▲ 93 r/css

You liked my 3D card the other day, I raise you my liquid buttons <3

Customizable and all code here: https://doathingy.com/?tool=dt_1778503835266_c5lcoh

I had seen some great liquid effects (like this Liquid), but nothing quite satisfactory. I'm using the overlapping div circles with svg filters (gaussian blur) trick and then built a custom js "physics engine", text sits in a separate layer.

u/Only-Season-2146 — 3 days ago
▲ 1 r/css

How is order of precedence established with CSS variables?

I have a CSS library that is themeable by way of CSS variables. I set the variables in the library like so:

:root,
:host {
  --my-color: #ffffff
}

Then in their own CSS code, the user can override this value:

:root,
:host {
  --my-color: #000000
}

This seems to work, but I'm wondering why it works. The selector is the same in both cases, so I'm not sure why it's using the variable.

Also, is there something I can do to ensure that in all cases the latter variable always gets chosen?

reddit.com
u/CoVegGirl — 1 day ago
▲ 20 r/css

if() function - Are new CSS features guaranteed to eventually be supported in all major browser?

I recently stumbled upon the CSS if() function. For me, being able to use media queries within the declaration block is pretty much the last reason to use SASS and with the if() function I would be able to write my stuff in pure CSS without any preprocessor.

section.main-content {
    padding: if(
        media(width < 600px): 5px;
        media(width < 1200px): 10px;
        else: 20px;
    );
}

As of right now, browser support is pretty meh. While it's been implemented in Chrome and Edge for about a year, Firefox, Safari and Samsung do not support it.

I am about to start coding a smol fun project and I was considering to just yolo it and use this new feature, even if it means that it won't be useable for 30% users for a couple months.

But are experimental CSS features guaranteed to eventually make it to all major browser at all? Or is it possible that two years from now, Firefox and Safari still haven't adopted this?

reddit.com
u/pnwstarlight — 6 days ago
▲ 3 r/css

!IMPORTANT

Why is this not interpreted as "Not" Important? Why use the exclamation at all? Just thinking out loud while programming.

reddit.com
u/michael_e_conroy — 3 days ago
▲ 3 r/css

Beginner question about padding/margins on elements to make them fit edges of the screen.

So when trying to make the background of an image or header fill the entire screen, I seem to have to put margin-left: -8px and margin-right: -8px. At 0px there's a small gap on the left and right edges of the screen. The element at the top of the screen I also have to put margin-top: 18px on. I feel like this can't be the intended way to do things and there's something obvious I'm missing but I'm not sure what. Also suspect my workaround might not work on different resolution screens. Putting padding to 0 doesn't fix it either. Googling this comes up with a lot of other people with the same issue but everyone just says to set margin and padding to 0.

Here's the code for my header for example:

text-align: center;

background-color: rgb(160, 20, 0);

padding-top: 8px;

padding-bottom: 8px;

margin-left: -8px;

margin-right: -8px;

Setting padding left and right to 0 has no effect, which I assume means they are already 0.

Is there something obviously dumb I've done? I've only just started learning CSS so I assume I've missed something pretty fundamental. Thanks.

reddit.com
u/Sabesaroo — 1 day ago
▲ 0 r/css

I was trying to make an expense tracker app by using HTML and CSS just for learning purpose. At the point when I needed to design my application, I asked the AI about the specifications and style along with the font styles, yet I did not comprehend anything that it told me. So I just requested it to make the entire website for me, just to understand the style. and in moments it made a pretty good webpage for me. After it I totally lost interest in make the app. Since I knew I could not make something as beautifully designed as that on my own, maybe i could do that site in some days but still, it did in seconds..

What do I do now? Should I even learn CSS and HTML anymore?

reddit.com
u/Feisty_Ad_627 — 7 days ago
▲ 32 r/css+13 crossposts

I built a visual frontend asset library so I can stop losing my own UI snippets

As a web developer, I often build or collect small frontend assets that are useful later: buttons, gradients, loaders, hover effects, CTAs, footers, bento grids, layout fragments and product UI patterns.

The problem is that these assets usually end up scattered across old projects, screenshots, notes, CodePens, local folders or random files. When I need one, I know I already made something similar, but finding it takes too long.

So I built UI IP Toolkit: a static visual catalog for fast access to my copy-ready frontend assets.

Live site: https://ui-ip-toolkit.vercel.app/ GitHub: https://github.com/ikerperez12/UI-IP-Toolkit-v4.0

What it is

UI IP Toolkit is a public, static frontend asset library. It is designed to be browsed visually, not as a package install.

It includes sections for:

  • Buttons and interaction states
  • Gradients and color systems
  • Loading patterns
  • Text effects
  • Hover treatments
  • Glass surfaces
  • CTAs and pricing blocks
  • Footers
  • Bento grids
  • Navigation patterns
  • 404 and recovery pages
  • Product UI patterns
  • Layout fragments and reusable CSS utilities

Every card is meant to be practical: open the site, scan visually, copy the snippet, adapt it, and move on.

Why I made it static

I wanted the toolkit to be simple, fast and easy to publish:

  • No backend
  • No runtime framework dependency
  • No account required
  • No build step needed for browsing
  • Self-hosted fonts and assets
  • Deployed as a static site on Vercel

The goal was not to create a huge npm package or a rigid design system. I wanted a personal working library that feels visual and fast enough to use during real frontend work.

The main use case

When I am building a new page or feature, I can open the toolkit and quickly find a starting point:

  • Need a loader? Go to Loading States.
  • Need a CTA? Open CTA Blocks or Purchase CTAs.
  • Need a footer? Open Footer Systems.
  • Need a visual layout idea? Open Bento Systems.
  • Need a small CSS utility? Open the utilities section.

It is basically a visual memory layer for reusable frontend work.

Tech stack

The project is intentionally simple:

  • HTML
  • CSS
  • Vanilla JavaScript
  • Local fonts
  • Local media assets
  • Vercel static hosting

The repository is public here:

https://github.com/ikerperez12/UI-IP-Toolkit-v4.0

The live version is here:

https://ui-ip-toolkit.vercel.app/

What I learned

The biggest improvement was not adding more components. It was making the catalog easier to navigate.

Once the toolkit had many sections, a long top nav became useless. I replaced it with a compact section menu grouped by category. That made the site feel much more like a real working tool instead of a long landing page.

I also learned that previews matter a lot. If every card looks too similar, the library feels bigger than it is useful. So I spent time making the previews more varied and more realistic while keeping the site lightweight.

Feedback welcome

I am sharing this because I think other frontend developers might have the same problem: useful assets scattered everywhere, but no quick visual way to reuse them.

Would you use a personal visual asset catalog like this in your own workflow? And what sections would you add next?

Live site: https://ui-ip-toolkit.vercel.app/ GitHub: https://github.com/ikerperez12/UI-IP-Toolkit-v4.0

u/Time-Willingness-360 — 4 days ago
▲ 1 r/css+5 crossposts

My extension can pull any website to plain tailwind css

[SELF-PROMOTION]

I built Tailfind, a Chrome extension for developers who work with Tailwind.

At first, I built it for personal use. I found it very useful, especially when developing new pages based on references from other interfaces. The main pain point it solves is reducing the manual work needed to recreate UI patterns. I decided to move forward and share it with other developers. I built Tailfind using Codex and managed to create an automated flow that successfully learned how to parse elements and generate clean, plain Tailwind output.

The idea is simple:
When you find a useful UI pattern on a real page, Tailfind lets you inspect the element, capture the right fragment, and convert it into plain Tailwind-ready HTML.

- No rebuilding from a blank file.
- No manually copying styles one by one.
- Just select, copy, paste, and keep moving.

It’s especially useful when prototyping, rebuilding existing interfaces, or turning live UI references into a starting point for Angular, React, Vue, or Svelte projects. Tailfind can also open the generated HTML directly in Tailwind Play, so you can tweak the result before bringing it into your codebase.

I’m currently refining the extension and would love feedback from developers who use Tailwind in real projects.

Chrome Web Store:
https://chromewebstore.google.com/detail/tailfind/famibopnbenoegknengohifmnjnkhohh

Website:
https://tailfind.org

Full Website capture GitHub page from my extension:
https://play.tailwindcss.com/XiZtXbLn9W

u/akopian25 — 3 days ago
▲ 5 r/css+1 crossposts

Hey everyone,

I’m building a chrome extension around a problem I keep running into: I open DevTools, delete a popup, hide a sticky banner, remove a distracting block, tweak some CSS… and then everything is gone after a reload.

The idea is to make those quick browser edits persistent.

So if a website has an annoying newsletter modal, floating ad, cookie banner, sidebar, paywall-style overlay, or any other element you don’t want to see, you could remove it once and have that change come back automatically next time. It could apply only to the current page, or to the whole domain if that makes sense.

The other side of it is for experimenting. Sometimes I’m adjusting spacing, colors, font sizes, classes, or small bits of HTML directly in DevTools just to see what looks better. The extension would keep track of those changes too, so instead of trying to remember “what did I change again?”, you’d have a clear record of the useful tweaks you made in the browser.

So it’s partly a way to clean up websites you visit often, and partly a way to save visual experiments before deciding whether to recreate them properly in your code.

I’m trying to understand if this is actually useful to people, or if it sounds like something that would be nice in theory but not part of your real workflow.

Would you use a tool like this? Do you see any other interesting features I could add?

reddit.com
u/Blozz12 — 8 days ago
▲ 11 r/css

CSS electric fire

Not sure if I'm aloud to post links to my own site?

I am learning web development, mainly HTML and CSS and I found this card with the electric border while looking for things made with only CSS.

https://codepen.io/BalintFerenczy/pen/KwdoyEN

I thought it was a pretty cool looking effect.

Not very useful but that didn't stop me from seeing what I could do with it.

Initially I just changed a couple of things and made this: https://thisistheway.one

But what I really wanted was to make a divider with it and ended up with this: https://thisistheway.one/divider-index.html

u/Roaster-Dude — 2 days ago
▲ 3 r/css

Custom font loading and FOIT/FOUT trade offs

Quick Definitions

FOUT (Flash of Unstyled Text):

Timeline:
[0ms]    HTML parsed, text visible in fallback font (e.g., Arial)
[800ms]  Custom font downloads
[800ms]  Text re-renders with custom font → visible style jump

FOIT (Flash of Invisible Text):

Timeline:
[0ms]     HTML parsed, text is HIDDEN (invisible)
[800ms]   Custom font downloads
[800ms]   Text appears with custom font
[3000ms]  If font fails → fallback shows after timeout

The Problem

I'm seeing that many sites are defaulting to having FOUT which sometimes results in funky layout shifts(workarounds exist), but it always results in a noticeable switch of fonts.

Some blog posts say to never do FOIT, but to me waiting 1 second (slow mobile connection) to show clean text seems like nicer UX. On desktop it makes no difference, but if you are driving through a tunnel or experiencing slow mobile connection for any other reason, FOUT results in your visitors seeing an ugly font for 1 or more seconds, and then all of a sudden the screen looks like it flickers and the intended fonts are loaded.

The Question

Maybe there is a middle ground where you show some minor text elements with FOUT, but keep heading and subheadings hidden until the font loads. The heading and subheadings are larger text and result in a much more significant flash when restyled. I feel like it is better to progressively show text as soon as relevant fonts are loaded(especially above the fold).

Am I the only one? Or is twitchy rendering the norm and everyone just got used to it?

reddit.com
u/yasonkh — 2 days ago
▲ 33 r/css+2 crossposts

The tool is StyleBop. Folder of .css files in, folder of .css files out — same files on disk, formatted cleanly, no proprietary format, no compile step. Open the same folder in VS Code afterward and the diffs are clean.

The reason I built it: I love writing CSS, but I don't love hand-managing a :root of 80 custom properties or hunting down which selector owns the padding-block: 1.25rem I want to tweak. So this is a CSS-aware editor that knows what's in your stylesheets and lets you act on the structure, not just the text.

Modern CSS it understands as first-class:

  • u/layer — cascade layers are surfaced in the UI; you can pick which layer a ruleset belongs to and drag-reorder priority
  • u/container and named container queries — write the condition once, the canvas previews under it
  • u/supports — feature queries with and/or/not compound forms
  • u/media wrapping rulesets directly
  • CSS nesting (& .child)
  • u/keyframes + a draggable timeline with cubic-bezier curve editor
  • u/font-face families grouped in the Tokens tab
  • Custom properties (var(--token)) — resolved inline by default, swap to raw var() syntax with one toggle

The thing I'm proudest of: project-wide token refactors.

  • Extract to Variable — pick any literal (#3b82f61.25remcubic-bezier(0.4, 0, 0.2, 1)), hit a shortcut, and it rewrites every matching occurrence across every file in the folder to var(--name). Per-file undo entries. Suggested names use a curated palette: #6495ED extracts as --color-cornflower, not --color-6495ed.
  • Usage tracker — every variable in the Tokens tab shows a usage count badge. Click to see every file/ruleset that consumes it. "0 references — safe to delete" stops dead tokens from accumulating.
  • Resolution chain — vars resolve through :root, layer overrides, and parent rulesets, so what you see is what the browser will compute.

What it doesn't do:

  • Not a framework. No Tailwind output, no utility classes, no build step.
  • Not a generator. It edits your CSS, it doesn't author it from scratch.
  • No JS or HTML editing — the canvas previews shapes/typography/effects but the surface area is CSS only.

Native:

100% Swift/SwiftUI, code-signed, notarized, Sparkle auto-update, no telemetry. Localized in 8 languages.

----

I'd love hard feedback from people who write CSS for real — especially edge cases I haven't hit. Try opening a real codebase and tell me what breaks.

Download: https://bendansby.com/apps/stylebop.html

u/FlowIll9219 — 9 days ago