Do you want to create fancy headings without rendering each heading with Photoshop? Here is a simple CSS trick to show you how to create gradient text effect with a PNG image (pure CSS, no Javascript or Flash). All you need is an empty <span> tag in the heading and apply the background image overlay using the CSS position:absolute property. This trick has been tested on most browsers: Firefox, Safari, Opera, and even Internet Explorer 6. Continue to read this article to find out how.
Benefits
- This is pure CSS trick, no Javascript or Flash. It works on most browsers including IE6 (PNG hack required).
- It is perfect for designing headings. You don't have to render each heading with Photoshop. This will save you time and bandwidth.
- You can use on any web fonts and the font size remains scalable.
How does this work?
The trick is very simple. Basically we are just adding a 1px gradient PNG (with alpha transparency) over the text.
The HTML markups
<h1><span></span>CSS Gradient Text</h1>
The CSS
The key point here is: h1 { position: relative } and h1 span { position: absolute }
h1 {
font: bold 330%/100% "Lucida Grande";
position: relative;
color: #464646;
}
h1 span {
background: url(gradient.png) repeat-x;
position: absolute;
display: block;
width: 100%;
height: 31px;
}
That's it! You are done. Click here to view my demo page.
Make it work on IE6
Since IE6 doesn't render PNG-24 properly, the following hack is required in order to display the transparent PNG (add anywhere in between the <head> tag):
<!--[if lt IE 7]>
<style>
h1 span {
background: none;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='gradient.png', sizingMethod='scale');
}
</style>
<![endif]-->
This is why we hate IE 6!
jQuery prepend version (for semantic lovers)
If you don't want to have the empty <span> tag in the heading, you can use Javascript to prepend the <span> tag. Here is a sample using jQuery prepend method:
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//prepend span tag to H1
$("h1").prepend("<span></span>");
});
</script>
More samples
Want to make Web 2.0 glossy text?

Literally, you can apply this trick on any solid background color (as long your gradient color is the same as your background color).





Pattern / Texture
You can also apply this trick with a tile background image. Look, here is an example of zebra pattern. So, be creative!

Limitations and more...
- This trick is only suitable for solid background color elements. Your gradient color (PNG image) must be the same color as your background color.
- IE PNG hack is required if you want it to work on IE 6.
- If your gradient image is taller than the heading, the text will not be selectable.


Clever. I’ll definitely bear this in mind should an appropriate project arise. Keep thinking outside the box! (”,)
Slick and simple. My favorite kind of tip.
What a great tip!!! Nice creative thinking. Thanks much!
~ jen
thats awesome, youre are “The” best designer!!!!!!
Nice effect!
But it doesn’t seem to work correctly when viewed through FeedDemon 2.6 (on WinXP SP2 with IE6).
kick ass my friend, kick ass
Looks real simple to boot!
I will be integrating that into a project next week
Nice trick!
that’s a brilliant idea. such a small touch, but makes a huge difference.
thanks
oh that is super slick… simple in concept and practice, but such a leap to actually get there. As a wise man once said, “genius is almost always displayed in great simplicity of method.”
Really like the tip, good to see that you thought of making it usable for links which is important. My only issue is that this will give people an excuse to continue with the over used shiny glossy look which is so arrgghhh old fashioned and rehashed!
Oh for some designers to think of something new rather than rehashing other peoples rehashed designs.
This is fantastic! I can’t wait to find an excuse to use this, thanks a bunch.
Wow, this is such a great tip/trick. Wish I thought of it!
This is really a tricky technique. How could you find that out?
This is just perfect for my upcoming design on my own blog. I was having thoughts on whether I should write a php function for this kind of font style but I’m too lazy for that. haha.
This is really a big help
That’s really great. I might use it. :) thanks.
Fantastic, the dark background sample looks the best. Very handy trick, may use this in the future!
Respect to your great work and i will use perhaps :)
Ralph
Pure Web 2.0 heading technique ;) thx
This is a nice technique although not too new actually. Essentially it’s the same as the “worn type” CSS technique (published on Nov 2005) but instead of a grunge pattern it uses a simple gradient to make text shiny. In essence, the web designer can transform typical headings using whatever pattern they wish on top of the text.
But what I don’t really like is the extra
<span>in the headers, so when I use such techniques I’d go with the jQuery approach &ndash it won’t do good if JavaScript is off, but it’s better than having to insert a (non-semantic) empty<span>tag inside every heading! (And how has JavaScript off anyway?)In the worn type article, the author also has a page with examples, similar to the ones you’re displaying, check it out.
so easy, so great!