HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
  • Insights
  • Verify Certificate
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials

HTML5andCSS3.org helps developers learn modern frontend skills with practical tutorials, production-ready snippets, and fast web tools built for everyday coding.

Quick Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Copyright
  • Disclaimer

Top Tools

  • Try It Editor
  • JSON Formatter
  • CSS Minifier
  • HTML Minifier
  • Base64 Encoder / Decoder

Contact

  • business@html5andcss3.org
Newsletter

Learn at your own pace, practice with useful tools, and build websites you're proud of.

© 2011-2026 html5andcss3.org. All rights reserved.

How to Use

CSS Tutorial

CSS Introduction

What is CSSCSS SyntaxHow to Add CSSCSS Comments

CSS Foundations

Cascade & InheritanceCSS SpecificityCSS UnitsBox SizingCSS VariablesCSS Math Functions

CSS Selectors

CSS Element SelectorCSS Class SelectorCSS ID SelectorCSS Universal SelectorCSS Group SelectorCSS CombinatorsCSS Attribute SelectorsCSS Pseudo ClassesCSS Pseudo Elements

CSS Colors and Backgrounds

CSS ColorsCSS HEX ColorsCSS RGB ColorsModern ColorsCSS Background ColorCSS Background ImageLayered Backgrounds

CSS Text & Fonts

CSS Text ColorCSS Text AlignmentCSS Text DecorationCSS Font FamilyCSS Font SizeWeb Fonts & TypographyText Wrapping

CSS Box Model

CSS MarginCSS PaddingCSS BorderCSS OutlineCSS Width and Height

CSS Layout

Normal FlowCSS DisplayCSS PositionAnchor PositioningCSS FloatCSS OverflowCSS Z-indexIntrinsic SizingAspect Ratio & Object FitMulti-column Layout

CSS Flexbox

Flex ContainerFlex DirectionJustify ContentAlign ItemsFlex WrapFlex Item Sizing

CSS Grid

CSS Grid ContainerCSS Grid ColumnsCSS Grid RowsCSS Grid GapCSS Grid Layout ExampleGrid PlacementGrid AreasCSS Subgrid

CSS Lists, Tables & Forms

CSS ListsCSS TablesCSS Form StylingCSS Input Fields

CSS Effects

CSS ShadowsCSS GradientsCSS FiltersCSS OpacityClipping & MaskingBlending & BackdropScroll Snap

CSS Animations & Transitions

CSS TransformCSS 2D TransformCSS 3D TransformCSS TransitionsEntry & Exit TransitionsCSS AnimationsScroll AnimationsView TransitionsMotion Paths

CSS Responsive Design

CSS Media QueriesResponsive LayoutMobile First DesignContainer QueriesPreference Media QueriesFeature Queries

Modern CSS Authoring

Cascade LayersNesting & ScopeLogical PropertiesGenerated Content

CSS Accessibility

Accessible CSSCSS ThemingModern Form StylingCSS User Interface

CSS Output & Performance

Print StylesCSS PerformanceCSS ArchitectureDebugging CSS

CSS Reference

CSS At-rulesCSS FunctionsCSS Tutorial PDF

CSS Projects

Responsive CSS Project
  1. Home
  2. /
  3. Tutorials
  4. /
  5. CSS Tutorial
  6. /
  7. CSS Animations

CSS Animations & Transitions

CSS Animations

CSS Animations allow elements to change styles automatically over time without requiring JavaScript.

Unlike transitions, which require a state change such as hover, animations can run automatically and continuously. The supporting concepts are explained in Scroll Animations and View Transitions.

CSS Animations are commonly used for:

  • Loading indicators
  • Bouncing buttons
  • Image sliders
  • Attention-grabbing effects
  • Interactive UI elements

Animations are created using:

  • @keyframes
  • Animation properties

Syntax

Step 1: Create Keyframes

Create Keyframes

css

@keyframes animation-name {
    from {
        property: value;
    }
    to {
        property: value;
    }
}

Step 2: Apply Animation

Apply Animation

css

selector {
    animation: animation-name duration;
}

Animation Example

css

@keyframes moveBox {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(200px);
    }
}
.box {
    animation: moveBox 2s;
}

Moves the element 200px to the right over 2 seconds.

Attributes

PropertyDescriptionExample
animation-nameSpecifies keyframe nameanimation-name: slide;
animation-durationSets animation lengthanimation-duration: 2s;
animation-delayDelays animation startanimation-delay: 1s;
animation-iteration-countSets repeat countanimation-iteration-count: infinite;
animation-directionControls animation directionanimation-direction: alternate;

Compose animations that affect the same property

When multiple animations target the same property, animation-composition controls whether a later effect replaces, adds to, or accumulates with the underlying value. Additive composition is especially useful when separate animations contribute independent transforms, but the final result should be tested because composition follows each property's animation type.

Focused example

css

.badge {
  animation:
    drift 2s infinite alternate,
    pulse 900ms infinite alternate;
  animation-composition: add, replace;
}

@keyframes drift {
  to { transform: translateX(2rem); }
}

@keyframes pulse {
  to { opacity: 0.55; }
}

Example

CSS Animations Complete Example

html

<!DOCTYPE html>
<html>
<head>
    <title>CSS Animation Example</title>
    <style>
        @keyframes bounce {
            0% {
                transform: translateY(0);
            }
            50% {
                transform: translateY(-50px);
            }
            100% {
                transform: translateY(0);
            }
        }
        .ball {
            width: 100px;
            height: 100px;
            background-color: lightblue;
            border-radius: 50%;
            animation: bounce 2s infinite;
        }
    </style>
</head>
<body>
    <div class="ball"></div>
</body>
</html>

Output

Browser Output

css

A blue circular element will appear
The circle will continuously move up and down
The animation will repeat forever
The movement will appear smooth and automatic

Browser Support

Feature
Chrome
Edge
Firefox
Safari
animation4312169
animation-composition11211211516

Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8.

Notes

Using Percentage Keyframes

Using Percentage Keyframes

css

@keyframes fadeIn {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

Creates a fade-in effect.

Infinite Animation

Infinite Animation

css

animation-iteration-count: infinite;

Repeats forever.

Alternate Direction

Alternate Direction

css

animation-direction: alternate;

Plays forward and then backward.

Delay Animation

Delay Animation

css

animation-delay: 2s;

Starts after 2 seconds.

Shorthand Syntax

Shorthand Syntax

css

animation:
    bounce
    2s
    ease
    infinite;

Common Animation Properties

PropertyPurpose
animation-nameSelect keyframes
animation-durationSet speed
animation-delayDelay start
animation-iteration-countRepeat animation
animation-directionControl direction

Conclusion

CSS Animations provide powerful tools for creating engaging and interactive web experiences. By combining @keyframes with animation properties, you can create smooth movements, visual effects, and dynamic interfaces without using JavaScript.

PreviousEntry & Exit TransitionsNextScroll Animations