There are many CSS properties that can set the link style. The peculiarity of a link is that it can be styled according to the state in which they are located. Four states of the link:
- A:link Common, inaccessible links
- a:visited user has visited the link
- A:hover the mouse pointer is over the link
- A:active the moment the link was clicked
When setting styles for different states of a link, follow these order rules:
- A:hover must be located after A:link and a:visited
- A:active must be located after a:hover
Common Link Properties:
- The Color property specifies the colors of the link display
- The Text-decoration attribute is mostly used to remove underscores from links
- Background-color attribute specifies the background color of the link
<!--This example shows how to add a variety of styles to a link -<!DOCTYPE HTML><HTML><Head><style>A.one:link{Color:#ff0000;}a.one:visited{Color:#0000ff;}A.one:hover{Color:#ffcc00;}A.two:link{Color:#ff0000;}a.two:visited{Color:#0000ff;}A.two:hover{font-size:150%;}A.three:link{Color:#ff0000;}a.three:visited{Color:#0000ff;}A.three:hover{background:#66ff66;}A.four:link{Color:#ff0000;}a.four:visited{Color:#0000ff;}A.four:hover{font-family:' Microsoft Ya Black ';}A.five:link{Color:#ff0000;text-decoration:None;}a.five:visited{Color:#0000ff;text-decoration:None;}A.five:hover{text-decoration:Underline;}</style></Head><Body><P>Please move the mouse pointer over the links below to see their style changes.</P><P><b><aclass= "One"href= "/index.html"Target= "_blank">This link changes color</a></b></P><P><b><aclass= "both"href= "/index.html"Target= "_blank">This link changes the font size</a></b></P><P><b><aclass= "three"href= "/index.html"Target= "_blank">This link changes the background color</a></b></P><P><b><aclass= "Four"href= "/index.html"Target= "_blank">This link changes the font</a></b></P><P><b><aclass= "Five"href= "/index.html"Target= "_blank">This link changes the decoration of the text</a></b></P></Body></HTML>
<!--This example shows a more advanced example, and we combine several CSS properties to show the link as a box -<!DOCTYPE HTML><HTML><Head><style>a:link,a:visited{Display:Block;Font-weight:Bold;font-size:14px;font-family:Verdana, Arial, Helvetica, Sans-serif;Color:#FFFFFF;Background-color:#98bf21;width:120px;text-align:Center;padding:4px;text-decoration:None;}a:hover,a:active{Background-color:#7A991A;}</style></Head><Body><ahref= "/index.html"Target= "_blank">W3school</a></Body></HTML>
CSS Styles-Links