jQuery .fadeToggle() Method

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Toggle Visibility

What You’ll Learn

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

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.

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.

📝 Syntax

Two overloads of .fadeToggle:

jQuery
// 1) Duration, easing, and complete callback — since jQuery 1.4.4
jQuery( selector ).fadeToggle( [duration ] [, easing ] [, complete ] )
// 2) Options object — since jQuery 1.4.4
jQuery( selector ).fadeToggle( options )

Parameters

  • 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 fade finishes. this is the DOM element.
  • options (PlainObject) — map with duration, easing, queue, step, progress, complete, and Promise-style start, done, fail, always.

Return value

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

Official jQuery API description

jQuery
// Fades first paragraph in or out with slow linear easing:
$( "button" ).first().on( "click", function() {
  $( "p" ).first().fadeToggle( "slow", "linear" );
} );

// Fades last paragraph in or out fast, logging on complete:
$( "button" ).last().on( "click", function() {
  $( "p" ).last().fadeToggle( "fast", function() {
    $( "#log" ).append( " finished " );
  } );
} );

⚡ Quick Reference

GoalCode
Toggle with default 400 ms$el.fadeToggle()
Slow preset + linear easing$el.fadeToggle("slow", "linear")
Custom duration + callback$el.fadeToggle(800, function() { ... })
Options object with easing$el.fadeToggle({ duration: 600, easing: "linear", complete: fn })
Button toggles a panel$("#btn").on("click", function() { $("#panel").fadeToggle(); })
Guard against rapid clicks$el.stop(true, true).fadeToggle()

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

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.

jQuery
$( "button" ).first().on( "click", function() {
  $( "p" ).first().fadeToggle( "slow", "linear" );
} );

$( "button" ).last().on( "click", function() {
  $( "p" ).last().fadeToggle( "fast", function() {
    $( "#log" ).append( " finished " );
  } );
} );
Try It Yourself

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.

jQuery
$( "#toggle-panel" ).on( "click", function() {
  $( "#panel" ).fadeToggle();
} );
Try It Yourself

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 );
} );
Try It Yourself

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.

jQuery
// Manual approach — verbose if/else
$( "#toggle-manual" ).on( "click", function() {
  var $box = $( "#box-manual" );
  if ( $box.is( ":visible" ) ) {
    $box.fadeOut( 400 );
  } else {
    $box.fadeIn( 400 );
  }
} );

// Equivalent — one line
$( "#toggle-shorthand" ).on( "click", function() {
  $( "#box-shorthand" ).fadeToggle( 400 );
} );
Try It Yourself

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.

jQuery
$( "#rapid-toggle" ).on( "click", function() {
  $( "#rapid-panel" )
    .stop( true, true )
    .fadeToggle( 300 );
} );
Try It Yourself

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.

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

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

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 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
.fadeToggle() Universal

Bottom line: Learn .fadeToggle() alongside .fadeIn(), .fadeOut(), and .queue() to build polished toggle and effect sequences in legacy and modern jQuery apps.

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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about .fadeToggle()

Shorthand for animated show/hide toggling.

5
Core concepts
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.

Continue to .slideDown()

Reveal hidden elements with a vertical slide — height animates and content below moves down.

.slideDown() →

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