jQuery .animate() Custom CSS Animations

Beginner
8 min read
Updated: Oct 2026
5 examples
Live preview

What Is .animate()?

.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.

Remember
$("#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
NeedUse
Custom multi-property tween$el.animate({ … })
Opacity show/hide.fadeIn() / .fadeOut()
Height show/hide.slideDown() / .slideUp()
Instant style change.css()
Stop a running tween.stop()

How to Use .animate()

Select the element, pass a properties map, then optionally duration, easing, or an options object.

  1. Select the target with jQuery ($("#box")).
  2. If it may be hidden, call .show() first when you need it visible.
  3. Call .animate({ prop: value, … }, duration) (or the options form).
  4. Use += / -= for relative moves; "show" / "hide" / "toggle" for height, width, opacity, and similar.
  5. Chain more .animate() calls to queue steps, or set queue: false for parallel runs.
PieceRequired?Role
propertiesYesMap of CSS targets (camelCase or quoted)
durationNoDefault 400; also "fast" (200) / "slow" (600)
easingNoDefault "swing"; built-in also "linear"
completeNoRuns once per matched element when its animation ends
Return value—jQuery object (chainable)

Pseudocode

Pseudocode
call $(elements).animate(properties, duration?, easing?, complete?)
  // or .animate(properties, options)

for each matched element:
    resolve relative values (+= / -=) from current CSS
    resolve show / hide / toggle keywords
    enqueue on fx (unless queue: false)

    each frame:
        tween every property toward its target
        if step provided: call step(now, fx)

    when finished:
        if complete provided: call complete (this = DOM element)

return the jQuery set for chaining

Cheat Sheet

Keep these facts handy while building custom animations.

TopicDetail
Syntax.animate(properties [, duration] [, easing] [, complete])
Options form.animate(properties, { duration, easing, queue, step, … })
SincejQuery 1.0
Default duration400 ms
Presets"fast" = 200 · "slow" = 600
Easingswing (default) · linear
Relative"+=50px" · "-=50px"
Keywords"show" · "hide" · "toggle"
Parallel{ queue: false }
Rapid clicks$el.stop(true, true).animate(…)

Live Preview

Click Run to animate the sample box. Pick a preset, then reset to restore defaults.

Hello!

Grow tweens width and opacity together. Reset restores the starting styles.

Result
Ready — click Run to animate.

jQuery Examples

Short, copy-ready snippets. Open DevTools, or use Try It Yourself for a live editor.

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.
  4. Together. All listed properties animate in the same timeframe.

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.
  4. Slow. "slow" is 600 ms per move.

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.
  4. Reset. Clear inline styles with .css(…) when comparing again.

Example 4 — step Sync Follower Blocks

Animate the first block; copy its left to siblings on every frame.

jQuery
$("#go").on("click", function () {
  $(".block").css("left", 0);
  $(".block").first().animate({ left: 200 }, {
    duration: 1000,
    step: function (now) {
      $(".block").slice(1).css("left", now);
    }
  });
});
Try It Yourself

How It Works

  1. Leader. Only the first .block is animated.
  2. step. Fires each frame with the current numeric now.
  3. Follow. Siblings get .css("left", now) — no second animation.
  4. Reset. Setting left to 0 first keeps repeats predictable.

Example 5 — height / opacity Toggle

Use the "toggle" keyword so jQuery picks show or hide from the current state.

jQuery
$("#run").on("click", function () {
  $("p").animate({
    height: "toggle",
    opacity: "toggle"
  }, "slow");
});
Try It Yourself

How It Works

  1. Keyword. "toggle" chooses show or hide from current visibility.
  2. Pair. Height and opacity animate together in one call.
  3. Slow. "slow" is 600 ms.
  4. Note. For simple fade toggles, prefer .fadeToggle().

Edge Cases & Pitfalls

CaseWhat happensFix
Element is display: noneAnimation may not be visibleCall .show() first, or use fade/slide helpers
Animate left / topNo movement if position is staticSet position: relative or absolute
Color / shorthand CSSIgnored or incomplete without pluginsNumeric longhands; Color plugin for colors
Spam clicksLong fx queue builds up.stop(true, true) before .animate()
jQuery.fx.offDuration becomes 0Respect reduced-motion / accessibility settings

Browser Support

.animate() has been part of jQuery since 1.0. It works in every browser that runs your loaded jQuery version — no separate CSS animation feature flag.

✓ Stable · jQuery 1.0+

jQuery .animate()

Supported across jQuery 1.x, 2.x, and 3.x. Prefer a current jQuery 3.x build. Directional properties still need non-static positioning.

100% With jQuery
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
.animate() Universal

Bottom line: Safe for everyday custom tweens. Stick to numeric properties, stop before spam clicks, and use fade/slide helpers when you only need show/hide.

Performance Notes

ApproachCostBest for
Few properties, one elementCheapUI polish, panels, buttons
Many elements × many propsMore layout/paintAnimate a container, not every child
Queued spam clicksWasted framesAlways .stop(true, true) on busy controls
CSS transitions / requestAnimationFrameOften smootherHeavy motion, complex timelines

Small .animate() calls are fine for learning and simple UI. Prefer fewer properties, smaller sets, and stop-before-animate on interactive controls.

Key Takeaways

  • Role: custom numeric CSS tweens — since jQuery 1.0.
  • Call: $el.animate({ prop: value }, duration) — default 400 ms.
  • Extras: +=/-=, queue: false, step, show/hide/toggle.
  • Limits: no auto-show; colors need a plugin; stop spam with .stop().

One line: .animate() tweens numeric CSS properties you choose — the flexible alternative to fade/slide helpers.

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() Method

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

.delay() tutorial →

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