Hello I have a question about :link
pseudo-class. I’m following your course on CSS and this pseudo-class is first used in “Styling Links” section.
Styling links - Learn web development | MDN (mozilla.org)
If I understood correctly it is used to style links that have not been visited so far. But that same thing could be achieved using a plain a selector, right?
Furthermore, here it says it could be used to differentiate between regular links and those that are just placeholders. Is this common practice, to have placeholder links? It seems a bit weird to me?
So, the links that have not been visited will have the default color that was defined with regular a
selector or maybe some class. Those that have been visited will be styled using the :visited
pseudo-class. ---- I see no reason to use :link
in this case
Again, here you used the a
selector to define outline
and text-decoration
, and you later used a:link
to define color. Wouldn’t it be the same if you put that color declaration inside of the above a
ruleset?
All things considered :link
seems a bit redundant to me, but I know that there must be a reason for it to exist. Could please give me some more info so that I could understand its use better. Thanks!!
Hello @Rastko_Gojgic
selector a will apply to any a element but
:link will apply only to a or area that has it’s href attribute set and never visited before
try to click the link and in the only a selector the color stay the same
but in the a:link the color change to the default visited value (of course if you did no set it )
please let me know if i need to explain it in better way 
1 Like
Hello, thanks for the reply
I’m afraid I need more clarification. I will try to rephrase my question, maybe I wasn’t explicit enough.
Can you give me an example of those links without destination (without href set)? Why and when are those used? When do they appear so we have to use :link
in order not to target those. I have never seen that in real life.
Ok, so I did that. If I delete the a:link {color: #265301;}
line of code the links get back to blue color. This is expected since I don’t have the color declaration in the original a {outline: none; text-decoration: none; padding: 2px 1px 0;}
line of code.
But if I put the color declaration inside of a
rule set and delete the :link
rule set I will get the same result.
So, my question is why have we split one rule set in two rule sets when the effect is the same. The only reason could be to target those links without destination that you have mentioned, but how often these links are used anyway?
As I said I have never seen those, and you haven’t mentioned them inside of your HTML and CSS courses.
you welcome
- first the point is - is it valid or not in js part you can use for loop as this
for(;;);
and it’s valid but would you see it manytimes in the people code that different story so in programing there 2 things
a) syntax which will not work if you did not follow it
b) symantic which mean you are using wrong code despite it valid from syntax point of view which lead to wrong result like if your function should add 2 numbers but you use - operation instead of + operation
so i do not have use case to help with it check this one check the first answer in this post
check this example
if you removed the a selector and kept only a:link then
only the color will be applied to the second link and if you click on that link it will change it’s colour to default color which is purple and the red color would not be applied to any
if you kept the a and removed the a:link the color will always be yellow for both links and for the second link it will always be yellow despite it visited or not
be careful to this last one
not just without href but also not visited
if it visited link then a:link would not be applied
also link can be use with area check this :link - CSS: Cascading Style Sheets | MDN
i am a learner same as you 
1 Like
Oh ok, then you know how confusing everything can be at times.
I think it makes a bit more sense to me now, thank you for help.
Basically if we don’t set pseudo classes like :hover, :visited or :link
, and we set a{color:yellow;}
, that color declaration will overwrite all other link color properties for all possible states.
(In this case these are colors set by the browser which are blue, purple and so on). In other words, it will always be yellow.
Likewise if we set a{color:yellow;} and a:link{color:red;} but we don’t set a:visited{}
the link will be red, but if we visit it, then it will turn yellow. That’s because it reverts to what it is specified in the **a**
ruleset.
I think I get it now, basically the best practice would be to define the styles using pseudo classes and not using the a
or some other selector.
Please correct me if I’m wrong 
Thanks again !!!
1 Like
you very welcome and when i get confused i reread it again or ask someone else cause sometime my brain keep miss the same thing manytimes 
and you got it right 
i prefer to say the best practice depend on the use case so for example let say i want to color a to be red despite it has href or not then using a only would be good choice and of course it would make sense to set the visited and other cases so it does not always be same color
and you very welcome 
1 Like
Great, thank you so much for help!!!
Have a nice day and keep learning 
2 Likes