Treehouse: Grow your CSS skills. Land your dream job.

Difference between ‘a:link’ and just ‘a’

  • # November 25, 2008 at 8:18 am

    Hi guys,

    I’ve never really understood the magic of links and css, sometimes it just works using a:link instead of just a. How does it actually work?

    Does the a element target both a:link, a:visited, a:active and a:hover? No..

    When having to style nested menus it can get a bit messy with all the css selectors you need on a three-level-menu :)

    # November 25, 2008 at 10:00 am

    I think its just being specific. They both do the same.

    When you use a: hover – you’re being specific to the anchor hover state
    like wise a:visited and a:active

    I would guess the actual proper way to write it (if you try to think like the W3C) would be:

    a:link {
    color: #666;
    a:visited {
    color: #030;
    a:hover {
    color: #333;
    a:active {
    color: #0C3;
    # November 25, 2008 at 10:08 am

    I have to start declaring link for the anchor styles. It is indeed the correct way to do it.

    # November 26, 2008 at 2:15 am

    Alright, thank you for clearing it up for me, Jonz.

    # November 26, 2008 at 11:23 am

    I *think* the a:link will only affect anchor links that actually have an href attribute, which isn’t required. so

    a:link {
    color: red;

    would affect:

    <a href="#">something</a>

    but not:


    I could be wrong though? Someone should do a quick test =)

    # November 26, 2008 at 12:38 pm

    I don’t think that’s correct Chris.


    Link Text

    Anchor Text

    The outcome was:

    Link Text

    Anchor Text

    # November 26, 2008 at 5:24 pm


    # November 26, 2008 at 6:34 pm

    Oh yeah…

    I must have not saved on the refresh or something :?

    Sorry about that.

    # December 1, 2008 at 5:51 am

    Thanks all. I just discovered these posts by Eric Meyer. It’s definitely worth a read.
    Link Specificity, Ordering the Link States and Who Ordered the Link States?

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.