OneBite.Dev - Coding blog in a bite size

remove underline from hyperlink css

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

In digital content, hyperlinks typically feature an underline, which is a widely recognized indicator of a clickable word or phrase. However, in some design contexts, you may prefer to eliminate this aspect. In this article, we will explain how to remove the underline from hyperlink using CSS.

The easiest way to remove the underline from a hyperlink is by using CSS. Here’s a basic code snippet:

a {
    text-decoration: none;
}

In the above code, “a” represents the hyperlink. The property “text-decoration” is used to specify the decoration added to the text and “none” means no decoration.

Let’s take the code step by step for a clear understanding of how it works.

  • Step 1: a - This is a CSS selector. The ‘a’ selector selects all the links on a page.

  • Step 2: { } - These curly brackets are used to contain the rules to be applied to the selector. Anything placed inside these brackets will affect the elements selected by the selector.

  • Step 3: text-decoration: none; - This is the rule we’re applying. The text-decoration property in CSS handles the decoration of text. By default, a hyperlink is underlined. However, setting ‘text-decoration’ as ‘none’ removes any decoration.

So, by defining this CSS rule, all links on your page will not have the underline. If you want to apply this rule to only specific links, you can use a class or id selector instead of the ‘a’ selector.

For instance, if you want to remove the underline from a hyperlink with the class ‘myHyperlink’, your code snippet would look like this:

.myHyperlink {
    text-decoration: none;
}

Now only links with the class ‘myHyperlink’ will have the underline removed. Using this simple technique, you can noticeably clean up the look of your hyperlinks and ensure they fit perfectly within your site’s design.

css