The .fadeToggle() instance method displays or hides matched elements by animating their opacity. This tutorial covers both overloads since jQuery 1.4.4, the default 400 ms duration, per-element callbacks, comparisons with .fadeIn(), .fadeOut(), .toggle(), and .show() / .hide(), and five hands-on examples from the official jQuery API plus accordion and rapid-click patterns.
01
Auto direction
Fade in or out by visibility
02
Since 1.4.4
Core toggle fade effect
03
Two overloads
Positional + options
04
Default 400 ms
fast/slow presets too
05
Callbacks
Once per element
06
fx queue
Chain with other effects
Fundamentals
Introduction
Panels, dropdowns, and accordions often need the same button to show and hide content — but with a smooth fade instead of an abrupt snap. Writing if (visible) fadeOut(); else fadeIn(); works, yet jQuery bundles that logic into a single call: .fadeToggle().
Available since jQuery 1.4.4, .fadeToggle() inspects each matched element’s visibility and runs the appropriate fade. Visible elements fade out and end at display: none; hidden elements unhide and fade to full opacity. It enqueues on the default fx queue like other effects, so you can chain it with .delay(), .slideToggle(), or another animation for polished sequential choreography.
Concept
Understanding the .fadeToggle() Method
Per the official jQuery API, .fadeToggle() displays or hides the matched elements by animating their opacity. When called on a visible element, the element’s display style property is set to none once the opacity reaches 0, so the element no longer affects the layout of the page.
Durations are given in milliseconds; higher values indicate slower animations. The strings "fast" (200 ms) and "slow" (600 ms) work as presets. When duration is omitted, the default is 400 ms — the same default as .fadeIn() and .fadeOut().
💡
Beginner Tip
Think of .fadeToggle() as the animated counterpart to .toggle(). One click handler, one method call — jQuery picks fade-in or fade-out based on whether the element is currently visible.
📋 .fadeToggle() vs fadeIn vs fadeOut vs .toggle() vs show/hide
Five ways to change visibility — only .fadeToggle() auto-picks fade direction with opacity animation.
.fadeToggle()
$el.fadeToggle("slow")
Animates opacity in or out based on current visibility — one method for both directions
.fadeIn()
$el.fadeIn("slow")
Always unhides hidden elements and fades to full opacity — reveal-only shorthand
.fadeOut()
$el.fadeOut("slow")
Always fades visible elements to transparent then sets display:none — exit-only shorthand
.toggle()
$el.toggle()
Instant show/hide with no opacity animation — same toggle intent, no fade
.show() / .hide()
$el.show(); $el.hide();
Immediate display change with no animation — you must pick direction manually
Hands-On
Examples Gallery
Each example demonstrates an official jQuery API .fadeToggle() pattern or a common real-world use case. Open DevTools or use the Try-it links. Example 1 mirrors the live demo on api.jquery.com/fadeToggle/.
📚 Getting Started
Official jQuery API demo — two buttons fading different paragraphs with easing and callback logging.
Example 1 — Official Demo: Two Buttons fadeToggle Paragraphs (Official API)
Click the first button to fadeToggle the first paragraph with slow linear easing. Click the second button to fadeToggle the last paragraph with the fast preset and append " finished " to #log on completion.
Button 1 toggles first paragraph with slow linear fade; button 2 toggles last paragraph fast and appends " finished " to #log
How It Works
Each button targets a different paragraph. .fadeToggle("slow", "linear") maps to 600 ms with constant-speed easing. The second button’s callback fires once per element when the fast (200 ms) fade completes, demonstrating per-element callback semantics.
Example 2 — Toggle #panel on Button Click with Default Duration
Click a button to show or hide #panel using the default 400 ms fade. No duration argument needed — jQuery handles direction automatically.
Each click fades #panel in or out over 400ms — visible panel fades out to display:none; hidden panel unhides and fades in
How It Works
Omitting duration uses the 400 ms default. jQuery checks whether #panel is visible and runs the equivalent of .fadeOut() or .fadeIn() internally. One handler covers both show and hide UX.
📈 Advanced Patterns
Accordion exclusivity, manual equivalence, and rapid-click queue management.
Example 3 — Accordion: Header fadeToggle Sibling Content, Only One Open
Click an accordion header to fadeToggle its sibling content panel. Before opening, fade out any other open panel so only one section stays visible at a time.
jQuery
$( ".accordion-header" ).on( "click", function() {
var $content = $( this ).next( ".accordion-content" );
// Close other open panels
$( ".accordion-content" ).not( $content ).filter( ":visible" ).fadeOut( 300 );
// Toggle this panel
$content.fadeToggle( 300 );
} );
Clicking a header toggles its content with fadeToggle(300); other visible panels fadeOut first — only one section open at a time
How It Works
.next(".accordion-content") selects the panel immediately following the clicked header. .fadeToggle(300) handles open/close for the clicked section, while .fadeOut(300) on siblings enforces exclusivity. Pairing both methods is a common accordion pattern.
Example 4 — Equivalent Manual Check: visible ? fadeOut() : fadeIn() vs fadeToggle()
Compare the verbose manual branch with a single .fadeToggle() call. Both produce the same animated toggle behavior.
Both buttons toggle their boxes identically — manual uses :visible check + fadeIn/fadeOut; shorthand uses single fadeToggle(400)
How It Works
jQuery’s internal visibility check mirrors $box.is(":visible"). .fadeToggle() is syntactic sugar that removes boilerplate while preserving the same fx queue behavior and display handling as the manual branch.
Example 5 — Rapid-Click Guard with stop(true, true).fadeToggle()
When users click a toggle button rapidly, queued animations stack and cause flicker. Call .stop(true, true) before .fadeToggle() to clear the queue and jump to the end state, then start a fresh toggle.
Rapid clicks no longer queue stacked fades — stop(true,true) clears queue and jumps to end state before each fadeToggle(300)
How It Works
The first true in .stop(true, true) clears the fx queue; the second jumps the current animation to its end state immediately. Then .fadeToggle(300) starts from a clean baseline, preventing half-finished opacity tweens from piling up.
Applications
🚀 Common Use Cases
Show/hide panels — one button toggles a settings drawer, help box, or notification with a smooth fade.
Accordions and FAQs — click a header to fadeToggle its content; pair with .fadeOut() on siblings for one-open behavior.
Toolbar and menu items — toggle submenus or option groups without writing separate show and hide handlers.
Inline edit forms — reveal or dismiss an edit area on the same trigger with animated feedback.
Preview toggles — switch between summary and detail views on repeated clicks with opacity transitions.
Effect chains — combine with .delay() and .slideToggle() for layered toggle choreography on the fx queue.
🧠 How .fadeToggle() Picks Direction
1
Visibility inspected
jQuery checks each matched element’s current visibility state. No separate toggle flag is stored — direction is derived from display/visibility at call time.
Input
2
Fade direction chosen
Visible elements run the fade-out path (opacity toward 0). Hidden elements run the fade-in path (unhide then opacity toward 1).
Branch
3
Opacity animates
jQuery tweens opacity over the chosen duration and easing. On fade-out, display: none is applied when opacity reaches 0.
Tween
4
▶
State flipped and callback
Element ends visible or hidden. complete fires once per matched element; fx queue advances to the next step.
Important
📝 Notes
Available since jQuery 1.4.4; options overload shares the same object shape as .fadeIn() and .fadeOut().
Default duration is 400 ms when omitted — same as .fadeIn() and .fadeOut().
Direction is determined by visibility at call time — jQuery does not maintain a separate toggle state variable.
On fade-out, display: none is set once opacity reaches 0; on fade-in, display is restored before opacity animates.
Callbacks fire once per matched element — use .promise().done() for one set-level callback.
Pair with .stop(true, true) when rapid clicks would otherwise queue conflicting fades.
Set jQuery.fx.off = true globally to disable all effects including .fadeToggle() (duration becomes 0).
Compatibility
Browser Support
.fadeToggle() is a jQuery instance method since 1.4.4+. It uses jQuery’s internal fx engine and opacity tweens — behavior is consistent wherever jQuery runs, independent of CSS transition support.
✓ Stable · jQuery 1.4.4+
jQuery .fadeToggle()
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 fadeToggle 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
.fadeToggle()Universal
Bottom line: Learn .fadeToggle() alongside .fadeIn(), .fadeOut(), and .queue() to build polished toggle and effect sequences in legacy and modern jQuery apps.
Wrap Up
Conclusion
The .fadeToggle() method is jQuery’s shorthand for animated show/hide toggling. Two overloads cover simple duration-plus-callback calls and full options objects with easing, queue control, and Promise-style hooks.
Let jQuery inspect visibility and pick fade direction automatically. Use the complete callback for follow-up logic, and guard rapid clicks with .stop(true, true) when needed. Pair this method with .fadeTo() behind you and .queue() ahead to master the full fx pipeline.
Use .fadeToggle() when one control both shows and hides with animation
Pass explicit duration for predictable UX — or rely on the 400 ms default for simple toggles
Call .stop(true, true) before .fadeToggle() on rapid-click triggers
Use the complete callback to update ARIA attributes or button labels after fade finishes
Call .promise().done() when you need one callback after all elements finish
❌ Don’t
Write manual if (visible) fadeOut(); else fadeIn(); when .fadeToggle() suffices
Expect .fadeToggle() to animate partial opacity — use .fadeTo() for that
Assume one callback covers the whole set — it fires per matched element
Stack rapid toggles without .stop() — queued fades cause flicker and wrong end states
Confuse .fadeToggle() with .toggle() — only the former animates opacity
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about .fadeToggle()
Shorthand for animated show/hide toggling.
5
Core concepts
🌟01
Auto direction
Fade in or out
Core
⏱02
Since 1.4.4
Toggle fade effect
API
🔄03
Two overloads
Positional + options
Syntax
📝04
Per-element cb
Not once per set
Callback
⚡05
vs toggle/show
Animated not instant
Compare
❓ Frequently Asked Questions
.fadeToggle() displays or hides matched elements by animating their opacity. If the element is visible, it fades out and sets display:none when opacity reaches 0. If hidden, it unhides and fades in to full opacity. One method replaces the fadeIn/fadeOut pair for toggle UX.
.fadeToggle() was added in jQuery 1.4.4 alongside .slideToggle(). It shares the same duration defaults, easing support, and callback semantics as .fadeIn() and .fadeOut().
1) .fadeToggle([duration] [, easing] [, complete]) — positional arguments with optional duration (default 400 ms), easing (default swing), and per-element complete callback. 2) .fadeToggle(options) — a plain object with duration, easing, queue, step, progress, complete, and Promise-style start/done/fail/always callbacks.
.fadeToggle() picks fadeIn or fadeOut automatically based on current visibility — no manual if/else. .toggle() instantly shows or hides with no opacity animation. .show() and .hide() change display immediately. Use .fadeToggle() when you want animated toggle behavior in one call.
jQuery determines direction from the element's current visibility at call time — visible elements fade out, hidden elements fade in. There is no separate toggle flag; each call inspects display/visibility state and runs the appropriate fade direction.
The complete callback runs once per matched element when that element's fade finishes — not once for the entire set. Inside the callback, this refers to the DOM element being animated. Use .promise().done() when you need a single callback after all elements complete.
Did you know?
.fadeToggle() was introduced in jQuery 1.4.4 alongside .slideToggle() as part of the toggle-effect family. Internally, jQuery does not store a separate “toggled” flag — each call inspects the element’s current visibility and delegates to the equivalent of .fadeIn() or .fadeOut(), which is why a single .fadeToggle() replaces the common visible ? fadeOut() : fadeIn() pattern.