.slideToggle() (since jQuery 1.0) displays or hides matched elements with a sliding motion by animating height. Visible elements slide up and get display: none; hidden elements slide down and show. Returns the jQuery object for chaining.
Remember
$("#panel").slideToggle(); // default 400 ms
$("#panel").slideToggle("slow"); // 600 ms
$("#panel").slideToggle(600, "linear", function () { /* done */ });
// Visible → slide up → display:none
// Hidden → slide down → fully visible
// display is saved and restored (e.g. inline stays inline)
Select the element, call .slideToggle() from a click handler — jQuery picks the direction.
Select the target with jQuery ($("#panel")).
On a user action, call .slideToggle() (optional duration / easing / complete).
jQuery checks visibility and runs slide-up or slide-down.
On hide, height reaches 0 then display: none frees layout space.
For spam clicks, chain .stop(true, true) before .slideToggle().
Piece
Required?
Role
Matched set
Yes
Elements to slide open or closed
duration
No
Default 400; also "fast" / "slow"
easing
No
Since 1.4.3 — swing (default) or linear
complete
No
Once per element when its slide ends
Return value
—
jQuery object (chainable)
Pseudocode
Pseudocode
call $(elements).slideToggle(duration?, easing?, complete?)
for each matched element:
if element is visible:
animate height → 0
set display: none
else:
restore saved display
animate height → natural height
if complete was provided:
call complete once for this element
(this = the DOM element)
return the jQuery set for chaining
Reference
Cheat Sheet
Keep these facts handy while building slide toggles.
Topic
Detail
Syntax
.slideToggle([duration] [, easing] [, complete])
Options form
.slideToggle({ duration, easing, complete, … })
Since
jQuery 1.0 (easing arg since 1.4.3)
Default duration
400 ms
Presets
"fast" = 200 · "slow" = 600
Easing
swing (default) · linear
Display
Saved / restored; none when fully hidden
Rapid clicks
$el.stop(true, true).slideToggle()
Try it
Live Preview
Click Run to slideToggle the sample panel. Change duration with the chips.
This panel slides open or closed with .slideToggle().
Each Run toggles visibility. Reset forces the panel visible again.
Result
Ready — click Run to slideToggle.
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools, or use Try It Yourself for a live editor.
Example 1 — Slow Toggle on Click
Official pattern: element starts shown; each click slides it closed or open.
jQuery
$("#clickme").on("click", function () {
$("#book").slideToggle("slow", function () {
// Animation complete.
});
});
Each click toggles all paragraphs
Visible ones collapse; hidden ones expand
All run in parallel over 600 ms
How It Works
Set. Every matched p is toggled.
Per element. Direction comes from each paragraph’s own visibility.
Parallel. They animate together, not one after another.
Preset."slow" is 600 ms.
Example 3 — Toggle with Per-Element Counter
Official idea: toggle several panels; increment a counter in each complete callback.
jQuery
$("#aa").on("click", function () {
$(".panel").slideToggle("slow", function () {
var n = parseInt($("#count").text(), 10);
$("#count").text(n + 1);
});
});
Drawer toggles at steady linear pace over 600 ms
Callback updates the text when finished
Built-in easing: swing (default) or linear
How It Works
Duration.600 ms total.
Easing."linear" keeps a constant rate.
Direction. Still auto from visibility.
Complete. Updates text when the tween ends.
Edge Cases & Pitfalls
Watch these when toggles feel wrong or “stack.”
queue
Rapid clicks queue animations
Use .stop(true, true) before .slideToggle() on toggle buttons users can spam.
callback
Complete runs once per element
Toggling three panels fires the callback three times. Use .promise().done() for one “all finished” hook.
display
Hide ends at display: none
The element leaves the layout when fully collapsed — that is intended.
fx.off
jQuery.fx.off skips the tween
When true, toggles snap open/closed instantly (duration 0).
vs toggle
.toggle() is not a slide
.toggle() shows/hides immediately. Use .slideToggle() for height animation.
Compatibility
Browser Support
.slideToggle() has been part of jQuery since 1.0 (positional easing since 1.4.3). It works in every browser that runs your loaded jQuery version — no separate browser feature flag.
✓ Stable · jQuery 1.0+
jQuery .slideToggle()
Supported across jQuery 1.x, 2.x, and 3.x. Prefer a current jQuery 3.x build. Height animation uses jQuery’s fx engine.
100%With jQuery
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
.slideToggle()Universal
Bottom line: Safe for FAQs, menus, and panels. Guard rapid clicks with .stop(true, true), and respect jQuery.fx.off for reduced motion.
Analysis
Performance Notes
Approach
Cost
Best for
One panel slideToggle
Cheap
Accordions, menus, help boxes
Many elements at once
More layout work
Prefer one wrapper when possible
Queued spam clicks
Wasted frames
Always .stop(true, true) on toggles
Height toggles trigger layout. One container is cheaper than sliding dozens of siblings — and stopping before toggle avoids stacked open/close queues.
Remember
Key Takeaways
Role: animated show/hide via height — since jQuery 1.0.
Direction: from current visibility — no separate toggle flag.
Guard:.stop(true, true) before toggle on busy buttons.
One line:.slideToggle() slides an element open or closed from its current visibility — one call for both directions.
Frequently Asked Questions
.slideToggle() shows or hides matched elements with a sliding motion by animating height. If the element is visible, it slides up and hides; if hidden, it slides down and shows. One call replaces a manual slideDown / slideUp branch.
1) .slideToggle([duration] [, complete]) — optional duration and completion callback. 2) .slideToggle(options) — an options object with duration, easing, queue, step, progress, and Promise-style callbacks. 3) .slideToggle([duration] [, easing] [, complete]) — positional easing since jQuery 1.4.3.
.slideDown() always reveals; .slideUp() always collapses. .fadeToggle() toggles opacity, not height. .toggle() switches display instantly with no animation. .slideToggle() picks slideDown or slideUp from current visibility.
Milliseconds, or the strings "fast" (200 ms) and "slow" (600 ms). Default is 400 ms when omitted.
Once per matched element when that element’s slide finishes — not once for the whole set. Use .promise().done() when you need a single callback after every element completes.
Yes. jQuery saves and restores display as needed. If an element was inline before hiding, it returns to inline after showing. When height reaches 0 after a hide, display is set to none so the element no longer affects layout.