4 Ideas For Styling Link Hovers With CSS

July 24, 2010

in Tutorials

CSS Link Hovers

Links are a basic part of the Internet. They’re what keep it connected, really, so why not make these connections fun? A link hover is what happens when you hover your mouse over a link (obviously). Usually you’ll see an underline, or an underline removed, or a different colour. But there are many ways to show people that they can click, so I thought I’d show you four of my favourites.

  1. Transition

    CSS3 has introduced an awesome new property called “transition”. Don’t be scared when I say CSS3, as this degrades perfectly fine and non-supporting browsers will just show a regular hover (I’m looking at you Internet Explorer). You can use this transition property to make your link change colour slowly. It’s a very subtle but nice-looking effect.

    You apply the transition like so:

    a:hover {
       color:#000;
       -webkit-transition:color 500ms ease-in;
       -moz-transition:color 500ms ease-in;
       -o-transition:color 500ms ease-in;
       transition:color 500ms ease-in;
    }
    

    Check me out, I’m an example.

  2. Shadow

    Another CSS3 trick. Make sure to specify this along with a colour, as otherwise it won’t degrade nicely at all and your older browser users will get confused.

    a:hover {text-shadow: 1px 1px 1px rgba(0,0,0,.4);}
    

    If you hover me, good things will happen.

  3. Move

    This is a simple one, but one that I like and use a lot. You can add some cool interactivity if you slightly alter a link’s position on hover.

    a:hover {position: relative; top: 2px;}
    

    I just can’t stay still when you hover me!

  4. Opacity

    This is a trick for images, and one that I use all the time. It’s nice to give images a hover state, as not all images are clickable, so you should be letting your readers know which ones are.

    a.img {opacity: .5;}
    

    You can see an example of this on the social media links at the top of this page. These links also move.

Well there they are. There’s nothing super mind-blowing here, but it’s the little details that count and will make your website a little more special. Are there any techniques that you like to use? Share them in the comments.

image by aidan morgan

Thesis Theme for WordPress:  Options Galore and a Helpful Support Community

You'll notice this site talks about the Thesis theme for Wordpress. Don't know what the heck that is? Find out.

{ 15 comments… read them below or add one }

Aurélien Lewin July 25, 2010 at 2:29 pm

What does -o-transition means? Others browsers?

Reply

Matt Dunn July 25, 2010 at 2:32 pm

Opera.

Reply

Freelance Web Design July 26, 2010 at 7:30 am

Great! Is transition:color for IE9?

Reply

Benjamin Reid July 26, 2010 at 1:04 pm

Some good tips there. I’d only make a link move when you click it (a:active), so it looks like it’s actually been pressed on the page – a satisfying UI element.

Reply

Matt Dunn July 28, 2010 at 1:59 am

That’s a sweet idea.

Reply

Alejandro Gonzalez July 26, 2010 at 1:54 pm

Great tips on css3. Looking up to using these soon. Thanks

Reply

ivan July 26, 2010 at 4:55 pm

transition doesn’t work on my firefox 3.6.8 or maybe i can’t see what really it do, in my case just is a normal change color,

excellent tips

Reply

Matt Dunn July 26, 2010 at 4:58 pm

Yep. Transition only works on Webkit-based browsers right now such as Safari (and Chrome). Hopefully soon -moz will kick in. Luckily it falls back to a regular hover.

Reply

Tony August 30, 2010 at 7:45 am

I like to combine both text shadow and transition. Has a really neat effect.

Reply

Jon Rawlins September 27, 2010 at 4:00 pm

It’s a shame that opacity alone doesn’t work in IE, even ie8 doesn’t support it without hacking it. A few things to think about is when you use a background image which is positioned, and then the hover is respositioned it will generally transition between the two which isn’t always a good thing. So it slides up for example when you have created Tabs. Therefore giving it the wrong feel totally.

Jonathan

Reply

Véronique October 16, 2010 at 5:02 pm

Hello, how can I manage to change the opacity of a div (instead of an image as shown in your demo) when I hover it? I tried and succeeded with an image but cannot find any answer when hovering a div (with a background image repeat-x). Thank you very much!

Reply

Brett Widmann January 9, 2011 at 4:01 am

I really like these ideas. Thanks for the code!

Reply

Ash January 16, 2011 at 9:28 am

I’m sure gonna be using the opacity trick. I love it!

Reply

Vivian September 19, 2011 at 11:45 pm

Can anyone help? This is the css code I have for my links so that when I hover over them the text displays as white.
.custom a:hover { background: #D31D8C; color: #FFFFFF; !important; }

This works on my Home page, but on my Links & Resources page, no text is seen when I hover. What must I do?

Thanks, Vivian.

Reply

Rohit November 14, 2011 at 7:17 pm

i cant do the opacity css in my link… can u tell me why??? i am pasting my html

and in the css i have written
a {
position:fixed;
top:200px;
left:375px;
}
a:hover {position: relative; top: 2px;}
img {
position:fixed;
top:200px;
left:375px;
}

Reply

Leave a Comment

Previous post:

Next post: