A Simple Fade with CSS3
by c.bavota | Posted in Tutorials | 15 comments
There was a time when the only way to fade an element or image was by using JavaScript/jQuery (see Creating a Mouseover Fade Effect with jQuery). With CSS3, you can easily create a fade effect with nothing more than a little CSS.
Let’s start with a text element:
<p class="fade">This is my text element that will fade when you hover over it.</p>
Now comes the CSS3:
.fade {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.fade:hover {
opacity: 0.5;
}
Hover over the text below to see a live demo:
This is my text element that will fade when you hover over it.
Let’s do the same thing with an image:
<img src="http://bavotasan.com/wp-content/uploads/2011/09/fadeimage.jpg" alt="" width="200" height="150" class="fade" />
Hover over the image below to see it in action:

We can also set it up so that a background color fades in. Let’s create a simple menu using an unordered list:
<ul class="nav-fade"> <li>Home</li> <li>Tutorials</li> <li>Articles</li> </ul>
Now for the CSS3:
.nav-fade li {
background: #fff;
padding: 3px 8px;
display: inline-block;
transition: background .25s ease-in-out;
-moz-transition: background .25s ease-in-out;
-webkit-transition: background .25s ease-in-out;
}
.nav-fade li:hover {
background: #ddd;
}
Let’s see it live:
As you can see, there are quite a few possibilities when it comes to using CSS3 to create a simple fade effect. As always, remember that CSS3 only works on modern browsers.
Resources



This is a great technique that you can use to really help add visual appeal to your site. I love it on the nav, thanks for the tip!
I’ve been thinking about implementing these CSS3 effects in my own site but I wondered do you know which versions of IE and Mozilla support these neat tricks?
As I understand it you have to have a pretty up-to-date browser.
In my own design project: http://www.riskcompliancejobs.com, I’m looking to avoid as much javascript as possible because the load on the server is quite large despite gzip and minify.
Most CSS3 will work only in IE9. It should work in Firefox from around FF3.0 onward.
This is a nice effect if you use photos a a navigation, but what happens if a visitor has an old browser version? What would he or she see?
They won’t see the fade effect in older browsers. The opacity and the transitions will not work.
Nice effects! It’s good to see CSS 3 getting more exposure – it’s certainly the least graphic-intensive or browser-burdening way of producing some really slick effects. You can always have a jQuery fall-back option for the older browsers with the use of some if statements.
nice tutorial! thanks for this!
Thanks for this tutorial. I’m currently getting started with CSS3 for my design course and will try this. Lets see if I can make it work
.
nice code, but doesn’t work in IE9
bummer
Many things don’t work in IE9. Maybe IE10 will prove to be a better browser. Maybe…
Thanks for the tutorial on the simple fade. I have an image on my website that I tried this with and I love the look. Your tutorial was very easy to follow along with. It made the coding process so much easier.
Nice tutorial, very simple.
Now I don’t want the image to be lighter when mouseover, I want it to be darker.
What can I do?
You can’t really make an image darker than it is, unless you add a black transparent overlay.
Really good tutorial! Creds
Thanks so much bavota
. This the one I’ve been looking for.