The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS CSS rule for a without href attribute

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #145367

    Hi all. I am new to this forum and have fun browsing the website, thanks!

    I am even newer to wild card uses but love learning. I can’t find a solution for my ‘problem’ on the website and I am sure some smart people here do have an answer. Is it possible to create a class for a tags that do not have the href attribute? Like so:

    a name=”link” rel=”friend”

    How should I do this?


    This is what you are looking for.


    This is a link
    This is a link


    [name="link"] {
         color: red;
    [rel="friend"] {
        color: green;
    Martin Duran

    Hi Folks,

    That selector will work, but I’m not sure how well supported it is. My guess is that older versions of IE don’t support it.

    Frenchness, to answer your question, yes you can add a class to an ‘a’ that doesn’t use a href=””. Style it as you please, it’ll work. And you can be sure that your styled will take place in even old IE browsers.


    Thank you! And thanks to the good old F5 for refresh (thanks for the reminder, it’s a blast from the past) I can finally post a reaction :)

    I am so new to this forum that I didn’t notice the buttons (they are probably too obvious, I am a details kind of person :D ) to post code. So I could not post the entire tags in the original message. It’s a learning curve :) However, here is the code example (some do not have the ‘rel’ attribute) but do have an id).

    `<a name="link" rel="friend"></a>`

    I realize I can style an ‘a’ tag without the href attribute but… I want to style all ‘a’ tags except the ones without the href attribute + I want to separately style the ‘a’ tags that do not have the href attribute.

    So I tried this:

    a :not([href]) {
    background-color: #fff;
    display: inline;

    But it doesn’t work :( It does though rescale images inside rollovers that do have the href attribute. I look forward to understanding this all.


    its a:not(...) and not a :not(...) ( no space between a and : )

    The first one selects an a-element without the href-attribute, the second one selects some element without the href-attribute inside an a-element.


    Thank you.

    I actually tried both yesterday but none worked. Just now though, after a fresh put on the server, it works! (Using the first option without the space).

    Thanks a lot for the help. I am new to this kind of coding and it confuses me a bit. I hope to learn a lot from this forum and who knows, maybe one day I’ll be able to help others myself. I look forward to that!

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘CSS’ is closed to new topics and replies.