jQuery animate() Method

Last Updated:

jQuery animate() Method

The jQuery animate() method performs a custom animation of a set of CSS properties.

Note: All animated properties should be animated to a single numeric value. For example, width, height, margin, or left can be animated but background-color cannot be animated.

Exemption: String values "show", "hide" and "toggle" can also be animated.


HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style> div{ width: 100px; height: 100px; background: #f69d3c; margin-bottom: 10px; line-height: 6; text-align: center; } </style> </head> <body> <h1>jQuery animate() Method</h1> <div>Div</div> <button id="myAnimate">Animate</button> <button id="myStop">Stop</button> <script> $(document).ready(function(){ $("#myAnimate").click(function(){ $("div").animate({width: 200}, 2000); }); $("#myStop").click(function(){ $("div").stop(); }); }); </script> </body> </html>


$(selector).animate({styles},speed, easing, callback);

Parameter Values

{styles} Required Specifies css styles for the element.
Note: Styles should in camelCase. For example
background-color = backgroundColor
line-height = lineHeight
speed Optional Specifies the speed of the animation effect.
Default value is 400 milliseconds.
Possible values are
  • "slow"
  • "fast"
  • milliseconds
easing Optional Specifies the easing function to use for the transition.
Default value is "swing"
Possible values are
  • "swing"
  • "linear"
callback Optional Specifies a function to be called once the animate() method is completed.

Browser Support

Browsergoogle chromesafarifirefoxinternet Exploreredgeoperagoogle chromesafarifirefoxedgeoperaandroid webviewsamsung internet

Share this Page

Meet the Author