CSS | animation-direction Property

The animation-direction property in CSS is used to define the direction of animation. The direction of animation should be forwards, backwards or in alternate cycles.

Syntax:

animation-direction: normal|reverse|alternate|alternate-reverse|initial|inherit;

Property Value: The animation-direction property are listed below:

  • normal: This animation property play the animation forward. It is the default value.

    Syntax:

    animation-direction: normal; 

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html> 
    <html
        <head
            <style
                body {
                    text-align:center;
                }
                h1 {
                    color:green;
                }
                h3 { 
                    width: 100%; 
                    animation-name: text; 
                    animation-duration: 2s; 
                    animation-iteration-count: infinite; 
                
                #one { 
                    animation-direction: normal; 
                
                @keyframes text { 
                    from { 
                        margin-left: 60%; 
                    
                    to { 
                        margin-left: 0%; 
                    
                
            </style
        </head
        <body
            <h1>GeeksforGeeks</h1
            <h2>animation-direction property</h2
            <h3 id="one">This text is normal.</h3
        </body
    </html>                                     

    chevron_right

    
    

    Output:

  • reverse: This animation property play the animation in the reverse direction.

    Syntax:

    animation-direction: reverse;

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html> 
    <html
        <head
            <style
                body {
                    text-align:center;
                }
                h1 {
                    color:green;
                }
                h3 { 
                    width: 100%; 
                    animation-name: text; 
                    animation-duration: 2s; 
                    animation-iteration-count: infinite; 
                
                #one { 
                    animation-direction: reverse; 
                
                @keyframes text { 
                    from { 
                        margin-left: 60%; 
                    
                    to { 
                        margin-left: 0%; 
                    
                
            </style
        </head
        <body
            <h1>GeeksforGeeks</h1
            <h2>animation-direction property</h2
            <h3 id="one">This text is reverse.</h3
        </body
    </html>                                     

    chevron_right

    
    

    Output:

  • alternate: This animation property play the animation forwards first, and then backwards.

    Syntax:

    animation-direction: alternate; 

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html> 
    <html
        <head
            <style
                body {
                    text-align:center;
                }
                h1 {
                    color:green;
                }
                h3 { 
                    width: 100%; 
                    animation-name: text; 
                    animation-duration: 2s; 
                    animation-iteration-count: infinite; 
                
                #one { 
                    animation-direction: alternate; 
                
                @keyframes text { 
                    from { 
                        margin-left: 60%; 
                    
                    to { 
                        margin-left: 0%; 
                    
                
            </style
        </head
        <body
            <h1>GeeksforGeeks</h1
            <h2>animation-direction property</h2
            <h3 id="one">This text is alternate.</h3
        </body
    </html>                                     

    chevron_right

    
    

    Output:

  • alternate-reverse: This animation property play animation backwards first, and then forwards.

    Syntax:

    animation-direction: alternate-reverse;

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html> 
    <html
        <head
            <style
                body {
                    text-align:center;
                }
                h1 {
                    color:green;
                }
                h3 { 
                    width: 100%; 
                    animation-name: text; 
                    animation-duration: 2s; 
                    animation-iteration-count: infinite; 
                
                #one { 
                    animation-direction: alternate-reverse;
                
                @keyframes text { 
                    from { 
                        margin-left: 60%; 
                    
                    to { 
                        margin-left: 0%; 
                    
                
            </style
        </head
        <body
            <h1>GeeksforGeeks</h1
            <h2>animation-direction property</h2
            <h3 id="one">This text is alternate-reverse.</h3
        </body
    </html>                                     

    chevron_right

    
    

    Output:

  • initial: This property is used to set the animation property to its default value.
  • inherit: This property is used to inherits the animation property from its parent element.

Supported Browser: The browser supported by animation-direction are listed below:

  • Google Chrome 43.0
  • Internet Explorer 10.0
  • Firefox 16.0
  • Safari 9.0
  • Opera 30.0


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.