jQuery .slideDown(): Expand and Show Hidden Content

jQuery .slideDown() reveals an element hidden with display: none by animating its height. Content below moves down as the element opens. Use the completion callback or effects queue if you need to measure the expanded panel or run follow-up code.

Reveal a hidden element with a slide

Duration is measured in milliseconds and defaults to 400. 'fast' is 200 ms and 'slow' is 600 ms. The default swing easing changes speed during the animation, while linear moves steadily. Pass an options object or positional arguments such as .slideDown(400, 'swing', complete). See the official jQuery .slideDown() documentation.

$("#panel").slideDown({ duration: 400, easing: "linear" });

The method starts or queues the animation and returns a jQuery object immediately. Use its completion callback to run work afterward. A regular callback function runs once per selected element with this set to that element.

Run an initially collapsed panel

Save the entire code as jquery-slidedown-example.html in UTF-8 and open it in a browser. It needs an internet connection to load the full jQuery 4.1.0 build. The effects module is included in this build. See the jQuery full and slim build descriptions.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Expand a panel with jQuery .slideDown()</title>
  <script src="https://code.jquery.com/jquery-4.1.0.min.js"></script>
  <style>
    body { margin: 1rem; color: #1b2b36; font: 1rem/1.6 system-ui, sans-serif; }
    main { max-width: 36rem; margin-inline: auto; }
    button { font: inherit; }
    #panel { box-sizing: border-box; margin-block: .7rem; padding: .85rem;
      background: #e6f2fa; border: 1px solid #50748c; }
    #panel p { margin-top: 0; }
    :focus-visible { outline: 3px solid #005d90; outline-offset: 3px; }
  </style>
</head>
<body>
  <main>
    <h1>Expand a panel with jQuery .slideDown()</h1>
    <button id="toggle" type="button" aria-controls="panel" aria-expanded="false">Expand</button>
    <div id="panel" style="display: none" inert>
      <p>This information is visible while the panel is expanded.</p>
      <button id="close" type="button">Close panel</button>
    </div>
    <p id="status">Collapsed</p>
  </main>
  <script>
    $(function () {
      const $button = $("#toggle");
      const $panel = $("#panel");
      const panel = $panel[0];
      const motion = matchMedia("(prefers-reduced-motion: reduce)");
      let expanded = false;

      function setExpanded(next) {
        if (next === expanded) return;
        expanded = next;
        if (!next && panel.contains(document.activeElement)) $button[0].focus();

        $panel.stop(true, true);
        panel.inert = !next;
        $button.attr("aria-expanded", String(next));
        $button.text(next ? "Collapse" : "Expand");

        const duration = motion.matches ? 0 : 400;
        if (next) $panel.slideDown(duration);
        else $panel.slideUp(duration);

        $panel.promise("fx").done(function () {
          if (expanded === next) $("#status").text(next ? "Expanded" : "Collapsed");
        });
      }

      $button.on("click", () => setExpanded(!expanded));
      $("#close").on("click", () => setExpanded(false));
    });
  </script>
</body>
</html>

The panel starts hidden and the outside button has aria-expanded="false". Activate Expand to reveal it. The completion text changes when the effect ends. Close it again with the button inside the panel. With reduced motion enabled, it opens immediately.

Handle rapid input and keyboard focus

When the panel closes while an inner control has focus, the example moves focus to the outside control. It applies inert while closing and while closed so its inner control stays out of the Tab order. The outside button uses aria-expanded to expose the state. See the WAI disclosure pattern for the keyboard pattern.

The example calls .stop(true, true) before starting a new effect. The first true clears waiting effects, and the second finishes the active effect immediately. Its completion handler can run at that point, so the demo updates the message only if it matches the latest request. See the .stop() documentation for queue behavior.

Run an action once all panels have opened

Use the completion callback for per-element work. Use .promise('fx').done(...) for one action after all effects on the selection end. Here, fx is the default effects queue. See the .promise() documentation.

const $panels = $(".batch-panel");

$panels.slideDown(400, "swing", function () {
  this.dataset.finished = "true";
}).promise("fx").done(function () {
  $("#batch-count").text($panels.length);
});

To try the code above, add two elements with class batch-panel and style="display: none", plus an output with id="batch-count". Each panel gets data-finished="true" when it opens, and the output reads 2 after both effects end.

Diagnose an effect that does not run

The demo starts with inline display: none. If the element has a hidden attribute, remove it when you intend to reveal the element. Check for display: none !important and inspect the ancestors. Changing a child’s display cannot show it inside a hidden parent. In the Network panel, also check that you loaded the full jQuery build with effects.

Use the Coding Factory .slideUp() example to close the panel. For a single control that chooses a sliding effect based on visibility, use the Coding Factory .slideToggle() example. Separate open and close handlers when only opening needs a completion action.