CSS How To Remove Underline From Link - Peter Lunch
Maybe your like
When styling a website you may want to remove the default underline from a link, like I have in with my navbar links.
Fortunately CSS offers many ways to remove the underline from a link. In this post you will learn how to remove underlines from links using CSS.
Firstly, when removing an underline from a link in CSS you need to understand what state it is in. The different states of a link are known as pseudo-classes, not to be confused with pseudo-elements and which state the link is in depends on the users activity.
The four different pseudo-classes are.
- a:visited - the user has visited the link and it is stored in the browsers history
- a:active - right as the user is clicking on the link
- a:hover - the user is hovering their mouse over the link
- a:link - the default state of a link, meaning the use has not visited, hovered or clicked on the link yet.
Due to links being underlined originally to help the user determine that they could click a link, a links default is to have an underline for each of the above pseudo-states.
In order to remove the underline from your links, you can use the CSS text-decoration property.
This property has four values, underline, overline, line-through but the value we care about is none.
Here are a few ways to remove underline from link using the CSS property.
/* remove underline from all link states */ a{ text-decoration:none; } /* remove underline from links individual states */ a:link{ text-decoration:none; } a:visited{ text-decoration:none; }In the examples above we make CSS remove the underline for the link by adding text-decoration:none to all of the link states.
It is important to note that order matters with the pseudo-classes, a:link and a:visited must come before a:hover and hover must come before a:active. When you think about it, it's common sense. A link is in it's default state before you can visit it and it will be hovered over before the user clicks it, finally it sets the state to active. You can remember the states with a handy acronym LVHA (link, visited, hover, active).
Let's look at some examples to see how we can remove the underline from some states but keep it for others.
There is one more powerful CSS pseudo-class selector that can manage state for our links and it is the :any-link pseudo-class selector.
:any-link matches all elements that match :link or :visited so we can easily remove the underline for any link element that has a href attribute.
:any-link{ text-decoration:none; }If you enjoyed this post you might also like my posts on…
- How to build a plan to successfully learn to code: A Step-by-step guide
- How to create a responsive gaming style Navigation Bar with HTML & CSS
- How to Plan and Build a Programming Project – Guide for Beginners
- Why I’m Learning to code
Tag » How To Remove Underline Link Css
-
How To Remove The Underline From Links In CSS - HubSpot Blog
-
CSS Styling Links - W3Schools
-
Remove Blue Underline From Link - Css - Stack Overflow
-
How To Remove Underline From A Link In CSS – HTML Style Guide
-
How To Remove Underline For Anchors Tag Using CSS? - GeeksforGeeks
-
How To Remove Underline From A Link In HTML? - Tutorialspoint
-
Remove The Underline From Hyperlink Text - Microsoft Support
-
Removing Underline From Link Elements Using CSS
-
Remove Underline On A Link Using CSS - YouTube
-
How Do I Remove The Underline From My Text Links?
-
HTML And CSS Tutorial: Removing Links Underline
-
How To Remove The Underline From Links In Neve - ThemeIsle Docs
-
How To Remove An Underline From One Specific Link In CSS - Quora
-
Macromedia - Turning Off Link Underlining In Dreamweaver 3 And 4