agyanadda@gmail.com

jQuery Fade

jQuery Effects 1 min read Updated Dec 1, 2026 Topic 7 of 25

Fade effects change an element's opacity smoothly.

Method Effect
.fadeIn() fade a hidden element in
.fadeOut() fade out, then hide
.fadeToggle() fade in or out
.fadeTo(speed, opacity) fade to a set opacity, e.g. 0.4

All accept a speed ('slow', 'fast', ms) and a callback.

Delay

.delay(2000) waits before the next effect in the queue:

$('#msg').fadeIn().delay(2000).fadeOut();

Perfect for "Saved!" messages that disappear by themselves.

Example

Example — Auto-hiding notification HTML
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>

<button id="save">Save profile</button>
<div id="toast" style="display:none;margin-top:10px;padding:10px 14px;background:#2b8a3e;color:#fff;border-radius:6px;width:max-content">✓ Profile saved</div>

<p style="margin-top:24px">
  <img id="pic" src="https://picsum.photos/id/1025/160/110" alt="Dog" style="border-radius:8px">
</p>
<button id="dim">Dim image</button>
<button id="full">Full image</button>

<script>
  $(function () {
    $('#save').click(function () {
      $('#toast').stop(true, true).fadeIn(300).delay(2000).fadeOut(600);
    });
    $('#dim').click(() => $('#pic').fadeTo('slow', 0.3));
    $('#full').click(() => $('#pic').fadeTo('slow', 1));
  });
</script>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which method fades an element to 50% opacity?

Exercise 2 True / False

fadeOut() hides the element at the end.

Exercise 3 Fill in the Blank

.___(2000) waits 2 seconds before the next effect.

Frequently Asked Questions

No. fadeTo only changes opacity; even at 0 the element still takes up space.