jQuery .fadeTo() Animate to a Target Opacity

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

What Is .fadeTo()?

.fadeTo() (since jQuery 1.0) animates matched elements to a specific opacity between 0 and 1. It is like .fadeIn(), but that method always unhides and goes to full opacity. Returns the jQuery object for chaining.

Remember
$("#book").fadeTo("slow", 0.5);           // dim to 50%
$("#panel").fadeTo(400, 0.33);
$el.fadeTo(600, 1, "linear", complete);   // easing since 1.4.3
$el.fadeTo(0, 0.5);                       // instant = .css("opacity", 0.5)

// Duration required · opacity 0–1 · display unchanged
NeedUse
Exact opacity (stay in layout)$el.fadeTo(duration, opacity)
Unhide + full opaque.fadeIn()
Fade out + hide.fadeOut()
Toggle fade either way.fadeToggle()
Instant opacity.css("opacity", n) or .fadeTo(0, n)

How to Use .fadeTo()

Pass a duration and a target opacity (0–1). Optionally add easing and a complete callback.

  1. Select the target ($("#book")).
  2. If it may be hidden and you need it visible, call .show() first.
  3. Call .fadeTo(duration, opacity) — both arguments are required for a normal fade.
  4. Optionally pass easing (since 1.4.3) and a complete callback.
  5. For spam clicks, chain .stop(true, true) before .fadeTo().
PieceRequired?Role
durationYesMilliseconds, "fast" (200), or "slow" (600)
opacityYesNumber from 0 (transparent) to 1 (opaque)
easingNoDefault "swing"; also "linear" (since 1.4.3)
completeNoRuns once per matched element when its fade ends
Return value—jQuery object (chainable)

Pseudocode

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

for each matched element:
    animate opacity → target (0…1) over duration
    do NOT change display

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

return the jQuery set for chaining

// Special case:
//   fadeTo(0, opacity)  ≡  css("opacity", opacity)

Cheat Sheet

Keep these facts handy while adjusting opacity.

TopicDetail
Syntax.fadeTo(duration, opacity [, easing] [, complete])
SincejQuery 1.0 · easing arg since 1.4.3
DurationRequired · no default like fadeIn/fadeOut
Opacity0 … 1
Presets"fast" = 200 · "slow" = 600
DisplayUnchanged (no show/hide)
Instant.fadeTo(0, n) ≡ .css("opacity", n)
CallbackOnce per element · use .promise() for “all done”
Rapid clicks$el.stop(true, true).fadeTo(…)

Live Preview

Click Run to fadeTo a target opacity. Reset restores full opaque.

This paragraph dims with .fadeTo() — it stays in layout.

Duration is 400 ms. The panel never gets display:none — only opacity changes.

Result
Ready — click Run to fadeTo.

jQuery Examples

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

Example 1 — Dim to 50% Opacity

From the jQuery docs: fade a visible element to 0.5 with a complete callback.

jQuery
$("#clickme").on("click", function () {
  $("#book").fadeTo("slow", 0.5, function () {
    // Animation complete.
  });
});
Try It Yourself

How It Works

  1. Duration. "slow" is required and equals 600 ms.
  2. Target. Opacity animates to 0.5.
  3. Layout. display is unchanged — space is kept.
  4. Callback. Fires once for that element when done.

Example 2 — First Paragraph to 0.33

Official demo: only the first paragraph fades; the second stays full opacity.

jQuery
$("p").first().on("click", function () {
  $(this).fadeTo("slow", 0.33);
});
Try It Yourself

How It Works

  1. first. Only the first p gets the click handler.
  2. this. Fades the clicked paragraph, not the whole set.
  3. 0.33. About one-third visible.
  4. Compare. The sibling paragraph stays at opacity 1.

Example 3 — Random Opacity on Click

Official demo: each click fades the clicked div to a random opacity.

jQuery
$("div").on("click", function () {
  $(this).fadeTo("fast", Math.random());
});
Try It Yourself

How It Works

  1. fast. Duration is 200 ms.
  2. Math.random(). Target opacity is between 0 and 1.
  3. Per click. Only the clicked div animates.
  4. Display. Boxes stay in place even at low opacity.

Example 4 — Fade Then Style Sibling

Official pattern: dim a choice, then bold/italic the label above it in the complete callback.

jQuery
$("div.opt").on("click", function () {
  $(this).fadeTo(250, 0.25, function () {
    $(this).css("cursor", "").prev().css({
      "font-weight": "bolder",
      "font-style": "italic"
    });
  });
});
Try It Yourself

How It Works

  1. fadeTo. Choice dims to 25% in 250 ms.
  2. Complete. Runs when that fade ends.
  3. prev. Styles the label sibling above the box.
  4. Still visible. The box stays in layout at low opacity.

Example 5 — Dim a Modal Backdrop

Show the backdrop, then fadeTo a soft dim — without fadeOut’s display: none mid-animation.

jQuery
$("#open").on("click", function () {
  $("#backdrop").show().fadeTo(600, 0.4);
  $("#modal").fadeIn(400);
});

$("#close").on("click", function () {
  $("#modal").fadeOut(300);
  $("#backdrop").fadeTo(400, 0, function () {
    $(this).hide();
  });
});
Try It Yourself

How It Works

  1. show. Makes the backdrop participate in layout/stacking.
  2. fadeTo. Soft dim to 40% — not a full hide.
  3. Close. Animate opacity to 0, then .hide() in the callback.
  4. Why fadeTo. You control the exact dim level for overlays.

Edge Cases & Pitfalls

CaseWhat happensFix
Omit durationInvalid / unexpected callAlways pass duration (ms, fast, or slow)
Element is display: noneOpacity may change but stay invisibleCall .show() first when you need it visible
Expect hide at opacity 0Element stays in layoutUse .fadeOut() or .hide() after
Spam clicksQueued fades stack up.stop(true, true) before .fadeTo()
jQuery.fx.offDuration becomes 0Respect reduced-motion / accessibility settings

Browser Support

.fadeTo() has been part of jQuery since 1.0 (easing argument since 1.4.3). It works in every browser that runs your loaded jQuery version.

✓ Stable · jQuery 1.0+

jQuery .fadeTo()

Supported across jQuery 1.x, 2.x, and 3.x. Prefer a current jQuery 3.x build. Always pass duration and an opacity between 0 and 1.

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

Bottom line: Safe for dimming and partial opacity. Remember: duration is required, and display is never changed automatically.

Performance Notes

ApproachCostBest for
One element fadeToCheapDim cards, overlays, hover states
Many elements at onceMore paint workPrefer one wrapper over many children
Queued spam clicksWasted framesAlways .stop(true, true) on busy controls

Opacity tweens are inexpensive for a few elements. Cost climbs with large sets or stacked queues — stop before fade, and dim one backdrop instead of dozens of children.

Key Takeaways

  • Role: animate to an exact opacity — since jQuery 1.0.
  • Call: $el.fadeTo(duration, opacity) — duration is required.
  • vs fadeIn/Out: no unhide · no display: none.
  • Instant: .fadeTo(0, n) equals .css("opacity", n).

One line: .fadeTo() animates opacity to an exact level without changing display — ideal for dimming.

Frequently Asked Questions

.fadeTo() animates the opacity of matched elements to a specific value between 0 and 1. Unlike .fadeIn() or .fadeOut(), it does not unhide elements or set display:none — the element keeps its current display and ends at the target opacity.
Yes. Unlike .fadeIn() and .fadeOut(), which default to 400 ms when duration is omitted, .fadeTo() requires duration to be specified. Pass milliseconds, "fast" (200), or "slow" (600). With duration 0, .fadeTo(0, opacity) equals .css("opacity", opacity).
No. It only changes opacity. It does not unhide like .fadeIn(), and it does not set display:none when fading toward 0 like .fadeOut(). Use it for partial transparency while keeping the element in layout.
.fadeIn() unhides and fades to full opacity. .fadeOut() fades to transparent then hides. .css("opacity", n) sets opacity instantly. .fadeTo() animates to an exact opacity without touching display.
With duration 0, .fadeTo() skips animation and sets opacity immediately — the same result as .css("opacity", opacity). Useful for an instant change while keeping the .fadeTo() call shape.
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.

Next: .fadeToggle() Method

Fade in or out from current visibility — one call for both directions.

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