How to Add a CSS Fade-in Transition Animation to Text, Images, Scroll & Hover (2024)

Animation — when done right — brings a website to life and increases engagement.

When done wrong, it’s nauseating.

An engaging website helps accomplish business goals. With so much competing for the average consumer’s attention, you need to find ways to stand out.

Using subtle transition animation effects is one way to make an impression on a website visitor.

One popular type of animation that can be effectively used by nearly any brand is the fade transition. This stylistic effect allows for images or text on your website to gradually appear or disappear.

You can use this style for text, images, on scroll, or on hover. Here are the options we'll discuss below:

  • Fade-in Image Transition
  • Fade-in Text Transition
  • Fade-in on Hover Animation
  • Fade-in on Scroll Animation
  • Fade Background Transition

The impact of fade-in animation can be powerful. Thankfully, it’s fairly easy to implement with Cascading Style Sheets (CSS) — a coding language used to enhance the appearance of your website.

CSS Fade Transition

A CSS fade transition is a stylistic effect in which an element — like an image, text, or background — gradually appears or disappears on the page.

To create these effects, you'll use either the transition or animation property in CSS. When using the transition property, you'll only be able to specify an initial state and a final state — not any intermediate points. For example, you can set a div element to transition from red to purple. But to specify the div to change from red to blue to purple to pink, you'll need to use the animation property.

CSS transitions also require a trigger — like a visitor hovering over an element — and animations do not. By default, an animation will automatically begin its sequence when the page loads. Although, you can delay its start time using the animation-delay property.

You can see how both the transition and animation properties are used in the examples below.

You can also check out to learn more.

Like fade transitions in movies, CSS fade transitions and animations work better on some websites than others. Let's look at some reasons you'd use this stylistic effect.

Free Resource

The Beginner's Guide to HTML and CSS for Marketers

Fill out the form to learn more about CSS.

Why add fade-in animation to your website?

Adding CSS animation to your website shouldn’t be an afterthought. You don’t want it to be something you throw into the mix just to add some flash to your website.

Instead, every design choice must be justified in terms of what it contributes to (or detracts from) the user experience (UX).

So consider this: Since animation involves movement, it’s nearly impossible to ignore this type of design. Because of its visual prominence, you need to be thinking about how to implement it while you’re in the early stages of designing a website.

The purpose of website animation goes beyond aesthetics. Animation can be used to improve the flow of your website and create a more engaging user interface (UI).

Fade-in animation is just one of many types of animation you can implement on your website. There are hover animations, loading animations, and dozens of other animation examples. But fade-in animation, in particular, offers plenty of flexibility: you can create image fades, text fades, hovering fades, scrolling fades, and background fades.

Below we'll walk through an example of each.

CSS Transition Opacity

The CSS opacity property is used to specify how opaque or transparent an element is. Values for this property range from 0 to 1, with 0 being completely transparent and 1 being completely opaque.

When combined with the animation or transition property, you can use the opacity property to make an element change from completely transparent to completely opaque (or vice versa) over a period of time.

When transitioning from completely transparent to completely opaque, the element will gradually appear on the page. That's called a fade-in animation, and it can be used on images, text, and other page elements too.

Fade-in Image Transition Using CSS

To demonstrate opacity transitions, let’s look at a fade-in image transition. Here, an image goes from transparent to full opacity over the course of a few seconds:

How to Add a CSS Fade-in Transition Animation to Text, Images, Scroll & Hover (2)

Here's how to make this effect happen:

1. In your HTML, create a div with the class fade-in-image.

2. Place your image inside this div. Your HTML will look like this:

 
<div class="fade-in-image">
<img src="source">
</div>

3. In your CSS, give your fade-in-image class the declaration animation: fadeIn 5s. You can adjust 5s to any span of time you want.

 
.fade-in-image { animation: fadeIn 5s; }

This assigns an animation called fadeIn to our div. This doesn’t do anything yet because we still need to create the effect using keyframes.

4. In the CSS, use the @keyframes rule paired with fadeIn. At 0%, set the opacity to 0. At 100%, set the opacity to 1. This creates the fade-in effect.

 
@keyframes fadeIn {
0% { opacity: 0; }
100% { opacity: 1; }
}

5. It’s also recommended you repeat the code above using vendor prefixes — "-webkit", "-moz", "-o", and "-ms" — to ensure cross-browser compatibility. For example, "-webkit" is for Chrome, Safari, and almost all iOS browsers. This is shown in the final code below:

See the Pen Fade-in Image Transition Using CSS by HubSpot (@hubspot) on CodePen.

You can keep reusing this CSS code with other images by using the fade-in-image CSS class within an element containing an image.

Fade-in Text Transition Using CSS

You can use the same CSS properties shared above with just a slight change to create a text fade-in effect.

How to Add a CSS Fade-in Transition Animation to Text, Images, Scroll & Hover (3)Here’s how to create this effect:

1. In your HTML, create a div with the class fade-in-text.

2. Place your text inside this div. In this example, we’ll create this text as a paragraph:

 
<div class="fade-in-text">
<p>Fade-in Text</p>
</div>

3. In your CSS, give the fade-in-text class the declaration animation: fadeIn 5s. Again, you can adjust this seconds value to any duration. Also, you can specify your font declarations here, like font-family and font-size:

 
.fade-in-text {
font-family: Arial;
font-size: 150px;
animation: fadeIn 5s;
}

4. Use the @keyframes rule paired with fadeIn. At 0%, set the opacity to 0. At 100%, set the opacity to 1.

 
@keyframes fadeIn {
0% { opacity: 0; }
100% { opacity: 1; }
}

5. Add vendor prefixes for cross-browser compatibility.

Here’s the final code:

See the Pen Fade-in Text Transition Using CSS by HubSpot (@hubspot) on CodePen.

You can use the fade-in-text class on any text element you want to apply this effect to.

CSS Fade-in Transition on Hover

A more interactive way to incorporate a fade-in animation effect involves triggering it on mouse hover. This can be applied to text or images.

For example, you could set an image to start at 50% opacity and increase to 100% opacity over the duration of one second when a user hovers over it.

How to Add a CSS Fade-in Transition Animation to Text, Images, Scroll & Hover (4)

Here are the steps for this effect:

1. In your HTML, create a div with the class fade-in-image.

2. Place your image inside this div.

 
<div class="fade-in-image">
<img src="source">
</div>

3. In your CSS, set the opacity of the fade-in-image class to 50%.

4. With the hover pseudo-class, add the declarations opacity: 100% and transition: opacity 1s.

 
.fade-in-image:hover {
opacity: 100%;
transition: opacity 1s;
}

Here’s the final code:

See the Pen CSS Fade-in Transition on Hover by HubSpot (@hubspot) on CodePen.

CSS Fade-in Transition on Scroll

Using fade-in animation with scrolling is a little more complicated than our previous examples. Your page has to detect when the user scrolls, and to do that you’ll need to use JavaScript. The JavaScript will register the scroll, triggering the CSS to adjust the animation.

How to Add a CSS Fade-in Transition Animation to Text, Images, Scroll & Hover (5)

To get the effect shown above, your code should look something like this code shared by Staffan Adolfsson on CodePen:

See the Pen fade in scroll by Staffan Adolfsson (@staffan-ad) on CodePen.

Here’s how to write it step-by-step:

1. In HTML, create four (or however many you want) section elements. Assign each section a unique class based on its color. Also, add the class tag to all section elements besides the first.

 
<section class="yellow"><h1>foobar</h1></section>
<section class="tag red"><h1>foobar</h1></section>
<section class="tag blue"><h1>foobar</h1></section>
<section class="tag green"><h1>foobar</h1></section>

2. In CSS, set the margin and padding of the body to 0.

3. Set the height of each section element to 100vh The “vh” stands for viewport height, and sets each section to take up the full height of the browser window.

 
section { height: 100vh; }

4. For all elements in the class tag, give them the declarations opacity: 0 and transition: all 1s. If you want your section elements to slide into view, you can also add the declaration transform: translate(0, 10vh).

 
.tag {
opacity: 0;
transform: translate(0, 10vh);
transition: all 1s;
}

5. Create a selector called .tag.visible and give it the declarationopacity: 1 (and, optionally, the declaration transform: translate(0, 0) if you used the transform declaration in the previous step)

 
.tag.visible {
opacity: 1;
transform: translate(0, 0);
}

6. Give each of your section elements a background color.

 
.yellow { background-color: lightyellow; }
.red { background-color: lightcoral; }
.blue { background-color: lightblue; }
.green { background-color: lightgreen; }

7. Finally, add the following JavaScript code (note that this code example also uses jQuery). This code first detects when the user scrolls. When the user begins to scroll, the code detects the top and bottom of the viewport, then checks each tag section element for whether the tag is inside the viewport (i.e., visible on the screen).

If the section element is in view, it assigns it the class visible (which, if you’ll remember, has an opacity of 1). If the section element is not in view, it removes the visible class from this section element.

 
$(document).on("scroll", function() {
var pageTop = $(document).scrollTop();
var pageBottom = pageTop + $(window).height();
var tags = $(".tag");

for (var i = 0; i < tags.length; i++) {
var tag = tags[i];
if ($(tag).position().top < pageBottom) {
$(tag).addClass("visible");
} else {
$(tag).removeClass("visible");
}
}
});

With some basic knowledge of JavaScript, making these kinds of impressive animation effects is doable, and common on a ton of websites.

CSS Fade Background Transition

You could also create a fade background color transition effect that doesn’t require the user to scroll down the page. Instead, use the CSS animation property to style the body element.

For example, you could set the background to transition from yellow to green over the duration of six seconds.

How to Add a CSS Fade-in Transition Animation to Text, Images, Scroll & Hover (6)

Here's how to do that.

1. In the CSS, assign three declarations to the body of the document: The initial background color, the animation, and an animation-fill-mode, which prevents the color from resetting to yellow when the animation is complete.

 
body {
background: #FCE97F;
animation: fadeBackground 6s;
animation-fill-mode: forwards;
}

2. Use the @keyframes rule to set the initial background color and the final background color.

 
@keyframes fadeBackground {
from { background-color: #FCE97F; }
to { background-color: #2EB07B; }
}

Here’s what the final code looks like:

See the Pen CSS Fade Background Transition by HubSpot (@hubspot) on CodePen.

If you’re running into issues here, see our post on fixes when your CSS animations aren’t working.

Create fade-in animations on your website.

Fade-in animation can be a powerful tool when telling a meaningful story and improving engagement. But, don’t add unnecessary animation to your website just for the sake of using animation.

Focus on using fade-in animation to highlight certain elements and create smoother transitions, as well as improve the overall user experience of your website.

Editor's note: This post was originally published in February 2020 and has been updated for comprehensiveness.

Originally published Jun 7, 2022 7:00:00 AM, updated June 07 2022

Topics:

CSS Animation

How to Add a CSS Fade-in Transition Animation to Text, Images, Scroll & Hover (2024)

FAQs

How do you add an animation to text in CSS? ›

An animation lets an element gradually change from one style to another. You can change as many CSS properties you want, as many times as you want. To use CSS animation, you must first specify some keyframes for the animation. Keyframes hold what styles the element will have at certain times.

How do I fade-in and fade out in CSS? ›

The jQuery fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the elements are faded out, fadeToggle() will fade them in. If the elements are faded in, fadeToggle() will fade them out.

What is CSS hover? ›

The :hover CSS pseudo-class matches when the user interacts with an element with a pointing device, but does not necessarily activate it. It is generally triggered when the user hovers over an element with the cursor (mouse pointer).

How do you add a transition to an image in CSS? ›

The transition property is a shorthand property for: transition-property. transition-duration. transition-timing-function.
...
Definition and Usage.
Default value:all 0s ease 0s
Inherited:no
Animatable:no. Read about animatable
Version:CSS3
JavaScript syntax:object.style.transition="all 2s" Try it

How do you fade an animation? ›

Fade in and Fade Out in Adobe Animate - YouTube

What is transition in CSS? ›

CSS transitions provide a way to control animation speed when changing CSS properties. Instead of having property changes take effect immediately, you can cause the changes in a property to take place over a period of time.

How do you make a website with animated text effect using HTML and CSS? ›

How To Make Animated Website Design Using HTML and CSS

How do you fadeOut an element in CSS? ›

And when hiding the element (by switching to the hidden class), we want to delay the visibility:hidden declaration, so that we can see the fade-out transition first. We're doing this by declaring a transition on the visibility property, with a 0s duration and a delay.

What is fadeIn effect? ›

Fade in effect can be used to display new video information from a static background. In case of matrix switching, this means visualization of a new video signal to a certain output. On the output the visitor may see the static and still background first and the video signal comes up smoothly.

What is fadeIn fadeOut effect? ›

The Fade In/Fade Out behavior lets you dissolve into and out of any object by ramping the opacity of the object from 0 percent to 100 percent at the start, and then back to 0 percent at the end. You can eliminate the fade-in or fade-out effect by setting the duration of the Fade In Time or Fade Out Time to 0 frames.

What are the 3 types of transitions? ›

Transitions can be divided into groups according to their functions.
  • Types of conjunctive adverbs. A conjunctive adverb modifies the action by creating logical connections in meaning between independent clauses. ...
  • Types of conjunctions. A conjunction is used to join words or groups of words. ...
  • Referents*
Jun 10, 2022

What is animation and transition in CSS? ›

Animations within CSS3 allow the appearance and behavior of an element to be altered in multiple keyframes. Transitions provide a change from one state to another, while animations can set multiple points of transition upon different keyframes.

How do you use transition properties in CSS? ›

Tip: A transition effect could typically occur when a user hover over an element. Note: Always specify the transition-duration property, otherwise the duration is 0, and the transition will have no effect.
...
Definition and Usage.
Default value:all
JavaScript syntax:object.style.transitionProperty="width,height" Try it
3 more rows

How do you make a scrolling website animation? ›

How to Make a Scrolling Website Showcase in Adobe After Effects

How do I scroll text without marquee in HTML? ›

You can use the :hover selector with the animation-play-state property to stop the scrolling of the text when hovered. Set the "paused" value for the animation-play-state .

How do you add an animation to text in HTML? ›

How To Make Animated Text Using HTML And CSS - YouTube

How do I fade a background image in CSS? ›

To fade a background image, the general steps are to:
  1. Stack 2 layers of <div> together to create the foreground and background. <div id="front"></div> ...
  2. Position and set the dimensions of the <div> containers. #front, #back { position: absolute; width: 100vw; } ...
  3. Lastly, set the background image and opacity.
Dec 28, 2021

How do I fade a div in CSS? ›

Use animation and transition property to create a fade-in effect on page load using CSS. Method 1: Using CSS animation property: A CSS animation is defined with 2 keyframes. One with the opacity set to 0, the other with the opacity set to 1.

How do you fade out a video in Filmora? ›

Double click on the video footage in the timeline, and then go to the Animation tab. Move the playhead in the timeline and then click the Add button accordingly, and then adjust the Opacity slider to make a fade effect.

How do I fade out music in Filmora? ›

If you need to detach the audio file from the video, you can use the Detach audio feature in Filmora to accomplish it easily. Find the "Fade Out" option from the context menu. Double click on the target file and switch to the "Audio" column. Then drag the slider bar until the audio is faded to your liking.

What is the correct syntax of animate () method? ›

jQuery Animations - The animate() Method

The jQuery animate() method is used to create custom animations. Syntax: $(selector). animate({params},speed,callback);

How do I fade to black in Premiere Pro? ›

Premiere Pro Fade In Fade Out Video Effect (Fade to Black) - YouTube

How do I fade-out graphics in Premiere Pro? ›

How to Fade in Text in Premiere Pro - Super EASY - YouTube

How do you fade an animation? ›

Fade in and Fade Out in Adobe Animate - YouTube

How do I fade a background image in CSS? ›

To fade a background image, the general steps are to:
  1. Stack 2 layers of <div> together to create the foreground and background. <div id="front"></div> ...
  2. Position and set the dimensions of the <div> containers. #front, #back { position: absolute; width: 100vw; } ...
  3. Lastly, set the background image and opacity.
Dec 28, 2021

How do you use transition properties? ›

The transition-timing-function property can have the following values:
  1. ease - specifies a transition effect with a slow start, then fast, then end slowly (this is default)
  2. linear - specifies a transition effect with the same speed from start to end.
  3. ease-in - specifies a transition effect with a slow start.

How do you delay animation in CSS? ›

CSS Animation Delay Syntax

The CSS animation-delay property has the following syntax: animation-delay: [time] | initial | inherit; As you can see, there are three possible values: time, initial, and inherit. The first option is [time], which is the number of seconds or milliseconds before the animation starts.

How do I fade in and out text animation? ›

Animate CC working with text - how to fade text in and out - YouTube

How do you fade an object in animate? ›

Animate will create a smooth fade-in effect.
  1. Move the red playhead to the first keyframe of the motion tween (frame 10). ...
  2. Select the cityscape instance on the Stage.
  3. In the Properties panel, Color Effect section, choose Alpha from the Style menu.
  4. Set the Alpha value to 0%.
Mar 25, 2017

What is fade in and fade out effect? ›

The Fade In/Fade Out behavior lets you dissolve into and out of any object by ramping the opacity of the object from 0 percent to 100 percent at the start, and then back to 0 percent at the end. You can eliminate the fade-in or fade-out effect by setting the duration of the Fade In Time or Fade Out Time to 0 frames.

How do you blur text in CSS? ›

The first way of creating a blurred text is making your text transparent and applying shadow to it. The shadow will make the text appear blurred. Use a <div> with an id "blur". Then, set the color property to its “transparent” value and define the text-shadow property to give a shadow to the text.

How do I blur a div in CSS? ›

The trick is to use background-position:fixed; on html / body and the element to blur on top of it, so , both background-image lays on the same area of the window. The duplicate uses an extra element, this can be a pseudo element if you do not wish to modify HTML structure. Flex can also be used to center body.

How do you blur in CSS? ›

Syntax. filter: blur(px); To apply a blur effect to the background image, with the blur function use the z-index property to set the stack order of the element, set the width and height 100% to have a full background image.

How do you give multiple transitions in CSS? ›

For multiple transitions, use the CSS3 transition property, which is a shorthand property. It sets the property, duration, timing, and delay of the transition in a single line.

How do CSS transitions work? ›

CSS transitions let you decide which properties to animate (by listing them explicitly), when the animation will start (by setting a delay), how long the transition will last (by setting a duration), and how the transition will run (by defining a timing function, e.g. linearly or quick at the beginning, slow at the end ...

Which CSS property is used for transition effect? ›

Definition and Usage. The transition-property property specifies the name of the CSS property the transition effect is for (the transition effect will start when the specified CSS property changes). Tip: A transition effect could typically occur when a user hover over an element.

How do I make an image bounce in CSS? ›

To create a simple bounce effect with CSS, we can use a combination of keyframes and animations.
  1. Create the HTML element. <div id="demo"></div> ...
  2. Define the bouncing keyframes, and attach it to the element. @keyframes bounce { 0% { transform: translateY(0); } 100% { transform: translateY(-50px); } }
Feb 28, 2022

How do I slow down hover in CSS? ›

how to slow down hover effect css
  1. -webkit-transition: all 500ms ease;
  2. -moz-transition: all 500ms ease;
  3. -ms-transition: all 500ms ease;
  4. -o-transition: all 500ms ease;
  5. transition: all 500ms ease;
Aug 29, 2020

What is animation delay in HTML? ›

The animation-delay CSS property specifies the amount of time to wait from applying the animation to an element before beginning to perform the animation. The animation can start later, immediately from its beginning, or immediately and partway through the animation.

Top Articles
Latest Posts
Article information

Author: Ouida Strosin DO

Last Updated:

Views: 6551

Rating: 4.6 / 5 (56 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Ouida Strosin DO

Birthday: 1995-04-27

Address: Suite 927 930 Kilback Radial, Candidaville, TN 87795

Phone: +8561498978366

Job: Legacy Manufacturing Specialist

Hobby: Singing, Mountain biking, Water sports, Water sports, Taxidermy, Polo, Pet

Introduction: My name is Ouida Strosin DO, I am a precious, combative, spotless, modern, spotless, beautiful, precious person who loves writing and wants to share my knowledge and understanding with you.