Exploring @property and its Animating Powers
CSS @property
: Unleashing the Power of Typed Custom Properties and Animations
The CSS @property
rule is a game-changer, offering unprecedented control over custom properties and their animations. It allows you to define the type of a custom property, providing the browser with crucial information for seamless transitions and animations – something previously impossible with standard CSS. While currently supported primarily in Chrome and Edge, its potential is undeniable, promising exciting developments for Firefox and Safari in the future.
Type Checking: The CSS Revolution
@property
introduces type checking to CSS, enabling the creation of mini-CSS specifications. This simple example demonstrates defining a custom property --spinAngle
with an angle type:
@property --spinAngle { initial-value: 0deg; inherits: false; syntax: '<angle>'; } @keyframes spin { to { --spinAngle: 360deg; } }</angle>
Supported types include length
, number
, percentage
, color
, image
, url
, integer
, angle
, time
, resolution
, transform-list
, transform-function
, and custom-ident
.
Beyond the Tricks: Animating with Precision
Previously, animating custom properties often involved workarounds. @property
streamlines this process. Let's explore some applications:
1. Animating Color: Animating hues using HSL provides smooth color transitions. Instead of cumbersome keyframes specifying numerous color stops, @property
simplifies this:
@property --hue { initial-value: 0; inherits: false; syntax: '<number>'; } @keyframes rainbow { to { --hue: 360; } }</number>
This allows for a smooth animation across the entire color spectrum, eliminating the need for manual keyframe calculations.
2. Animating Numbers: Combining @property
with CSS counters enables animating numerical values directly. This is particularly useful for creating dynamic counters or timers:
@property --milliseconds { inherits: false; initial-value: 0; syntax: '<integer>'; } .counter { counter-reset: ms var(--milliseconds); animation: count 1s steps(100) infinite; } .counter:after { content: counter(ms); } @keyframes count { to { --milliseconds: 100; } }</integer>
This creates a smoothly incrementing counter, avoiding the inaccuracies of JavaScript's setInterval
.
3. Animating Gradients: @property
simplifies animating gradient color stops. By using calc()
and animating a custom property, you can create dynamic effects like moving waves:
@keyframes waves { 50% { --wave: 25%; } }
This offers a fluid animation, unlike the stepped transitions previously required.
4. Animating Transforms: @property
allows for precise control over transform animations. Instead of animating the entire transform
property, you can animate individual components (translateX
, translateY
, rotate
), creating complex, smooth movements:
@keyframes throw { 0% { --x: -500%; --rotate: 0deg; } 50% { --y: -250%; } 100% { --x: 500%; --rotate: 360deg; } }
This enables sophisticated animations that were previously difficult or impossible to achieve.
Conclusion: A New Era of CSS Animation
@property
opens up a world of possibilities for CSS animations. By providing type information to the browser, it enables precise, smooth, and complex animations that were previously unattainable. Experiment with the various data types and explore the creative potential of this powerful new feature. Share your creations and inspire others!
The above is the detailed content of Exploring @property and its Animating Powers. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

Let’s attempt to coin a term here: "Static Form Provider." You bring your HTML

In this week's roundup of platform news, Chrome introduces a new attribute for loading, accessibility specifications for web developers, and the BBC moves

Two articles published the exact same day:

This is me looking at the HTML element for the first time. I've been aware of it for a while, but haven't taken it for a spin yet. It has some pretty cool and

The first part of this two-part series detailed how we can get a two-thumb slider. Now we'll look at a general multi-thumb case, but with a different and

GooFonts is a side project signed by a developer-wife and a designer-husband, both of them big fans of typography. We’ve been tagging Google

The document head might not be the most glamorous part of a website, but what goes into it is arguably just as important to the success of your website as its
