July 12th, 2024

@property: Next-gen CSS variables now with universal browser support

The CSS Houdini APIs now universally support the @property rule in modern browsers. This feature enhances CSS custom properties by allowing type definitions, fallback values, error handling, and advanced syntax for smoother property animations.

Read original articleLink Icon
@property: Next-gen CSS variables now with universal browser support

The @property rule, a part of the CSS Houdini APIs, is now universally supported across modern browsers as of July 9, 2024. This feature enhances control and flexibility for CSS custom properties, also known as CSS variables. It allows for defining types for custom properties, setting fallback values to prevent style disappearance, and improving error handling within CSS. By registering CSS custom properties with @property, users can create advanced custom properties with detailed syntax and inheritance settings. This approach ensures that properties contain expected values, preventing failures in stylesheets. Additionally, @property enables smooth animation of properties like gradients, previously challenging to transition, by providing syntactic meaning to variables. This advancement in CSS empowers developers to create more dynamic and expressive stylesheets.

Link Icon 5 comments
By @lenkite - 6 months
CSS becoming an unreadable mess with so much special-syntax for properties. The cognitive load is just too much. HN folks make fun of tailwind (even I am guilty), but the hard fact remains that Tailwind simplifies and dumbs-down stuff for the mortal programmer. I personally find reading complex C++ Template Metaprogramming easier to follow than sophisticated CSS.

    .card {
      border-radius: 1rem;
      max-width: 36ch;
      padding: 2rem;
      background: radial-gradient(
          300px circle at 55% 60% in oklab, 
          var(--shine-2), transparent 100% 100%
        ), radial-gradient(
          farthest-side circle at 75% 30% in oklab, 
          var(--shine-1) 0%, var(--card-bg) 100%
        );
      background-blend-mode: color-burn;
      animation: animate-color-1 8s infinite linear alternate, 4s animate-color-2 1s infinite linear alternate;
    }
By @londons_explore - 6 months
Are we turing complete yet? Can I play doom in pure CSS?
By @dayjah - 6 months
Reading the radial gradient example I’m struck by how much English is used, “farthest-side” as an example, and how far beyond short hand symbols for concepts (“var”, “int”, etc) we’ve moved.

I’ve been around a while, I understand that English is the lingua-franca of compiled languages … but CSS seems like a singular travesty.. other instructions in the “radial-gradient” function are “animate”, “infinite”, “alternate”.

I feel like CSS deserves to be internationalized, as it stands this group is creating a dialect that only English speakers can understand with relatively low cognitive load.