jQuery .slideToggle() Method

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

What You’ll Learn

The .slideToggle() instance method displays or hides matched elements with a sliding motion by animating height. This tutorial covers all three overloads since jQuery 1.0 (including easing since 1.4.3), default and preset durations, per-element callbacks, comparisons with .slideDown(), .slideUp(), .fadeToggle(), and .toggle(), and five hands-on examples from the official jQuery API.

01

Toggle

Show ↔ hide slide

02

Duration

ms, fast, slow

03

Three overloads

Positional / options

04

Easing

Since 1.4.3

05

Callbacks

Once per element

06

Display

Saved & restored

Introduction

Accordion panels, FAQ answers, and collapsible menus need one control that both opens and closes content. Writing if (visible) slideUp else slideDown works, but .slideToggle() bundles that logic into a single jQuery effect call.

Available since jQuery 1.0, .slideToggle() animates height so lower page content slides up or down as items appear or disappear. It enqueues on the default fx queue like other effects, which means you can chain it after .delay(), .fadeIn(), or another animation for readable sequential UI transitions.

Understanding the .slideToggle() Method

Per the official jQuery API, .slideToggle() displays or hides the matched elements with a sliding motion. The method animates height — if the element is initially displayed, it will be hidden; if hidden, it will be shown.

jQuery saves and restores the display property as needed. If an element has a display value of inline, then is hidden and shown, it will once again be displayed inline. When height reaches 0 after a hiding animation, display is set to none so the element no longer affects page layout.

💡
Beginner Tip

Think of .slideToggle() as .slideDown() and .slideUp() in one method. Click once to expand, click again to collapse — no manual visibility branch required.

📝 Syntax

Three overloads of .slideToggle:

jQuery
// 1) Duration and complete callback
jQuery( selector ).slideToggle( [duration ] [, complete ] )
// 2) Options object — queue, step, Promise callbacks
jQuery( selector ).slideToggle( options )
// 3) Duration, easing, complete — since jQuery 1.4.3
jQuery( selector ).slideToggle( [duration ] [, easing ] [, complete ] )

Parameters

  • duration (Number or String, default 400) — milliseconds, or "fast" (200) / "slow" (600).
  • easing (String, default "swing", since 1.4.3) — built-in swing or linear; plugins add more.
  • complete (Function) — called once per matched element when that element’s slide finishes.
  • options.queue (Boolean or String, default true) — false runs immediately; string names a custom queue.
  • options.step, progress, start, done, fail, always — same Promise-style hooks as other effects (since 1.8).

Return value

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

Official jQuery API description

jQuery
// With the element initially shown, hide it slowly on click:
$( "#clickme" ).on( "click", function() {
  $( "#book" ).slideToggle( "slow", function() {
    // Animation complete.
  });
});

⚡ Quick Reference

GoalCode
Default 400 ms toggle$el.slideToggle()
Slow toggle (600 ms)$el.slideToggle("slow")
Custom duration + callback$el.slideToggle(800, function() { ... })
Linear easing since 1.4.3$el.slideToggle(600, "linear", function() { ... })
Options overload$el.slideToggle({ duration: 500, easing: "linear", complete: fn })
Accordion FAQ panel$header.on("click", function() { $panel.slideToggle("slow"); })

📋 .slideToggle() vs slideDown vs slideUp vs fadeToggle vs .toggle()

Five ways to change visibility — only .slideToggle() auto-picks slide direction based on current state in one height-animated call.

.slideToggle()
$el.slideToggle("slow")

Visible → slideUp/hide; hidden → slideDown/show — one method for accordion-style panels

.slideDown()
$el.slideDown("slow")

Always reveals hidden elements — animates height open; lower content slides down to make room

.slideUp()
$el.slideUp("slow")

Always collapses visible elements — animates height to zero then hides

.fadeToggle()
$el.fadeToggle("slow")

Opacity toggle — no height animation; content below does not slide to make room

.toggle()
$el.toggle()

Instant show/hide with no transition — use when animation is not needed

Examples Gallery

Each example demonstrates an official jQuery API .slideToggle() pattern. Open DevTools or use the Try-it links. All five mirror live demos on api.jquery.com/slideToggle/.

📚 Getting Started

Official jQuery API demos — basic click-to-toggle and paragraph slide patterns.

Example 1 — Basic Usage: #book slideToggle("slow") on #clickme Click

With the element initially shown, click #clickme to slide toggle #book over the slow preset (600 ms). A second click shows it again.

jQuery
// With the element initially shown, we can hide it slowly:
$( "#clickme" ).on( "click", function() {
  $( "#book" ).slideToggle( "slow", function() {
    // Animation complete.
  });
});
Try It Yourself

How It Works

.slideToggle("slow") maps to 600 milliseconds. jQuery checks visibility: visible elements slide up to height 0 then hide; hidden elements restore display and slide down to full size.

Example 2 — Toggle All Paragraphs slideToggle("slow") (Official Example 1)

Click a button to animate all paragraphs to slide up or down, completing the animation within 600 milliseconds.

jQuery
$( "button" ).on( "click", function() {
  $( "p" ).slideToggle( "slow" );
});
Try It Yourself

How It Works

Every matched p toggles independently based on its own visibility. Visible paragraphs collapse; hidden ones expand — all in parallel over the slow preset.

📈 Advanced Patterns

Callback counters, accordion panels, and easing since jQuery 1.4.3.

Example 3 — Toggle div:not(.still) with Counter Callback (Official Example 2)

Click #aa to slide toggle all divs except .still dividers. The callback increments a counter span after each toggle completes.

jQuery
$( "#aa" ).on( "click", function() {
  $( "div:not(.still)" ).slideToggle( "slow", function() {
    var n = parseInt( $( "span" ).text(), 10 );
    $( "span" ).text( n + 1 );
  });
});
Try It Yourself

How It Works

The complete callback runs once per matched div after its slide finishes. Because callbacks fire per element, the counter increments multiple times per click when several divs toggle in parallel.

Example 4 — Accordion FAQ: Header Click Toggles .answer Panel

Click an FAQ header to slide toggle its .answer panel open or closed — the classic accordion pattern built on one line.

jQuery
$( ".faq-header" ).on( "click", function() {
  $( this ).next( ".answer" ).slideToggle( "slow" );
});
Try It Yourself

How It Works

.next(".answer") targets the panel sibling. .slideToggle("slow") handles both directions — hide answers with CSS display: none initially, then toggle on header click.

Example 5 — slideToggle(600, "linear", callback) with Easing Since 1.4.3

Use the three-argument overload to pick linear easing instead of the default swing curve, with a completion callback.

jQuery
$( "#toggle-btn" ).on( "click", function() {
  $( "#drawer" ).slideToggle( 600, "linear", function() {
    $( this ).text( "Toggle complete at constant speed" );
  });
});
Try It Yourself

How It Works

Since jQuery 1.4.3, the middle argument names an easing function. Built-in options are swing (default, accelerates mid-animation) and linear (constant rate). jQuery UI adds more easing plugins.

🚀 Common Use Cases

  • Accordion and FAQ panels — slide toggle answer sections hidden with display: none on header click.
  • Collapsible sidebars — reveal or hide navigation drawers with a vertical slide instead of instant pop-in.
  • Multi-div toggles — animate groups of divs between dividers, as in the official #aa demo with a counter callback.
  • Paragraph or content blocks — one button toggles all matched paragraphs up or down over a slow preset.
  • Notification drawers — repeat show/hide cycles without separate .slideDown() and .slideUp() branches.
  • Effect chains — combine with .delay() and .fadeToggle() for full expand/collapse choreography on the fx queue.

🧠 How .slideToggle() Toggles an Element

1

Visibility check

jQuery inspects each matched element. Visible → slide up path; hidden → slide down path. No manual if/else required.

Branch
2

Display saved or restored

On show, display is restored (inline stays inline). On hide, display is saved before the height tween begins toward zero.

Setup
3

Height animates over duration

Default 400 ms, or your chosen ms / fast / slow with optional swing or linear easing. Lower content slides up or down to make room.

Tween
4

Final state and callback

Element ends visible at full height or hidden with display: none. complete fires once per matched element; fx queue advances to the next step.

📝 Notes

  • Available since jQuery 1.0; easing overload added in 1.4.3; Promise callbacks in options since 1.8.
  • Default duration is 400 ms; "fast" = 200 ms, "slow" = 600 ms.
  • Animates height, not opacity — lower page content physically slides up or down as items appear or disappear.
  • If visible → behaves like .slideUp() then hide; if hidden → behaves like .slideDown() then show.
  • Saves and restores display as needed; inline elements return to inline after showing.
  • Callbacks fire once per matched element — use .promise().done() for one set-level callback.
  • Set jQuery.fx.off = true globally to disable all effects including .slideToggle() (duration becomes 0).
  • IE note: if .slideToggle() is called on a <ul> whose <li> children have position: relative, absolute, or fixed, the effect may fail in IE6–IE9 unless the ul has layout. Add position: relative; and zoom: 1; to the ul to fix it.

Browser Support

.slideToggle() is a jQuery instance method since 1.0+. It uses jQuery’s internal fx engine and height tweens — behavior is consistent wherever jQuery runs, independent of CSS transition support.

Stable · jQuery 1.0+

jQuery .slideToggle()

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

Bottom line: Learn .slideToggle() alongside .slideDown(), .slideUp(), and .finish() to build polished expand and collapse sequences in legacy and modern jQuery apps.

Conclusion

The .slideToggle() method is jQuery’s shorthand for displaying or hiding elements with a vertical sliding motion. Three overloads cover simple durations, options objects, and easing since 1.4.3.

One click handler replaces manual visibility branches. Pick your duration or preset, and use the complete callback to chain follow-up effects. Pair this method with .slideDown() behind you and .finish() ahead to master interrupting and controlling the fx pipeline.

💡 Best Practices

✅ Do

  • Use .slideToggle() for accordion panels instead of manual slideDown/slideUp branches
  • Use "slow" / "fast" for readable preset timing across your app
  • Hide answer panels with CSS or .hide() before the first toggle reveal
  • Use the complete callback to update counters or focus inputs without setTimeout
  • Call .promise().done() when you need one callback after all elements finish

❌ Don’t

  • Use .slideToggle() when you always want reveal-only — choose .slideDown() instead
  • Use .slideToggle() when you need an opacity fade — choose .fadeToggle() instead
  • Forget the IE ul/li layout fix when list items use positioned CSS
  • Assume one callback covers the whole set — it fires per matched element
  • Forget jQuery.fx.off in tests — it zeroes duration for all effects globally

Key Takeaways

Knowledge Unlocked

Five things to remember about .slideToggle()

Shorthand show/hide by sliding elements open or closed with a height animation.

5
Core concepts
02

Three overloads

Positional / options

API
🔄 03

400 / fast / slow

Default durations

Timing
📝 04

Per-element cb

Not once per set

Callback
👁 05

Display saved

inline stays inline

Rule

❓ Frequently Asked Questions

.slideToggle() displays 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 method replaces manual visibility checks plus separate .slideDown() and .slideUp() calls.
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 hidden elements; .slideUp() always collapses visible ones. .fadeToggle() toggles opacity, not height. .toggle() switches display instantly with no animation. .slideToggle() picks slideDown or slideUp based on current visibility in one call.
Duration is in milliseconds. Default is 400 ms when omitted. The strings "fast" (200 ms) and "slow" (600 ms) map to preset speeds, the same as other jQuery effect methods.
The complete callback runs once per matched element when that element's slide finishes — not once for the entire set. Use .promise().done() when you need a single callback after all elements complete.
Yes. jQuery saves and restores display as needed. If an element was inline before hiding, it returns to inline after showing. When height reaches zero after a hide animation, display is set to none so the element no longer affects layout.
Did you know?

The official jQuery .slideToggle() div demo increments a counter inside the completion callback once per toggled div — because callbacks fire per matched element, not once per click. That pattern teaches an important fx API rule: use .promise().done() when you need a single callback after the entire set finishes animating.

Continue to .stop()

Stop the current animation, clear the queue, or jump to the current step’s end CSS.

.stop() →

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