How to remove the underline from hyperlinks using CSS?

Removing Underline from Hyperlinks with CSS

Hyperlinks, by default, are underlined in most browsers to distinguish them from normal text. However, there might be scenarios where you might want to remove those underlines to make your webpage more appealing or due to any design considerations.

In CSS, we can achieve this by using the text-decoration property of the anchor tag <a>. The correct code snippet for removing underline from hyperlinks is a {text-decoration:none}.

Here is how it's explained:

  • a: The anchor tag which is used to define the hyperlinks.
  • {text-decoration:none}: In CSS, the text-decoration property is used to set the text formatting to none.

So, simply put, this line of code is instructing the browser to remove any text formatting (in our case underline) from the anchor tag.

Let me illustrate this with an example:

<!DOCTYPE html>
<html>
<head>
<style>
a {
  text-decoration: none;
}
</style>
</head>
<body>

<h2>Removing Underlines from Links</h2>
<p><a href="https://github.com/">This link will not be underlined.</a></p>

</body>
</html> 

In the above HTML document, we have a hyperlink to "https://github.com/". The CSS style text-decoration: none; prevents the link from being underlined.

While removing underlines can be an aesthetic choice, keep in mind that underlines provide a clear visual cue that a text is a hyperlink, improving accessibility. Always consider your audience and how your design choices impact usability, particularly for those who might be visually impaired or those who rely on assistive technology.

Do you find this helpful?