Modern CSS Code Snippets: Stop writing CSS like it's 2015

(modern-css.com)

92 points | by eustoria 4 hours ago ago

26 comments

  • ktpsns an hour ago ago

    CSS in 2025: Let's write html inlined styles as if it was 2005 and separation of formatting/representation was never invented. I talk of tailwind, of course.

    • crooked-v 25 minutes ago ago

      Tailwind is a direct response to how the "C" in "CSS" actually sucks, so there's no surprise that it's so popular.

    • mattlondon 24 minutes ago ago

      Wait until you see React & JSX...

      At least html and CSS are both presentation. React/JSX now confuses presentation and business logic.

      • lateforwork 13 minutes ago ago

        > React/JSX now confuses presentation and business logic

        React was originally designed to be the "V in MVC". You can still use it that way. React becomes very simple when you only use it as the V in MVC.

        • azangru 9 minutes ago ago

          What are the M and the C, and how do they talk to the V in this case?

          • apsurd 3 minutes ago ago

            react can be pure functions that take in props. Given a set of props, ideally data primitives, the outputted view is guaranteed. it's nice.

            In practice, the entire JS ecosystem enjoys flying off the rails, every season, but it's not strictly react's fault.

            To answer your question, however those props get into the component is up the the M & C. can be async server, or shoved in as json in the script tag.

          • cbarrick 4 minutes ago ago

            - M for Model: your data model. - V for View: views of your data. - C for Controller: does stuff with your data.

    • h4x0rr an hour ago ago

      Yeah let's do that. You have everything related to your component on place instead of jumping between files.

      • lawn an hour ago ago

        Is jumping between files supposed to be difficult or something?

        • afiori 18 minutes ago ago

          Without a lot of discipline it is very easy to end up with a css with lots of unclear and hard to guess effects. Eg consider the case of <A type=1><B><A type=2></A></B></A> where A and B are complex templates. Any selector with the " " operator on A risk expanding to the inner A even if it was intended only for the outer. Similarly a :has selector might catch a descendant of the wrong element.

          @scope fixes a lot of this, but it is a complex problem. With tailwind you mostly have to worry about inheritance

        • ewuhic 16 minutes ago ago

          Is staying in one file supposed to be difficult or something?

        • chrisweekly 34 minutes ago ago

          Colocation is a useful principle in component-based architecture.

        • runarberg 42 minutes ago ago

          Also modern CSS is often written in a <style> tag either in a native web component or in a framework which supports single file component like vue or svelte.

  • Bengalilol an hour ago ago

    Me: cool, let's be creative, I love 2026.

    Browsers: Yeah, but beware of limited availability, most of those creative examples are in the 40-50% browsers support range.

    • graypegg 42 minutes ago ago

      In the past this was a major issue that meant useful features were only ever usable after IE/Safari finally supported them half a decade later, but it has seriously gotten better. Sadly as a result of Chromium's overbearing presence, but it's a helpful outcome at least.

      https://wpt.fyi/interop-2025

  • cwillu 14 minutes ago ago

    Stop pinning things to the edges of the screen and window. Some sites have literally over 50% of the viewable area taken up by irrelevant static elements. Let the content scroll, like god intended.

  • anematode 22 minutes ago ago

    Random pet peeve... it annoys me when people have old browser-specific aliases to standardized CSS properties. For example, -o-tab-size and -moz-tab-size instead of just tab-size. Those properties haven't done anything on Opera/Firefox for a decade!

  • piskov an hour ago ago

    2015 is good enough.

    For example instead of grid center, one can use flex and margin auto.

    If you are building really nation-wide products, there are still a lot of guys in corporate with old windows (where even chrome stopped updating like win7). Or, you know, old or poor people with PC from 2008.

    Also don’t forget guys with mobile phones: not like one could easily install a browser there. Especially on phones which no longer receive updates.

    So writing CSS like it is 2015 is great. Not because it feels great but because it is what caring about your users (and business) is.

    Otherwise you’ll get humbled by your clients soon enough. And in corporate they won’t even be your clients unless you support old stuff: IE 11 is a great target if you really want to shine.

    • nicoburns an hour ago ago

      I definitely don't agree with all of these, but grid centering is pretty nice and has a lot fewer quirks than Flexbox based solutions.

  • jgalt212 an hour ago ago

    CSS and JavaScript are like two dysfunctional law enforcement agencies fighting over jurisdiction.

    • sublinear an hour ago ago

      All web standards are like this, and then the battle continues when it comes to browser implementation.

  • laacz an hour ago ago

    Is it just me or gradients and tile grid with specific hover effects are AI generated stuff giveaways? Maybe it's old people yelling at clouds, but I'm very reluctant to trust the site, when I see these signs.

    • apsurd an hour ago ago

      AI got it from people though.

      I too am saddened by the instant-polish marketing pages everyone and their grandma deploys to Render, but also some people at some point in time really did make these effects. And they are nice. HTML based UIs will always have a place in my heart.

      Btw: actually I think webflow did more to pump this stuff out to the masses. The animate on scroll being the biggest offender. It's so good, but not for every literal text paragraph on your local bakery's website.

    • samhh an hour ago ago

      You’re right not to trust it, it’s wrongly calling sibling-index() widely available. And that’s the first example I checked.

  • user3939382 33 minutes ago ago

    CSS is the only thing from browsers we actually need. The rest can be done in a terminal. Contemporary terminals could even render the UI with way less memory. The browser is a nightmare because it wasn’t architected to run applications.

    • azangru 2 minutes ago ago

      > The browser ... wasn’t architected to run applications.

      Could you explain this? What prevents the browser from running applications? How should it have been architected otherwise if running applications was the goal?