jQuery .animate() Custom CSS Animations

Beginner
5 min read
Updated: Nov 2026
3 examples
Effects

Definition

.animate() (since jQuery 1.0) performs a custom animation of numeric CSS properties on matched elements. You pass a map of targets; jQuery tweens from the current values to those targets. Returns the jQuery object for chaining.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("#box").animate({ width: "70%", opacity: 0.4 }, 1500);
$("#box").animate({ left: "+=50px" }, "slow");
$("#box").animate({ height: "toggle" }, { duration: 400, easing: "linear" });

// Numeric props only · does not auto-show hidden elements
// Queued by default · queue:false runs in parallel
CallWhat it does
.animate() Custom CSS AnimationsLearn jQuery .animate(): animate numeric CSS properties since 1.0, relative +=/-= values, queue:false parallel runs, step sync, show/hide/toggle keywords, and compare with fadeIn, slideUp, .css(), and .stop().

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select the target with jQuery ($("#box")).
Step 2If it may be hidden, call .show() first when you need it visible.
Step 3Call .animate({ prop: value, … }, duration) (or the options form).

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

Example 1 — Multi-Property Animation

From the jQuery docs: animate several numeric CSS properties in one call.

jQuery
$("#go").on("click", function () {
  $("#block").animate({
    width: "70%",
    opacity: 0.4,
    marginLeft: "0.6in",
    fontSize: "3em",
    borderWidth: "10px"
  }, 1500);
});
Try It Yourself

How It Works

  1. Map. One object lists every property to change.
  2. Tween. jQuery interpolates from current values to each target.
  3. Duration. 1500 is milliseconds for the whole run.

Example 2 — Relative += / -=

Move left or right from the current position — each click queues on the fx queue.

jQuery
$("#right").on("click", function () {
  $(".block").animate({ left: "+=50px" }, "slow");
});

$("#left").on("click", function () {
  $(".block").animate({ left: "-=50px" }, "slow");
});
Try It Yourself

How It Works

  1. Relative. += / -= add or subtract from the current value.
  2. Position. left needs a non-static positioned element.
  3. Queue. Default queue: true stacks rapid clicks.

Example 3 — queue: false vs Queued

Block1 starts width immediately in parallel; Block2 runs three steps one after another.

jQuery
$("#go1").on("click", function () {
  $("#block1")
    .animate({ width: "90%" }, { queue: false, duration: 3000 })
    .animate({ fontSize: "24px" }, 1500)
    .animate({ borderRightWidth: "15px" }, 1500);
});

$("#go2").on("click", function () {
  $("#block2")
    .animate({ width: "90%" }, 1000)
    .animate({ fontSize: "24px" }, 1000)
    .animate({ borderLeftWidth: "15px" }, 1000);
});
Try It Yourself

How It Works

  1. Parallel. queue: false starts width without waiting on the fx queue.
  2. Still queued. Later chained calls without queue: false enqueue normally.
  3. Serial. Block2’s three animates wait for each other.

Frequently Asked Questions

.animate() runs a custom animation on matched elements by gradually changing numeric CSS properties toward target values. Unlike .fadeIn() or .slideUp(), it does not automatically show hidden elements — you choose exactly which properties move and for how long.
1) .animate(properties [, duration] [, easing] [, complete]) — positional duration, easing, and complete callback. 2) .animate(properties, options) — an options object with duration, easing, queue, specialEasing, step, progress, complete, start, done, fail, and always.
Basic jQuery animates numeric properties such as width, height, left, opacity, and scrollTop. Colors need the jQuery Color plugin or jQuery UI. Prefer longhand names like fontSize or borderWidth over shorthand font or border.
By default queue is true, so each .animate() waits on the fx effects queue. queue: false starts that animation immediately without waiting for prior queued effects. Later chained .animate() calls still enqueue unless they also set queue: false.
step fires on each animation frame for every animated property on every element. It receives now (current numeric value) and fx (tween object with elem, prop, start, end). Use it to sync other elements or build custom mid-flight behavior.
When a property value starts with += or -=, jQuery computes the target from the current value. { left: "+=50px" } moves 50px right; { left: "-=50px" } moves 50px left. Chained relative moves queue naturally — each step runs after the previous one finishes.

Next: .delay() Pause Between Queued Effects

Insert a timed pause in the fx queue between chained animations.

.delay() Pause Between Queued Effects tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful