jQuery .animate() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Custom Animation

What You’ll Learn

The .animate() instance method performs custom animations on numeric CSS properties. This tutorial covers both overloads since jQuery 1.0, relative += / -= values, queue: false parallel timing, the step callback, comparisons with shorthand effects and .css(), and five hands-on examples from the official jQuery API.

01

Properties

CSS object targets

02

Duration

ms, fast, slow

03

Options

Second overload

04

Relative

+=50 / -=50

05

step()

Per-frame sync

06

fx queue

Serial by default

Introduction

jQuery ships shorthand effect methods like .fadeIn() and .slideUp() for common show/hide patterns. When you need fine-grained control over which CSS properties change and how long each transition runs, .animate() is the general-purpose tool.

Available since jQuery 1.0, .animate() accepts a plain object of CSS properties and animates each numeric value toward its target. Every call enqueues on the default fx queue unless you pass queue: false — so chained animations run one after another, just like other jQuery effects.

Understanding the .animate() Method

.animate( properties [, duration ] [, easing ] [, complete ] ) uses positional arguments for timing and a completion callback. .animate( properties, options ) passes duration, easing, queue, step, and Promise-style callbacks inside an options object.

Property values are treated as pixels unless you specify units like em, %, or in. Keywords "show", "hide", and "toggle" expand to appropriate numeric endpoints. Unlike shorthand effects, .animate() does not reveal hidden elements automatically.

💡
Beginner Tip

Think of .animate() as a tween engine for CSS numbers. You supply the destination values; jQuery handles the in-between frames over the duration you choose.

📝 Syntax

Two overloads of .animate:

jQuery
// 1) Positional — duration, easing, complete callback
jQuery( selector ).animate( properties [, duration ] [, easing ] [, complete ] )
// 2) Options object — queue, step, specialEasing, Promise callbacks
jQuery( selector ).animate( properties, options )

Parameters

  • properties (PlainObject) — CSS properties and target values. Supports relative += / -=, and keywords "show", "hide", "toggle".
  • duration (Number or String, default 400) — milliseconds, or "fast" (200) / "slow" (600).
  • easing (String, default "swing") — built-in swing or linear; plugins add more.
  • complete (Function) — called once per matched element when that element’s animation finishes.
  • options.queue (Boolean or String, default true) — false runs immediately; string names a custom queue (requires .dequeue() to start).
  • options.step (Function) — fired each frame per property; receives now and tween object fx.
  • options.specialEasing (PlainObject) — per-property easing map (since 1.4).

Return value

  • A jQuery object for chaining further methods on the same set.

Official jQuery API description

jQuery
// Basic usage — opacity, relative left, toggle height
$( "#clickme" ).on( "click", function() {
  $( "#book" ).animate({
    opacity: 0.25,
    left: "+=50",
    height: "toggle"
  }, 5000, function() {
    // Animation complete.
  });
});

⚡ Quick Reference

GoalCode
Animate width and opacity$el.animate({ width: 300, opacity: 0.5 }, 600)
Move relatively$el.animate({ left: "+=50px" }, "slow")
Run without waiting on fx$el.animate({ left: 50 }, { queue: false, duration: 500 })
Toggle height show/hide$("p").animate({ height: "toggle", opacity: "toggle" }, "slow")
Sync other elements per frame.animate({ left: 100 }, { step: function(now) { ... } })
Per-property easing.animate({ width: "toggle" }, { specialEasing: { width: "linear" } })

📋 .animate() vs fadeIn/slideUp vs .css() vs .stop()

Four ways to change element appearance — each tool fits a different job in the animation pipeline.

.animate()
.animate({ left: 100 })

Custom numeric CSS transitions over time — full control of properties, duration, easing, and queue

fadeIn / slideUp
.fadeIn().slideUp()

Shorthand effects with preset property sets — auto-show/hide and common motion patterns

.css()
.css("left", 100)

Instant style change with no transition — use when animation is not needed

.stop()
.stop(true, true)

Halts running animations and optionally clears the fx queue — pair with .animate() chains

Examples Gallery

Each example demonstrates an official jQuery API .animate() pattern. Open DevTools or use the Try-it links. All five mirror the live demos on api.jquery.com/animate/.

📚 Getting Started

Official jQuery API demos — multi-property animation and relative movement.

Example 1 — Multi-Property Demo (Official Example 1)

Click Run to animate width, opacity, marginLeft, fontSize, and borderWidth simultaneously over 1500ms using mixed unit types.

jQuery
// Using multiple unit types within one animation.
$( "#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

A single .animate() call can target many properties at once. jQuery interpolates each numeric value in parallel over the shared duration. Mixed units (%, in, em, px) are resolved per property.

Example 2 — Relative Left with +=50 / -=50 Buttons (Official Example 2)

Two buttons move absolutely positioned blocks by relative offsets. Each click queues another "slow" animation on the fx pipeline.

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

Leading += or -= tells jQuery to add or subtract from the current computed value. Rapid clicks enqueue separate steps on fx, so movements run sequentially rather than overlapping.

📈 Advanced Patterns

Queue control, step callbacks, and toggle keywords from the official API.

Example 3 — queue:false Parallel vs Sequential Chained .animate() (Official Example 3)

Block1 uses queue: false on the width tween so fontSize and border animate while width still expands. Block2 chains three serial .animate() calls.

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

Default queue: true serializes chained effects on fx. Setting queue: false on the first tween lets it run immediately alongside subsequent queued steps — a key technique for overlapping motion.

Example 4 — step Function Syncing Other Divs (Official Example 4)

The first block animates left to 100 while the step callback copies the current now value to every sibling block each frame.

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

How It Works

step fires once per property per element per frame. Here only the first div is animated, but the callback reads now and applies it instantly to siblings via .css(), creating synchronized motion without separate tweens.

Example 5 — height/opacity Toggle on Paragraphs (Official Example 5)

Animate all paragraphs to toggle both height and opacity over the "slow" duration (600ms).

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

How It Works

The "toggle" keyword resolves to show or hide endpoints based on current visibility state. jQuery tracks toggle state when you consistently use "toggle" as the property value, enabling reversible hide/show animations in one line.

🚀 Common Use Cases

  • Custom panel motion — animate width, height, and margin together for expandable sidebars or drawers.
  • Relative nudging — move elements incrementally with += / -= on arrow-key or button clicks.
  • Parallel overlays — use queue: false so a background fade runs while foreground content slides.
  • Synced followers — drive multiple elements from one leader via the step callback.
  • Reversible toggles — collapse and expand blocks with height: "toggle" and opacity: "toggle".
  • Scroll animations — tween scrollTop or custom plugin properties for smooth page navigation.

🧠 How .animate() Runs a Tween

1

Parse property targets

jQuery resolves numeric endpoints, relative offsets, and toggle keywords per matched element.

Setup
2

Enqueue or run now

Default queue: true waits on fx; queue: false starts the tween immediately.

Queue
3

Step each frame

The fx timer interpolates values; optional step and progress callbacks fire per frame.

Tween
4

Complete and dequeue

complete runs per element; the fx queue advances to the next waiting effect.

📝 Notes

  • Available since jQuery 1.0; two overloads with positional args or an options object.
  • Default duration is 400 ms; "fast" = 200 ms, "slow" = 600 ms.
  • Unlike .fadeIn(), .animate() does not auto-show hidden elements.
  • Directional properties (left, top) require non-static positioning to be visible.
  • Set jQuery.fx.off = true globally to disable all animations (duration becomes 0).
  • Callbacks fire once per matched element — use .promise() for a single set-level callback.

Browser Support

.animate() is a jQuery instance method since 1.0+. It relies on jQuery’s internal fx engine and timer loop, not on browser-specific animation APIs — behavior is consistent wherever jQuery runs.

Stable · jQuery 1.0+

jQuery .animate()

Supported in all jQuery 1.x, 2.x, 3.x, and 4.x releases. Works in Chrome, Firefox, Safari, Edge, IE 6+ (with compatible jQuery builds), and Node.js via jsdom.

100% jQuery animate API support
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: Learn .animate() alongside .stop() and .queue() to build reliable custom animation pipelines in legacy and modern jQuery apps.

Conclusion

The .animate() method is jQuery’s general-purpose tween engine for numeric CSS properties. Use the positional overload for simple cases or the options object when you need queue, step, or per-property easing.

Relative values, toggle keywords, and queue: false unlock patterns that shorthand effects cannot express. Pair your knowledge with .stop() to cancel mid-flight and .queue() to inspect or extend the fx pipeline.

💡 Best Practices

✅ Do

  • Set position: relative or absolute before animating left / top
  • Use the options overload when you need queue: false, step, or specialEasing
  • Prefer relative += / -= for incremental button-driven movement
  • Call .stop(true, true) before starting a new animation on the same element
  • Use .promise() when you need one callback after all elements finish

❌ Don’t

  • Expect .animate() to reveal hidden elements — call .show() first if needed
  • Animate shorthand CSS like font or background — use specific longhand properties
  • Assume non-numeric colors animate without the Color plugin or jQuery UI
  • Chain many rapid .animate() calls without .stop() — the fx queue will backlog
  • Forget that step fires per property per element — guard against redundant DOM writes

Key Takeaways

Knowledge Unlocked

Five things to remember about .animate()

Custom tweens for any numeric CSS property on matched elements.

5
Core concepts
02

Two overloads

Positional / options

API
03

+= / -=

Relative motion

Pattern
04

queue: false

Parallel timing

Advanced
🔄 05

step callback

Per-frame sync

Hook

❓ Frequently Asked Questions

.animate() performs 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 control exactly which properties move and how long the transition takes.
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.
Most non-numeric properties cannot be animated with basic jQuery. Numeric properties like width, height, left, opacity, and scrollTop work. Colors need the jQuery Color plugin or jQuery UI. Shorthand properties like font or border are not fully supported — use fontSize or borderWidth instead.
By default queue is true and each .animate() waits on the fx effects queue. Setting queue: false starts that animation immediately without waiting for prior queued effects. Chained .animate() calls after a queue:false step still enqueue normally unless they also set queue: false.
The step option fires at each animation frame for every animated property on every element. It receives now (current numeric value) and fx (a jQuery.fx tween object with elem, prop, start, and end). Use it to sync other elements or build custom animation types mid-flight.
When a property value starts with += or -=, jQuery computes the target from the element's current value. { left: "+=50px" } moves 50px farther right; { left: "-=50px" } moves 50px left. Relative values queue naturally when chained — each step runs after the previous one completes.
Did you know?

jQuery’s official queue: false demo runs a 3-second width expansion in parallel with font-size and border animations that would normally wait on the fx queue. That single option is what separates overlapping motion from the serial chaining you get with .fadeIn().slideUp() — and it is one of the most overlooked knobs in the entire effects API.

Continue to .delay()

Insert pauses between queued animations — slide up, wait, then fade in.

.delay() →

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.

6 people found this page helpful