CSS: Animation vs. Transition












121















So, I understand how to perform both CSS3 transitions and animations. What is not clear, and I've googled, is when to use which.



For example, if I want to make a ball bounce, it is clear that animation is the way to go. I could provide keyframes and the browser would do the intermediates frames and I'll have a nice animation going.



However, there are cases when a said effect can be achieved either way. A simple and common example would be implement the facebook style sliding drawer menu:



This effect can be achieved through transitions like so:



.sf-page {
-webkit-transition: -webkit-transform .2s ease-out;
}

.sf-page.out {
-webkit-transform: translateX(240px);
}


http://jsfiddle.net/NwEGz/



Or, through animations like so:



.sf-page {
-webkit-animation-duration: .4s;
-webkit-transition-timing-function: ease-out;
}

.sf-page.in {
-webkit-animation-name: sf-slidein;
-webkit-transform: translate3d(0, 0, 0);
}

.sf-page.out {
-webkit-animation-name: sf-slideout;
-webkit-transform: translateX(240px);
}

@-webkit-keyframes sf-slideout {
from { -webkit-transform: translate3d(0, 0, 0); }
to { -webkit-transform: translate3d(240px, 0, 0); }
}

@-webkit-keyframes sf-slidein {
from { -webkit-transform: translate3d(240px, 0, 0); }
to { -webkit-transform: translate3d(0, 0, 0); }
}


http://jsfiddle.net/4Z5Mr/



With HTML that looks like so:



<div class="sf-container">
<div class="sf-page in" id="content-container">
<button type="button">Click Me</button>
</div>
<div class="sf-drawer">
</div>
</div>


And, this accompanying jQuery script:



$("#content-container").click(function(){
$("#content-container").toggleClass("out");
// below is only required for css animation route
$("#content-container").toggleClass("in");
});


What I'd like to understand is what are the pros and cons of these approaches.




  1. One obvious difference is that animating is taking a whole lot more code.

  2. Animation gives better flexibility. I can have different animation for sliding out and in

  3. Is there something that can be said about performance. Do both take advantage of h/w acceleration?

  4. Which is more modern and the way going forward

  5. Anything else you could add?










share|improve this question





























    121















    So, I understand how to perform both CSS3 transitions and animations. What is not clear, and I've googled, is when to use which.



    For example, if I want to make a ball bounce, it is clear that animation is the way to go. I could provide keyframes and the browser would do the intermediates frames and I'll have a nice animation going.



    However, there are cases when a said effect can be achieved either way. A simple and common example would be implement the facebook style sliding drawer menu:



    This effect can be achieved through transitions like so:



    .sf-page {
    -webkit-transition: -webkit-transform .2s ease-out;
    }

    .sf-page.out {
    -webkit-transform: translateX(240px);
    }


    http://jsfiddle.net/NwEGz/



    Or, through animations like so:



    .sf-page {
    -webkit-animation-duration: .4s;
    -webkit-transition-timing-function: ease-out;
    }

    .sf-page.in {
    -webkit-animation-name: sf-slidein;
    -webkit-transform: translate3d(0, 0, 0);
    }

    .sf-page.out {
    -webkit-animation-name: sf-slideout;
    -webkit-transform: translateX(240px);
    }

    @-webkit-keyframes sf-slideout {
    from { -webkit-transform: translate3d(0, 0, 0); }
    to { -webkit-transform: translate3d(240px, 0, 0); }
    }

    @-webkit-keyframes sf-slidein {
    from { -webkit-transform: translate3d(240px, 0, 0); }
    to { -webkit-transform: translate3d(0, 0, 0); }
    }


    http://jsfiddle.net/4Z5Mr/



    With HTML that looks like so:



    <div class="sf-container">
    <div class="sf-page in" id="content-container">
    <button type="button">Click Me</button>
    </div>
    <div class="sf-drawer">
    </div>
    </div>


    And, this accompanying jQuery script:



    $("#content-container").click(function(){
    $("#content-container").toggleClass("out");
    // below is only required for css animation route
    $("#content-container").toggleClass("in");
    });


    What I'd like to understand is what are the pros and cons of these approaches.




    1. One obvious difference is that animating is taking a whole lot more code.

    2. Animation gives better flexibility. I can have different animation for sliding out and in

    3. Is there something that can be said about performance. Do both take advantage of h/w acceleration?

    4. Which is more modern and the way going forward

    5. Anything else you could add?










    share|improve this question



























      121












      121








      121


      42






      So, I understand how to perform both CSS3 transitions and animations. What is not clear, and I've googled, is when to use which.



      For example, if I want to make a ball bounce, it is clear that animation is the way to go. I could provide keyframes and the browser would do the intermediates frames and I'll have a nice animation going.



      However, there are cases when a said effect can be achieved either way. A simple and common example would be implement the facebook style sliding drawer menu:



      This effect can be achieved through transitions like so:



      .sf-page {
      -webkit-transition: -webkit-transform .2s ease-out;
      }

      .sf-page.out {
      -webkit-transform: translateX(240px);
      }


      http://jsfiddle.net/NwEGz/



      Or, through animations like so:



      .sf-page {
      -webkit-animation-duration: .4s;
      -webkit-transition-timing-function: ease-out;
      }

      .sf-page.in {
      -webkit-animation-name: sf-slidein;
      -webkit-transform: translate3d(0, 0, 0);
      }

      .sf-page.out {
      -webkit-animation-name: sf-slideout;
      -webkit-transform: translateX(240px);
      }

      @-webkit-keyframes sf-slideout {
      from { -webkit-transform: translate3d(0, 0, 0); }
      to { -webkit-transform: translate3d(240px, 0, 0); }
      }

      @-webkit-keyframes sf-slidein {
      from { -webkit-transform: translate3d(240px, 0, 0); }
      to { -webkit-transform: translate3d(0, 0, 0); }
      }


      http://jsfiddle.net/4Z5Mr/



      With HTML that looks like so:



      <div class="sf-container">
      <div class="sf-page in" id="content-container">
      <button type="button">Click Me</button>
      </div>
      <div class="sf-drawer">
      </div>
      </div>


      And, this accompanying jQuery script:



      $("#content-container").click(function(){
      $("#content-container").toggleClass("out");
      // below is only required for css animation route
      $("#content-container").toggleClass("in");
      });


      What I'd like to understand is what are the pros and cons of these approaches.




      1. One obvious difference is that animating is taking a whole lot more code.

      2. Animation gives better flexibility. I can have different animation for sliding out and in

      3. Is there something that can be said about performance. Do both take advantage of h/w acceleration?

      4. Which is more modern and the way going forward

      5. Anything else you could add?










      share|improve this question
















      So, I understand how to perform both CSS3 transitions and animations. What is not clear, and I've googled, is when to use which.



      For example, if I want to make a ball bounce, it is clear that animation is the way to go. I could provide keyframes and the browser would do the intermediates frames and I'll have a nice animation going.



      However, there are cases when a said effect can be achieved either way. A simple and common example would be implement the facebook style sliding drawer menu:



      This effect can be achieved through transitions like so:



      .sf-page {
      -webkit-transition: -webkit-transform .2s ease-out;
      }

      .sf-page.out {
      -webkit-transform: translateX(240px);
      }


      http://jsfiddle.net/NwEGz/



      Or, through animations like so:



      .sf-page {
      -webkit-animation-duration: .4s;
      -webkit-transition-timing-function: ease-out;
      }

      .sf-page.in {
      -webkit-animation-name: sf-slidein;
      -webkit-transform: translate3d(0, 0, 0);
      }

      .sf-page.out {
      -webkit-animation-name: sf-slideout;
      -webkit-transform: translateX(240px);
      }

      @-webkit-keyframes sf-slideout {
      from { -webkit-transform: translate3d(0, 0, 0); }
      to { -webkit-transform: translate3d(240px, 0, 0); }
      }

      @-webkit-keyframes sf-slidein {
      from { -webkit-transform: translate3d(240px, 0, 0); }
      to { -webkit-transform: translate3d(0, 0, 0); }
      }


      http://jsfiddle.net/4Z5Mr/



      With HTML that looks like so:



      <div class="sf-container">
      <div class="sf-page in" id="content-container">
      <button type="button">Click Me</button>
      </div>
      <div class="sf-drawer">
      </div>
      </div>


      And, this accompanying jQuery script:



      $("#content-container").click(function(){
      $("#content-container").toggleClass("out");
      // below is only required for css animation route
      $("#content-container").toggleClass("in");
      });


      What I'd like to understand is what are the pros and cons of these approaches.




      1. One obvious difference is that animating is taking a whole lot more code.

      2. Animation gives better flexibility. I can have different animation for sliding out and in

      3. Is there something that can be said about performance. Do both take advantage of h/w acceleration?

      4. Which is more modern and the way going forward

      5. Anything else you could add?







      css css3 css-transitions css-animations






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 14 '13 at 19:58









      Zentaurus

      5361824




      5361824










      asked Dec 14 '13 at 17:28









      Code PoetCode Poet

      5,623185490




      5,623185490
























          7 Answers
          7






          active

          oldest

          votes


















          165














          It looks like you've got a handle on how to do them, just not when to do them.



          A transition is an animation, just one that is performed between two distinct states - i.e. a start state and an end state. Like a drawer menu, the start state could be open and the end state could be closed, or vice versa.



          If you want to perform something that does not specifically involve a start state and an end state, or you need more fine grain control over the keyframes in a transition, then you've got to use an animation.






          share|improve this answer



















          • 5





            check out this article too kirupa.com/html5/css3_animations_vs_transitions.htm , it correctly points out that transitions are the way to go when doing javascript interactions.

            – Scott Jungwirth
            Jun 22 '15 at 17:27



















          33














          I'll let the definitions speak for themselves (according to Merriam-Webster):




          Transition: A movement, development, or evolution from one form, stage, or style to another



          Animation: Endowed with life or the qualities of life; full of movement




          The names appropriately fit their purposes in CSS



          So, the example you gave should use transitions because it is only a change from one state to another






          share|improve this answer































            8















            1. Animation takes a lot more code unless you're using the same transition over and over, in which case an animation would be better.



            2. You can have different effects for sliding in and out without an animation. Just have a different transition on both the original rule and the modified rule:



              .two-transitions {
              transition: all 50ms linear;
              }

              .two-transitions:hover {
              transition: all 800ms ease-out;
              }


            3. Animations are just abstractions of transitions, so if the transition is hardware accelerated, the animation will be. It makes no difference.


            4. Both are very modern.


            5. My rule of thumb is if I use the same transition three times, it should probably be an animation. This is easier to maintain and alter in the future. But if you are only using it once, it is more typing to make the animation and maybe not worth it.







            share|improve this answer


























            • I should also add that animations have keyframes, allowing you to do very complex and controlled progressions, which is kind of amazing.

              – paulcpederson
              Dec 15 '13 at 6:43



















            2














            Animations are just that - a smooth behavior of set of properties. In other words it specifies what should happen to a set of element's properties. You define an animation and describe how this set of properties should behave during the animation process.



            Transitions on the other side specify how a property (or properties) should perform their change. Each change. Setting a new value for certain property, be it with JavaScript or CSS, is always a transition, but by default it is not smooth. By setting transition in the css style you define different (smooth) way to perform these changes.



            It can be said that transitions define a default animation that should be performed every time the specified property has changed.






            share|improve this answer



















            • 1





              I disagree with this definition as both specify how and what

              – Zach Saucier
              Jul 31 '14 at 2:12



















            2














            A shorter answer, straight on point:



            Transition:




            1. Needs a triggering element (:hover, :focus etc.)

            2. Only 2 animation states (start and end)

            3. Used for simpler animations (buttons, dropdown menus and so on)

            4. Easier to create but not so many animation/effect possibilities


            Animation @keyframes:




            1. It can be used for endless animations

            2. Can set more than 2 states

            3. No boundaries


            Both use CPU acceleration for a much smoother effect.






            share|improve this answer

































              1















              Is there something that can be said about performance. Do both take
              advantage of h/w acceleration?




              In modern browsers, h/w acceleration occurs for the properties filter, opacity and transform. This is for both CSS Animations and CSS Transitions.






              share|improve this answer































                -1














                I believe CSS3 animation vs CSS3 transition will give you the answer you want.



                Basically below are some takeaways :




                1. If performance is a concern, then choose CSS3 transition.

                2. If state is to be maintained after each transition, then choose CSS3 transition.

                3. If the animation needs to be repeated, choose CSS3 animation. Because it supports animation-iteration-count.

                4. If a complicated animation is desired. Then CSS3 animation is preferred.






                share|improve this answer



















                • 3





                  #2 and #3 aren't true

                  – Zach Saucier
                  Aug 23 '15 at 2:01











                • I'm not sure how #3 is untrue? It seems a reasonable point to consider, and the animation-iteration-count seems to be a valid property: developer.mozilla.org/en-US/docs/Web/CSS/…

                  – user4275029
                  Jul 12 '17 at 13:30











                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20586143%2fcss-animation-vs-transition%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                7 Answers
                7






                active

                oldest

                votes








                7 Answers
                7






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                165














                It looks like you've got a handle on how to do them, just not when to do them.



                A transition is an animation, just one that is performed between two distinct states - i.e. a start state and an end state. Like a drawer menu, the start state could be open and the end state could be closed, or vice versa.



                If you want to perform something that does not specifically involve a start state and an end state, or you need more fine grain control over the keyframes in a transition, then you've got to use an animation.






                share|improve this answer



















                • 5





                  check out this article too kirupa.com/html5/css3_animations_vs_transitions.htm , it correctly points out that transitions are the way to go when doing javascript interactions.

                  – Scott Jungwirth
                  Jun 22 '15 at 17:27
















                165














                It looks like you've got a handle on how to do them, just not when to do them.



                A transition is an animation, just one that is performed between two distinct states - i.e. a start state and an end state. Like a drawer menu, the start state could be open and the end state could be closed, or vice versa.



                If you want to perform something that does not specifically involve a start state and an end state, or you need more fine grain control over the keyframes in a transition, then you've got to use an animation.






                share|improve this answer



















                • 5





                  check out this article too kirupa.com/html5/css3_animations_vs_transitions.htm , it correctly points out that transitions are the way to go when doing javascript interactions.

                  – Scott Jungwirth
                  Jun 22 '15 at 17:27














                165












                165








                165







                It looks like you've got a handle on how to do them, just not when to do them.



                A transition is an animation, just one that is performed between two distinct states - i.e. a start state and an end state. Like a drawer menu, the start state could be open and the end state could be closed, or vice versa.



                If you want to perform something that does not specifically involve a start state and an end state, or you need more fine grain control over the keyframes in a transition, then you've got to use an animation.






                share|improve this answer













                It looks like you've got a handle on how to do them, just not when to do them.



                A transition is an animation, just one that is performed between two distinct states - i.e. a start state and an end state. Like a drawer menu, the start state could be open and the end state could be closed, or vice versa.



                If you want to perform something that does not specifically involve a start state and an end state, or you need more fine grain control over the keyframes in a transition, then you've got to use an animation.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 15 '13 at 1:41









                AdamAdam

                28k94462




                28k94462








                • 5





                  check out this article too kirupa.com/html5/css3_animations_vs_transitions.htm , it correctly points out that transitions are the way to go when doing javascript interactions.

                  – Scott Jungwirth
                  Jun 22 '15 at 17:27














                • 5





                  check out this article too kirupa.com/html5/css3_animations_vs_transitions.htm , it correctly points out that transitions are the way to go when doing javascript interactions.

                  – Scott Jungwirth
                  Jun 22 '15 at 17:27








                5




                5





                check out this article too kirupa.com/html5/css3_animations_vs_transitions.htm , it correctly points out that transitions are the way to go when doing javascript interactions.

                – Scott Jungwirth
                Jun 22 '15 at 17:27





                check out this article too kirupa.com/html5/css3_animations_vs_transitions.htm , it correctly points out that transitions are the way to go when doing javascript interactions.

                – Scott Jungwirth
                Jun 22 '15 at 17:27













                33














                I'll let the definitions speak for themselves (according to Merriam-Webster):




                Transition: A movement, development, or evolution from one form, stage, or style to another



                Animation: Endowed with life or the qualities of life; full of movement




                The names appropriately fit their purposes in CSS



                So, the example you gave should use transitions because it is only a change from one state to another






                share|improve this answer




























                  33














                  I'll let the definitions speak for themselves (according to Merriam-Webster):




                  Transition: A movement, development, or evolution from one form, stage, or style to another



                  Animation: Endowed with life or the qualities of life; full of movement




                  The names appropriately fit their purposes in CSS



                  So, the example you gave should use transitions because it is only a change from one state to another






                  share|improve this answer


























                    33












                    33








                    33







                    I'll let the definitions speak for themselves (according to Merriam-Webster):




                    Transition: A movement, development, or evolution from one form, stage, or style to another



                    Animation: Endowed with life or the qualities of life; full of movement




                    The names appropriately fit their purposes in CSS



                    So, the example you gave should use transitions because it is only a change from one state to another






                    share|improve this answer













                    I'll let the definitions speak for themselves (according to Merriam-Webster):




                    Transition: A movement, development, or evolution from one form, stage, or style to another



                    Animation: Endowed with life or the qualities of life; full of movement




                    The names appropriately fit their purposes in CSS



                    So, the example you gave should use transitions because it is only a change from one state to another







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 15 '13 at 1:36









                    Zach SaucierZach Saucier

                    16.6k74894




                    16.6k74894























                        8















                        1. Animation takes a lot more code unless you're using the same transition over and over, in which case an animation would be better.



                        2. You can have different effects for sliding in and out without an animation. Just have a different transition on both the original rule and the modified rule:



                          .two-transitions {
                          transition: all 50ms linear;
                          }

                          .two-transitions:hover {
                          transition: all 800ms ease-out;
                          }


                        3. Animations are just abstractions of transitions, so if the transition is hardware accelerated, the animation will be. It makes no difference.


                        4. Both are very modern.


                        5. My rule of thumb is if I use the same transition three times, it should probably be an animation. This is easier to maintain and alter in the future. But if you are only using it once, it is more typing to make the animation and maybe not worth it.







                        share|improve this answer


























                        • I should also add that animations have keyframes, allowing you to do very complex and controlled progressions, which is kind of amazing.

                          – paulcpederson
                          Dec 15 '13 at 6:43
















                        8















                        1. Animation takes a lot more code unless you're using the same transition over and over, in which case an animation would be better.



                        2. You can have different effects for sliding in and out without an animation. Just have a different transition on both the original rule and the modified rule:



                          .two-transitions {
                          transition: all 50ms linear;
                          }

                          .two-transitions:hover {
                          transition: all 800ms ease-out;
                          }


                        3. Animations are just abstractions of transitions, so if the transition is hardware accelerated, the animation will be. It makes no difference.


                        4. Both are very modern.


                        5. My rule of thumb is if I use the same transition three times, it should probably be an animation. This is easier to maintain and alter in the future. But if you are only using it once, it is more typing to make the animation and maybe not worth it.







                        share|improve this answer


























                        • I should also add that animations have keyframes, allowing you to do very complex and controlled progressions, which is kind of amazing.

                          – paulcpederson
                          Dec 15 '13 at 6:43














                        8












                        8








                        8








                        1. Animation takes a lot more code unless you're using the same transition over and over, in which case an animation would be better.



                        2. You can have different effects for sliding in and out without an animation. Just have a different transition on both the original rule and the modified rule:



                          .two-transitions {
                          transition: all 50ms linear;
                          }

                          .two-transitions:hover {
                          transition: all 800ms ease-out;
                          }


                        3. Animations are just abstractions of transitions, so if the transition is hardware accelerated, the animation will be. It makes no difference.


                        4. Both are very modern.


                        5. My rule of thumb is if I use the same transition three times, it should probably be an animation. This is easier to maintain and alter in the future. But if you are only using it once, it is more typing to make the animation and maybe not worth it.







                        share|improve this answer
















                        1. Animation takes a lot more code unless you're using the same transition over and over, in which case an animation would be better.



                        2. You can have different effects for sliding in and out without an animation. Just have a different transition on both the original rule and the modified rule:



                          .two-transitions {
                          transition: all 50ms linear;
                          }

                          .two-transitions:hover {
                          transition: all 800ms ease-out;
                          }


                        3. Animations are just abstractions of transitions, so if the transition is hardware accelerated, the animation will be. It makes no difference.


                        4. Both are very modern.


                        5. My rule of thumb is if I use the same transition three times, it should probably be an animation. This is easier to maintain and alter in the future. But if you are only using it once, it is more typing to make the animation and maybe not worth it.








                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Dec 15 '13 at 1:04









                        m59

                        36.9k13100118




                        36.9k13100118










                        answered Dec 14 '13 at 19:42









                        paulcpedersonpaulcpederson

                        487412




                        487412













                        • I should also add that animations have keyframes, allowing you to do very complex and controlled progressions, which is kind of amazing.

                          – paulcpederson
                          Dec 15 '13 at 6:43



















                        • I should also add that animations have keyframes, allowing you to do very complex and controlled progressions, which is kind of amazing.

                          – paulcpederson
                          Dec 15 '13 at 6:43

















                        I should also add that animations have keyframes, allowing you to do very complex and controlled progressions, which is kind of amazing.

                        – paulcpederson
                        Dec 15 '13 at 6:43





                        I should also add that animations have keyframes, allowing you to do very complex and controlled progressions, which is kind of amazing.

                        – paulcpederson
                        Dec 15 '13 at 6:43











                        2














                        Animations are just that - a smooth behavior of set of properties. In other words it specifies what should happen to a set of element's properties. You define an animation and describe how this set of properties should behave during the animation process.



                        Transitions on the other side specify how a property (or properties) should perform their change. Each change. Setting a new value for certain property, be it with JavaScript or CSS, is always a transition, but by default it is not smooth. By setting transition in the css style you define different (smooth) way to perform these changes.



                        It can be said that transitions define a default animation that should be performed every time the specified property has changed.






                        share|improve this answer



















                        • 1





                          I disagree with this definition as both specify how and what

                          – Zach Saucier
                          Jul 31 '14 at 2:12
















                        2














                        Animations are just that - a smooth behavior of set of properties. In other words it specifies what should happen to a set of element's properties. You define an animation and describe how this set of properties should behave during the animation process.



                        Transitions on the other side specify how a property (or properties) should perform their change. Each change. Setting a new value for certain property, be it with JavaScript or CSS, is always a transition, but by default it is not smooth. By setting transition in the css style you define different (smooth) way to perform these changes.



                        It can be said that transitions define a default animation that should be performed every time the specified property has changed.






                        share|improve this answer



















                        • 1





                          I disagree with this definition as both specify how and what

                          – Zach Saucier
                          Jul 31 '14 at 2:12














                        2












                        2








                        2







                        Animations are just that - a smooth behavior of set of properties. In other words it specifies what should happen to a set of element's properties. You define an animation and describe how this set of properties should behave during the animation process.



                        Transitions on the other side specify how a property (or properties) should perform their change. Each change. Setting a new value for certain property, be it with JavaScript or CSS, is always a transition, but by default it is not smooth. By setting transition in the css style you define different (smooth) way to perform these changes.



                        It can be said that transitions define a default animation that should be performed every time the specified property has changed.






                        share|improve this answer













                        Animations are just that - a smooth behavior of set of properties. In other words it specifies what should happen to a set of element's properties. You define an animation and describe how this set of properties should behave during the animation process.



                        Transitions on the other side specify how a property (or properties) should perform their change. Each change. Setting a new value for certain property, be it with JavaScript or CSS, is always a transition, but by default it is not smooth. By setting transition in the css style you define different (smooth) way to perform these changes.



                        It can be said that transitions define a default animation that should be performed every time the specified property has changed.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Mar 11 '14 at 21:23









                        Jonan GeorgievJonan Georgiev

                        461510




                        461510








                        • 1





                          I disagree with this definition as both specify how and what

                          – Zach Saucier
                          Jul 31 '14 at 2:12














                        • 1





                          I disagree with this definition as both specify how and what

                          – Zach Saucier
                          Jul 31 '14 at 2:12








                        1




                        1





                        I disagree with this definition as both specify how and what

                        – Zach Saucier
                        Jul 31 '14 at 2:12





                        I disagree with this definition as both specify how and what

                        – Zach Saucier
                        Jul 31 '14 at 2:12











                        2














                        A shorter answer, straight on point:



                        Transition:




                        1. Needs a triggering element (:hover, :focus etc.)

                        2. Only 2 animation states (start and end)

                        3. Used for simpler animations (buttons, dropdown menus and so on)

                        4. Easier to create but not so many animation/effect possibilities


                        Animation @keyframes:




                        1. It can be used for endless animations

                        2. Can set more than 2 states

                        3. No boundaries


                        Both use CPU acceleration for a much smoother effect.






                        share|improve this answer






























                          2














                          A shorter answer, straight on point:



                          Transition:




                          1. Needs a triggering element (:hover, :focus etc.)

                          2. Only 2 animation states (start and end)

                          3. Used for simpler animations (buttons, dropdown menus and so on)

                          4. Easier to create but not so many animation/effect possibilities


                          Animation @keyframes:




                          1. It can be used for endless animations

                          2. Can set more than 2 states

                          3. No boundaries


                          Both use CPU acceleration for a much smoother effect.






                          share|improve this answer




























                            2












                            2








                            2







                            A shorter answer, straight on point:



                            Transition:




                            1. Needs a triggering element (:hover, :focus etc.)

                            2. Only 2 animation states (start and end)

                            3. Used for simpler animations (buttons, dropdown menus and so on)

                            4. Easier to create but not so many animation/effect possibilities


                            Animation @keyframes:




                            1. It can be used for endless animations

                            2. Can set more than 2 states

                            3. No boundaries


                            Both use CPU acceleration for a much smoother effect.






                            share|improve this answer















                            A shorter answer, straight on point:



                            Transition:




                            1. Needs a triggering element (:hover, :focus etc.)

                            2. Only 2 animation states (start and end)

                            3. Used for simpler animations (buttons, dropdown menus and so on)

                            4. Easier to create but not so many animation/effect possibilities


                            Animation @keyframes:




                            1. It can be used for endless animations

                            2. Can set more than 2 states

                            3. No boundaries


                            Both use CPU acceleration for a much smoother effect.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Jan 23 at 8:37









                            Pang

                            6,9161664102




                            6,9161664102










                            answered Jan 14 at 11:17









                            GrecAGrecA

                            214




                            214























                                1















                                Is there something that can be said about performance. Do both take
                                advantage of h/w acceleration?




                                In modern browsers, h/w acceleration occurs for the properties filter, opacity and transform. This is for both CSS Animations and CSS Transitions.






                                share|improve this answer




























                                  1















                                  Is there something that can be said about performance. Do both take
                                  advantage of h/w acceleration?




                                  In modern browsers, h/w acceleration occurs for the properties filter, opacity and transform. This is for both CSS Animations and CSS Transitions.






                                  share|improve this answer


























                                    1












                                    1








                                    1








                                    Is there something that can be said about performance. Do both take
                                    advantage of h/w acceleration?




                                    In modern browsers, h/w acceleration occurs for the properties filter, opacity and transform. This is for both CSS Animations and CSS Transitions.






                                    share|improve this answer














                                    Is there something that can be said about performance. Do both take
                                    advantage of h/w acceleration?




                                    In modern browsers, h/w acceleration occurs for the properties filter, opacity and transform. This is for both CSS Animations and CSS Transitions.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 22 '18 at 6:01









                                    Eric WilligersEric Willigers

                                    93968




                                    93968























                                        -1














                                        I believe CSS3 animation vs CSS3 transition will give you the answer you want.



                                        Basically below are some takeaways :




                                        1. If performance is a concern, then choose CSS3 transition.

                                        2. If state is to be maintained after each transition, then choose CSS3 transition.

                                        3. If the animation needs to be repeated, choose CSS3 animation. Because it supports animation-iteration-count.

                                        4. If a complicated animation is desired. Then CSS3 animation is preferred.






                                        share|improve this answer



















                                        • 3





                                          #2 and #3 aren't true

                                          – Zach Saucier
                                          Aug 23 '15 at 2:01











                                        • I'm not sure how #3 is untrue? It seems a reasonable point to consider, and the animation-iteration-count seems to be a valid property: developer.mozilla.org/en-US/docs/Web/CSS/…

                                          – user4275029
                                          Jul 12 '17 at 13:30
















                                        -1














                                        I believe CSS3 animation vs CSS3 transition will give you the answer you want.



                                        Basically below are some takeaways :




                                        1. If performance is a concern, then choose CSS3 transition.

                                        2. If state is to be maintained after each transition, then choose CSS3 transition.

                                        3. If the animation needs to be repeated, choose CSS3 animation. Because it supports animation-iteration-count.

                                        4. If a complicated animation is desired. Then CSS3 animation is preferred.






                                        share|improve this answer



















                                        • 3





                                          #2 and #3 aren't true

                                          – Zach Saucier
                                          Aug 23 '15 at 2:01











                                        • I'm not sure how #3 is untrue? It seems a reasonable point to consider, and the animation-iteration-count seems to be a valid property: developer.mozilla.org/en-US/docs/Web/CSS/…

                                          – user4275029
                                          Jul 12 '17 at 13:30














                                        -1












                                        -1








                                        -1







                                        I believe CSS3 animation vs CSS3 transition will give you the answer you want.



                                        Basically below are some takeaways :




                                        1. If performance is a concern, then choose CSS3 transition.

                                        2. If state is to be maintained after each transition, then choose CSS3 transition.

                                        3. If the animation needs to be repeated, choose CSS3 animation. Because it supports animation-iteration-count.

                                        4. If a complicated animation is desired. Then CSS3 animation is preferred.






                                        share|improve this answer













                                        I believe CSS3 animation vs CSS3 transition will give you the answer you want.



                                        Basically below are some takeaways :




                                        1. If performance is a concern, then choose CSS3 transition.

                                        2. If state is to be maintained after each transition, then choose CSS3 transition.

                                        3. If the animation needs to be repeated, choose CSS3 animation. Because it supports animation-iteration-count.

                                        4. If a complicated animation is desired. Then CSS3 animation is preferred.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Jun 17 '15 at 15:35









                                        PixelsTechPixelsTech

                                        1,82812327




                                        1,82812327








                                        • 3





                                          #2 and #3 aren't true

                                          – Zach Saucier
                                          Aug 23 '15 at 2:01











                                        • I'm not sure how #3 is untrue? It seems a reasonable point to consider, and the animation-iteration-count seems to be a valid property: developer.mozilla.org/en-US/docs/Web/CSS/…

                                          – user4275029
                                          Jul 12 '17 at 13:30














                                        • 3





                                          #2 and #3 aren't true

                                          – Zach Saucier
                                          Aug 23 '15 at 2:01











                                        • I'm not sure how #3 is untrue? It seems a reasonable point to consider, and the animation-iteration-count seems to be a valid property: developer.mozilla.org/en-US/docs/Web/CSS/…

                                          – user4275029
                                          Jul 12 '17 at 13:30








                                        3




                                        3





                                        #2 and #3 aren't true

                                        – Zach Saucier
                                        Aug 23 '15 at 2:01





                                        #2 and #3 aren't true

                                        – Zach Saucier
                                        Aug 23 '15 at 2:01













                                        I'm not sure how #3 is untrue? It seems a reasonable point to consider, and the animation-iteration-count seems to be a valid property: developer.mozilla.org/en-US/docs/Web/CSS/…

                                        – user4275029
                                        Jul 12 '17 at 13:30





                                        I'm not sure how #3 is untrue? It seems a reasonable point to consider, and the animation-iteration-count seems to be a valid property: developer.mozilla.org/en-US/docs/Web/CSS/…

                                        – user4275029
                                        Jul 12 '17 at 13:30


















                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f20586143%2fcss-animation-vs-transition%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Paul Cézanne

                                        UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

                                        Angular material date-picker (MatDatepicker) auto completes the date on focus out