Today I’ll teach you how top create tooltips purely using Cascading Style Sheets(CSS). Tooltips are basically little blocks of information that are used to inform users about certain attributes of your website elements. This is a tooltip example!Click on this link to see how a tooltip looks like.
Most tooltips are created with the help of javascript or some other programming languages. This can be cumbersome because not everyone wants to learn Javascript. But CSS tooltips are easy to create and can be loaded quickly without any delay.
Here is what you have to do:-
1. Make a blank HTML file and paste the following text in the BODY part :-
This is a pure CSS tooltip!Tooltip 1
This is the HTML part where we create a hyperlink with the text Tooltip1. In the next step, we are going to hide the text within the span tags which will serve as the tooltip text.
2. Now post this CSS information in your HEAD part of the HTML file :-
.tooltip { position:relative; z-index:24; }
.tooltip span { display:none;}
.tooltip:hover {z-index:25;}
.tooltip:hover span {
display:block;
position:absolute;
width:120px;
top:25px;
left:20px;
background-color:#FCFBDC;
border:1px solid #333333;
padding:5px;
font-size:11px;
color:#333333;
text-decoration:none;
font-family:Verdana, Arial, Helvetica, sans-serif;
}
If you look at the above code carefully, we have given the property display:none to the span tag inside the hyperlink. This will make the text inside the span tag invisible. Now when you hover your mouse, we make it appear again by giving the property display:block to the span tag on hover. The positioning of the .tooltip span class is relative because we will place the tooltip text relative to the hyperlink area and make the span tag absolute by defining its fixed position. The z-index is used so that tooltips are in the front of the hyperlink and do not overlap. The more the value of z-index, the farther in the front goes the element.
These tooltips can also be integrated into a wordpress theme easily. Just copy the CSS into your style.css file and when creating your posts, just take help of the HTML code and create your own tooltips. Rest is all styling which can be altered according to your own choice. You may also use images inside the tooltip boxes.
So, just learn this trick and you will be making nifty CSS tooltips in no time. And yes, don’t forget to leave a comment!
54 replies on “Pure CSS Tooltips”
Thank you -.- Sir, you are awesome
Great tips about CSS! Thanks for sharing them.
nice and easy to install,
good article
Very cool tips here!
NICE! but how to shape the box? I mean to make more stylish
thanks
Great work, Thanks.
Hi
I am new at all this and have just used these in a site and they’re working great except for… (why is there always a caveat!!) Is there any way to do this without the href – if someone actually clicks on the tooltip “link”, the page refreshes and they lose their place…???
Thanks!
Wow, nice post, nways thanks for mr. anand for making this work on ie perfectly. And to the makers as well, peace out! 🙂
Awesome, blog post!! I just had to comment.
@mukesh:-
Noted on other sites with a quick google search, add the following:
.aaa2 a.tooltip:hover { /*BG color is a must for IE6*/
background: #E3ECF4;
text-decoration:none;
}
Sign: umsun Hello!!! rcuwwymhyw and 6621ssgfhphzye and 3127Sorry, what did you mean?? A??
I love your site. 🙂 Love design!!! I just came across your blog and wanted to say that I?ve really enjoyed browsing your blog posts. Sign: ndsam
Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.
Looks nice, but there is no text in the tooltip box.
[Firefox 3.5]
Very very nice. Thx a Lot !
for ie6 add
a.tooltip:hover { visibility:visible; }
that’s it!.
hi,
this does not work in IE6 can any one solve this bug?
any help will be appreciated…..
thanx
Good one!
Nice work! Very thankful!
Hi there,
Thanks for the tip! Works great in Firefox and IE7, but the tooltip is not showing in IE6. Any help would be appreciated?!
one question i want tooltip in fixed position in all resolution. is it possible?
It cool thank you for Pure CSS Tooltips
Cool
It cool thank you for Pure CSS Tooltips
I really like this useful tip, thank you!
I tried running the downloaded file but the tooltip is not showing up. Is there any kind of a restriction on the XP machines with SP2 or SP3?
Thanks 🙂
Thanks ! Good tip & Cool…
I do like this especially since it uses CSS and not Js.. but my I ask why you have not used it throughout this whole blog?
Thanks for your nice post ^^
TY! Just what I was after.
Thank you a good tip!
Hey,
Thank you! A Good tip!
Regards,
Jack
<tooltip title=”This is a tooltip”>Trigger a tooltip</tooltip>
How about a tooltip without CSS or JS? Try this on Chrome:
Trigger a tooltip
Awesomeness!
it good Thank!
it is work, let me post about this trick on my blog.
thanks jai!
cool. will try this for my tab menu.
I wonder how they look like in Chrome browser?
great (tool)tip! thanks.
Risorsa davvero carina.. Thanks a lot!
I used to think that these things were done with JavaScript. Now I know CSS can do it!
Thanks alot!
Cool!!!
Very cool tips here!
Thanks. That’s really useful. Is there a way to make this a plugin?
Nice and easy 🙂
I am now design a new theme for my blog’s birthday and I may consider adding this to my theme.
Thinks Jai!
Thanks!Learning…
Hmmm….nice
Adding it right now! Great tip 😉
Let me add this to my CSS
Ahhh.. a CSS tooltip, I’ve always thought of using javascript instead. Good point there 🙂
thanks jai, awesome tips as always!
Good Tips.