{"id":335207,"date":"2021-03-04T07:51:39","date_gmt":"2021-03-04T15:51:39","guid":{"rendered":"https:\/\/css-tricks.com\/?p=335207"},"modified":"2021-03-04T07:51:41","modified_gmt":"2021-03-04T15:51:41","slug":"exploring-property-and-its-animating-powers","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/exploring-property-and-its-animating-powers\/","title":{"rendered":"Exploring @property and its Animating Powers"},"content":{"rendered":"\n
Uh, what\u2019s While everything about But before we get too giddy about this, it\u2019s worth noting that support isn\u2019t quite there. As it current stands at the time of this writing, That\u2019s right! Type checking in CSS. It\u2019s sorta like creating our very own mini CSS specification. And that\u2019s a simple example. Check out all of the various types we have at our disposal:<\/p>\n\n\n\n Before any of this, we may have relied on using \u201ctricks\u201d for powering animations with custom properties.<\/p>\n\n\n\n CSS variables are awesome, right? But scope power is often overlooked. For example, take this demo, 3 different animations but only 1 animation defined 💪 That means dynamic animations 😎 https:\/\/t.co\/VN02NlC4G8<\/a> via @CodePen<\/a> #CSS<\/a> #animation<\/a> #webdev<\/a> #webdesign<\/a> #coding<\/a> pic.twitter.com\/ig8baxr7F3<\/a><\/p>\u2014 Jhey 🐻🛠 (@jh3yy) November 5, 2019<\/a><\/blockquote> @property<\/code>? It\u2019s a new CSS feature! It gives you superpowers. No joke, there is stuff that
@property<\/code> can do that unlocks things in CSS we\u2019ve never been able to do before.<\/p>\n\n\n\n
@property<\/code> is exciting, perhaps the most interesting thing is that it provides a way to specify a type<\/strong> for custom CSS properties. A type provides more contextual information to the browser, and that results in something cool: We can give the browser the information is needs to transition and animate those properties!<\/strong><\/p>\n\n\n\n\n\n\n\n
@property<\/code> is supported in Chrome and, by extension, Edge. We need to keep an eye on browser support<\/a> for when we get to use this in other places, like Firefox and Safari.<\/p>\n\n\n
First off, we get type checking<\/h3>\n\n\n
@property --spinAngle {\n \/* An initial value for our custom property *\/\n initial-value: 0deg;\n \/* Whether it inherits from parent set values or not *\/\n inherits: false;\n \/* The type. Yes, the type. You thought TypeScript was cool *\/\n syntax: '<angle>';\n}\n\n@keyframes spin {\n to {\n --spinAngle: 360deg;\n }\n}<\/code><\/pre>\n\n\n\n
length<\/code><\/li>
number<\/code><\/li>
percentage<\/code><\/li>
length-percentage<\/code><\/li>
color<\/code><\/li>
image<\/code><\/li>
url<\/code><\/li>
integer<\/code><\/li>
angle<\/code><\/li>
time<\/code><\/li>
resolution<\/code><\/li>
transform-list<\/code><\/li>
transform-function<\/code><\/li>
custom-ident<\/code> (a custom identifier string)<\/li><\/ul>\n\n\n\n