- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Selectors
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS - animation
The animation shorthand is a CSS property that makes it easier to apply animations between styles.
Constituent properties
This property is a shorthand for the following CSS properties:
- animation-delay
- animatiom-direction
- animation-duration
- animation-fill-mode
- animation-iteration-count
- animation-name
- animation-play-state
- animation-timing-function
Possible Values
The following is the list of all the possible values of animation shorthand property.
<single-easing-function> - Specifies the kind of transition. The value needs to be from the list of values in <easing-function>.
<single-animation-iteration-count> - The count of playbacks for the animation. The value needs to be among the options found in animation-iteration-count.
<single-animation-direction> - The animation's direction of playback. The value needs to be among those that animatiom-direction offers.
<single-animation-fill-mode> - Chooses the styles that should be applied to the target of the animation both before and after it is executed. The value has to come from the animation-fill-mode list.
<single-animation-play-state> - Determines if the animation is currently playing. One of the values in animation-play-state must be the value.
One or more single animation, separated by commas, make up the animation property.
Each animation property is defined as:
The <time> value occurs zero times, once or twice.
The following values occurs zero times or once
<single-easing-function>
<single-animation-iteration-count>
<single-animation-direction>
<single-animation-fill-mode>
<single-animation-play-state>
A name for the animation that is optional and can be <string>, <custom-ident>, or none.
Syntax
animation = <single-animation># <single-animation> = <time [0s,∞]> || <easing-function> || <time> || <single-animation-iteration-count> || <single-animation-direction> || <single-animation-fill-mode> || <single-animation-play-state> || [ none | <keyframes-name> ]
Applies To
All the HTML elements.
CSS animation - Basic Example
In the following example, a 5-second ease-in-out animation is used to produce a continuous alternate rising effect for a box element using the animation shorthand property.
<html> <head> <style> :root { overflow: hidden; background-color: lightcoral; display: flex; height: 400px; justify-content: center; } .box { background-color: lightgray; border-radius: 10%; height: 150px; aspect-ratio: 1 / 1; animation: 5s ease-in-out 0s infinite alternate box-rise; } @keyframes box-rise { from { transform: translateY(100vh); } to { transform: translateY(0); } } </style> </head> <body> <div class="box"></div> </body> </html>
CSS animation - Animating Multiple Properties
In the following example, multiple properties are smoothly animated by using the animation shorthand property.
<html> <head> <style> :root { overflow: hidden; background-color: lightgreen; display: flex; height: 400px; justify-content: center; } .flower { background-color: #ff69b4; border-radius: 15%; width: 150px; height: 150px; animation: 3s ease-in-out 0s infinite alternate blooming-flower; } @keyframes blooming-flower { from { transform: translateY(110vh) rotate(60deg); background-color: #00bfff; box-shadow: 0 0 10px #00bfff; } to { transform: translateY(0) rotate(0); background-color: #ffd700; box-shadow: 0 0 20px #ffd700; } } </style> </head> <body> <div class="flower"></div> </body> </html>
CSS animation - Applying Multiple Animations
In the following example, the animation shorthand property is used to apply a dual animation sequence.
<html> <head> <style> :root { overflow: hidden; background-color: #ffeb3b; display: flex; height: 400px; justify-content: center; } .firework { background-color: #ff4500; border-radius: 50%; width: 200px; height: 120px; animation: 3s linear 0s infinite alternate explode-firework, 4s linear 0s infinite alternate color-shift; } @keyframes explode-firework { from { transform: translateY(110vh) rotate(180deg); background-color: #ff0000; box-shadow: 0 0 10px #ff0000; } to { transform: translateY(0) rotate(0); background-color: #0000ff; box-shadow: 0 0 20px #0000ff; } } @keyframes color-shift { from { filter: hue-rotate(0deg); } to { filter: hue-rotate(360deg); } } </style> </head> <body> <div class="firework"></div> </body> </html>
CSS animation - Cascading Multiple Animations
In the following example, two different animations are cascaded together in a smooth manner using the animation shorthand property.
<html> <head> <style> :root { overflow: hidden; background-color: #ff7f50; justify-content: center; align-items: center; height: 200px; } .shape { background-color: #9acd32; width: 120px; height: 120px; border-radius: 30%; animation: 2s ease-in-out 0s infinite alternate ascent, 2s linear 0s infinite alternate swing; } @keyframes ascent { from { transform: translateY(110vh); } to { transform: translateY(0); } } @keyframes swing { from { transform: translateX(90vw); } to { transform: translateX(10vw); } } </style> </head> <body> <div class="shape"></div> </body> </html>