OneBite.Dev - Coding blog in a bite size

remove the underline from a hyperlink in css

Code snippet for how to remove the underline from a hyperlink in css with sample and detail explanation

Frequently when adding hyperlinks to a webpage, a default underline appears underneath. While these can be useful for making links immediately noticeable, you may prefer a cleaner, more minimalist style. In this article, we are going to demonstrate how to remove the underline from a hyperlink utilizing CSS.

Let’s begin with a straightforward example of CSS code to remove the underline.

a {
  text-decoration: none;
}

In this small snippet, a represents all the hyperlinks on your webpage. The property text-decoration with a value of none signifies that no additional styling (in this case, underlining) should be added to the link.

Now that we know what the code looks like, let’s break down exactly what’s happening.

  1. a: This is known as a selector in CSS jargon. A selector targets, or selects, HTML elements that you wish to style. In this case, all hyperlinks on your webpage, which are associated with the <a> tag, are being targeted.

  2. {…}: These braces enclose the properties you wish to apply to the selected HTML element. These can include a wide range of styling options, such as color, size, font, and in this case, text decorations.

  3. text-decoration: none; This is a CSS property-value pair. “text-decoration” controls the decoration added to text, and “none” means that no decorations are added. Therefore, if the element (in this case, hyperlinks) had initially been underlined as per the browser defaults, this property will remove that underline.

Remember to include this CSS code within a <style> tag in the HTML head section of your document, or save it as an external .css file that you can link to your HTML page. This simple yet elegant solution gives you mastery over the appearance of your hyperlinks, and indeed, your entire web page.

css