- 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-duration Property
The CSS property animation-duration defines how long an animation takes to complete a single cycle.
The shorthand property animation is often convenient to use, as it allows all animation properties to be set at the same time.
Possible Value
The CSS property animation-duration can have following value:
<time> - The duration of an animation that runs through a complete cycle can be specified in either seconds (s) or milliseconds (ms). It's important that the value is a positive number or zero, and specifying the unit is mandatory.
If no value is specified, the default value 0s is used so that the animation can be continued (triggering the animationStart and animationEnd events).
Whether the animation is visible with a duration of 0s depends on the animation-fill-mode value, which is described below:
The initial frame of the animation, as determined by animation-direction, will be displayed during the animation-delay countdown, if animation-fill-mode is set to backwards or both.
The last frame of the animation will be displayed, as determined by animation-direction, when the animation-delay expires if animation-fill-mode is set to forwards or both.
The animation will not be displayed if animation-fill-mode is set to none.
Note: The declaration gets ignored, when negative value is passed, as it is invalid.
Note: When multiple comma-separated values on an animation-* property is specified, the values are applied to the animations in the order in which the animation-names appear.
Note: While defining the CSS scroll-driven animations, the value of animation-iteration-count determines the number of times the animation is repeated over the course of timeline's progress. In case no value is specified for animation-iteration-count, the animation is executed only once. infinte is a valid value, but may result in an unworkable animation in case of CSS scroll-driven animation.
Syntax
animation-duration = <time [0s,∞]>#
Applies To
All the HTML elements, ::before and ::after pseudo-elements.
CSS animation-duration - Basic Example
The following example demonstrates how to create a simple animation with a specified duration using the animation-duration property.
In this example, we have a red box that moves horizontally from left to right and then back to the left.
The animation-duration property is used to specify the duration of the animation in seconds or milliseconds.
Here, we have set the duration to 2 seconds (animation-duration: 2s;).
<html> <head> <style> .box { width: 100px; height: 100px; background-color: red; position: relative; animation-name: move; animation-duration: 4s; animation-iteration-count: infinite; animation-direction: alternate; } @keyframes move { 0% { left: 0; } 100% { left: 400px; } } </style> </head> <body> <div class="box"></div> </body> </html>