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
Fundamentals
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.
Concept
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.
📋 .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
Hands-On
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 );
});
Div expands to 70% width, fades to 40% opacity, shifts margin, grows text, thickens border — all in one 1500ms tween
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.
» button: each .block moves 50px right (queued if clicked rapidly)
« button: each .block moves 50px left from its current position
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.
Block1: width expands 3s while font and border animate in parallel afterward
Block2: width, then font, then border — each waits for the previous step
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.
All blocks move left in lockstep — followers mirror the leader's left value every animation frame
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).
Visible paragraphs shrink and fade out; hidden ones expand and fade in — reversed on second run
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.
Applications
🚀 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.
Important
📝 Notes
Available since jQuery 1.0; two overloads with positional args or an options object.
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.
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll 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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about .animate()
Custom tweens for any numeric CSS property on matched elements.
5
Core concepts
🎨01
Properties object
Numeric CSS targets
Core
⏱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.