jQuery .fadeTo() Animate to a Target Opacity

Beginner
5 min read
Updated: Nov 2026
3 examples
Effects

Definition

.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.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$("#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
CallWhat it does
.fadeTo() Animate to a Target OpacityLearn jQuery .fadeTo(): animate matched elements to a specific opacity between 0 and 1 since 1.0, required duration, easing since 1.4.3, no display change, and compare with fadeIn, fadeOut, fadeToggle, and .css().

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Select the target ($("#book")).
Step 2If it may be hidden and you need it visible, call .show() first.
Step 3Call .fadeTo(duration, opacity) — both arguments are required for a normal fade.

Return Value

Return ValueDescription
jQuery objectMost setters and traversing helpers return the jQuery collection so you can chain more methods.

jQuery Examples

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.

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.

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.

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() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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