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











Have you ever needed a countdown timer on a project? For something like that, it might be natural to reach for a plugin, but it’s actually a lot more

Everything you ever wanted to know about data attributes in HTML, CSS, and JavaScript.

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

One thing that caught my eye on the list of features for Lea Verou's conic-gradient() polyfill was the last item:

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

The inline-template directive allows us to build rich Vue components as a progressive enhancement over existing WordPress markup.

Every time I start a new project, I organize the code I’m looking at into three types, or categories if you like. And I think these types can be applied to

PHP templating often gets a bad rap for facilitating subpar code — but that doesn't have to be the case. Let’s look at how PHP projects can enforce a basic
