Code Skiller logoCB Logo
Logo LearnLearnLogo PracticePracticeLogo HireHireLogo IDEIDE

CSS Animations

User image

Published by

sanya sanya

Published at: 28th Jul, 2023
2.045 mins read

CSS animations allow you to create dynamic and interactive effects on webpages. They can be used to bring elements to life, add visual interest, and enhance user experience.

The overview of the key concepts and properties related to CSS animations in descriptive manner is described further.

@keyframes

@keyframes is a CSS rule that defines the animation sequence. It specifies a set of styles at various points in the animation timeline.

Each style is associated with a percentage value (0% to 100%) or a keyword (from for 0% and to for 100%).

animation-name

The animation-name property specifies the name of the @keyframes animation to apply to an element.

.element { animation-name: slide-in; }

animation-duration

The animation-duration property sets the duration of the animation in seconds or milliseconds.

.element { animation-duration: 1s; }

animation-delay

The animation-delay property specifies a delay before the animation starts.

animation-delay: 0.5s;



animation-timing-function

The animation-timing-function property defines the speed curve or timing function of the animation. It determines how the intermediate styles are interpolated over the animation duration.

Common timing functions include linear, ease, ease-in, ease-out, and ease-in-out.

animation-timing-function: ease;

animation-iteration-count

The animation-iteration-count property is used to determine the number of times the animation should repeat. You can set a specific number (2, 3, etc.) or use infinite for continuous looping.

animation-iteration-count: infinite;

animation-direction

The animation-direction property controls the direction of the animation. Values include normal (forward), reverse (backward), alternate (forward, then backward), and alternate-reverse (backward, then forward).

animation-fill-mode

The animation-fill-mode property specifies how the element styles should be applied before and after the animation.

Values include none (no styles applied), forwards (apply the styles from the last keyframe after the animation ends), backwards (apply the styles from the first keyframe before the animation starts), and both (apply styles from both the first and last keyframes).

transition

Although not specifically an animation property, the transition property allows for smooth transitions between two or more CSS property values.

It specifies the property, duration, timing function, and delay for the transition effect.

To use CSS animations, we typically define the animation using @keyframes, apply it to an element using animation-name, and configure other properties like animation-duration, animation-timing-function, and animation-iteration-count as needed.

@keyframes slide-in { from { transform: translateX(-100%); } to { transform: translateX(0); } }
.box { width: 200px; height: 200px; background-color: blue; animation-name: slide-in; animation-duration: 1s; animation-timing-function: ease; animation-delay: 0.5s; animation-iteration-count: infinite; }

Library

WEB DEVELOPMENT

Basic

HTML - Hyper Text Markup Language

CSS - Cascading Style Sheets

Cascading Style Sheets (CSS)

Selectors and Combinators

CSS Transforms

Units

CSS Icons and Colors

CSS Borders

CSS Margin

CSS Padding

CSS Dimensions

CSS Box Model

CSS Background

Pseudo Classes in CSS

CSS Positions

CSS Flexbox

Responsiveness in CSS

CSS Transitions

CSS Animations

Other CSS Properties

Var()

CSS Frameworks

CSS Grids

CSS Display Properties

JavaScript

Frontend

Backend

Interview Questions

FAANG QUESTIONS

On this page

@keyframes

animation-name

animation-duration

animation-delay

animation-timing-function

animation-iteration-count

animation-direction

animation-fill-mode

transition