jQuery .fadeToggle() Method

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

What Is .fadeToggle()?

.fadeToggle() (since jQuery 1.4.4) displays or hides matched elements by animating their opacity. Visible elements fade out and get display: none; hidden elements unhide and fade in. Returns the jQuery object for chaining.

Remember
$("#panel").fadeToggle();           // default 400 ms
$("#panel").fadeToggle("slow", "linear");
$("#panel").fadeToggle("fast", function () { /* done */ });

// Visible → fade out → display:none
// Hidden  → show → fade in to opacity 1
NeedUse
Animated show/hide toggle$el.fadeToggle()
Fade in only.fadeIn()
Fade out only.fadeOut()
Instant toggle (no fade).toggle()
Height toggle.slideToggle()

How to Use .fadeToggle()

Select the element, call .fadeToggle() from a click (or other) handler, optionally pass duration, easing, or a callback.

  1. Select the target with jQuery ($("#panel")).
  2. On a user action, call .fadeToggle() (optional duration / easing / complete).
  3. jQuery checks visibility and runs fade-in or fade-out.
  4. On fade-out, display: none is set when opacity hits 0.
  5. For spam clicks, chain .stop(true, true) before .fadeToggle().
PieceRequired?Role
Matched setYesElements to fade in or out
durationNoDefault 400; also "fast" (200) / "slow" (600)
easingNoDefault "swing"; built-in also "linear"
completeNoRuns once per matched element when its fade ends
Return value—jQuery object (chainable)

Pseudocode

Pseudocode
call $(elements).fadeToggle(duration?, easing?, complete?)

for each matched element:
    if element is visible:
        animate opacity → 0
        set display: none
    else:
        restore display
        animate opacity → 1

    if complete was provided:
        call complete once for this element
        (this = the DOM element)

return the jQuery set for chaining

Cheat Sheet

Keep these facts handy while building fade toggles.

TopicDetail
Syntax.fadeToggle([duration] [, easing] [, complete])
Options form.fadeToggle({ duration, easing, complete, … })
SincejQuery 1.4.4
Default duration400 ms
Presets"fast" = 200 · "slow" = 600
Easingswing (default) · linear
CallbackOnce per element · use .promise() for “all done”
Rapid clicks$el.stop(true, true).fadeToggle()

Live Preview

Click Run to fadeToggle the sample paragraph. Change duration with the chips.

This paragraph fades in or out with .fadeToggle().

Each Run toggles visibility. Reset forces the paragraph visible again.

Result
Ready — click Run to fadeToggle.

jQuery Examples

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

Example 1 — Official Two-Button Demo

From the jQuery docs: slow linear on the first p; fast with a complete log on the last p.

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

  1. Target. Each button selects a different paragraph.
  2. Slow path. "slow" is 600 ms; "linear" keeps a steady pace.
  3. Fast path. "fast" is 200 ms with default swing easing.
  4. Callback. The complete function runs once for that paragraph when done.

Example 2 — Toggle a Panel on Click

One button, default 400 ms — jQuery picks fade-in or fade-out.

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

How It Works

  1. Bind. The click handler always calls the same method.
  2. Inspect. jQuery reads whether #panel is visible.
  3. Animate. Visible → fade out; hidden → fade in.
  4. Layout. After fade-out, display: none frees page space.

Example 3 — Accordion (One Open)

Fade-toggle the clicked section; fadeOut other open panels first.

jQuery
$(".acc-head").on("click", function () {
  var $body = $(this).next(".acc-body");

  $(".acc-body").not($body).filter(":visible").fadeOut(300);
  $body.fadeToggle(300);
});
Try It Yourself

How It Works

  1. Sibling. .next(".acc-body") is the panel under the header.
  2. Close others. Visible siblings get .fadeOut(300).
  3. Toggle self. .fadeToggle(300) opens or closes the clicked panel.
  4. Result. At most one section stays open.

Example 4 — Manual Branch vs .fadeToggle()

Same behavior: check :visible and call fadeOut / fadeIn, or use one shorthand call.

jQuery
// Manual
$("#runManual").on("click", function () {
  var $el = $("#manual");
  if ($el.is(":visible")) {
    $el.fadeOut(400);
  } else {
    $el.fadeIn(400);
  }
});

// Equivalent shorthand
$("#runToggle").on("click", function () {
  $("#toggle").fadeToggle(400);
});
Try It Yourself

How It Works

  1. Manual. You test :visible and pick the direction.
  2. Shorthand. .fadeToggle() does that check internally.
  3. Same queue. Both use the fx queue and the same display rules.
  4. Prefer. Use .fadeToggle() for less boilerplate.

Example 5 — Rapid-Click Guard with .stop()

Clear the queue and jump to the end state before starting a new toggle.

jQuery
$("#spam").on("click", function () {
  $("#msg").stop(true, true).fadeToggle(300);
});
Try It Yourself

How It Works

  1. Problem. Each click queues another fade → flicker.
  2. Clear. First true empties the fx queue.
  3. Jump. Second true finishes the current tween now.
  4. Toggle. .fadeToggle() starts from a known end state.

Edge Cases & Pitfalls

Watch these when fades feel wrong or “stack.”

queue

Rapid clicks queue animations

Use .stop(true, true) before .fadeToggle() on toggle buttons users can spam.

callback

Complete runs once per element

Animating three elements fires the callback three times. Use .promise().done() for one “all finished” hook.

display

Fade-out ends at display: none

The element leaves the layout. That is intended — not the same as opacity 0 while still taking space.

fx.off

jQuery.fx.off skips animation

When true, toggles snap instantly (duration 0). Useful for reduced-motion preferences.

vs toggle

.toggle() is not a fade

.toggle() shows/hides immediately. Use .fadeToggle() when you want opacity animation.

Browser Support

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

✓ Stable · jQuery 1.4.4+

jQuery .fadeToggle()

Supported across jQuery 1.4.4+, 2.x, and 3.x. Prefer a current jQuery 3.x build. Opacity animation uses jQuery’s fx engine.

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

Bottom line: Safe for everyday UI toggles. Guard rapid clicks with .stop(true, true), and respect jQuery.fx.off for reduced motion.

Performance Notes

ApproachCostBest for
One element fadeToggleCheapPanels, menus, help boxes
Many elements at onceMore paint workKeep sets small; prefer one container
Queued spam clicksWasted framesAlways .stop(true, true) on toggles

Opacity fades are inexpensive for a few elements. Cost climbs with large sets or stacked queues — stop before toggle, and prefer fading one wrapper over dozens of children.

Key Takeaways

  • Role: animated show/hide via opacity — since jQuery 1.4.4.
  • Call: $el.fadeToggle() — default 400 ms; optional easing + complete.
  • Direction: from current visibility — no separate toggle flag.
  • Guard: .stop(true, true) before toggle on busy buttons.

One line: .fadeToggle() fades an element in or out from its current visibility — one call for both directions.

Frequently Asked Questions

.fadeToggle() shows or hides matched elements by animating 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 call replaces a manual fadeIn / fadeOut branch.
.fadeToggle() was added in jQuery 1.4.4. It shares the same duration defaults, easing support, and callback semantics as .fadeIn() and .fadeOut().
1) .fadeToggle([duration] [, easing] [, complete]) — optional duration (default 400 ms), easing (default swing), and a per-element complete callback. 2) .fadeToggle(options) — a plain object with duration, easing, queue, step, progress, complete, and Promise-style start/done/fail/always.
.fadeToggle() picks fade-in or fade-out from current visibility. .fadeIn() / .fadeOut() are one-direction only. .toggle() shows or hides instantly with no opacity animation. Use .fadeToggle() when one control should animate both directions.
Once per matched element when that element’s fade finishes — not once for the whole set. Inside the callback, this is the DOM element. Use .promise().done() when you need a single callback after every element completes.
Call .stop(true, true) before .fadeToggle(). The first true clears the fx queue; the second jumps the current animation to its end state. Then fadeToggle starts from a clean baseline.

Next: .slideDown() Method

Reveal hidden content by animating height — the slide counterpart to fade effects.

.slideDown() 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