"How to Underline Text in HTML: A Step-by-Step Guide"

Gerald Jun 16, 2026

Underlining Text in HTML: A Step-by-Step Guide

How to Underline Text in Illustrator (Every Method & Styling Trick Explained)
How to Underline Text in Illustrator (Every Method & Styling Trick Explained)

When it comes to adding emphasis to specific text on a web page, underlining is a popular choice. In HTML, underlining text is a straightforward process that can be accomplished using a few different methods. In this article, we'll take a closer look at how to underline text in HTML, including the various techniques and best practices to keep in mind.

How to add both an underline and an overline to your text (and in different colors) with HTML + CSS
How to add both an underline and an overline to your text (and in different colors) with HTML + CSS

Method 1: Using the `` Tag

The most straightforward way to underline text in HTML is to use the `` tag. This tag is specifically designed for underlining text and can be easily applied to any text element on a web page.

html notes
html notes

To use the `` tag, simply wrap the text you want to underline with the opening and closing `` tags. For example:

Underlined text

How to Get Rid of Red Underline in Word - Make Tech Easier
How to Get Rid of Red Underline in Word - Make Tech Easier

Method 2: Using CSS

Another way to underline text in HTML is to use CSS. This method provides more flexibility and control over the underlining style, allowing you to customize the color, thickness, and style of the underline.

To use CSS to underline text, you'll need to add a class or ID to the text element and then apply the CSS styles using the `.underline` or `#underline` selector. For example:

HTML Formatting — Text Formatting Tags — TutorialBrain
HTML Formatting — Text Formatting Tags — TutorialBrain

Underlined text with CSS

Here's an example of the CSS styles you can use:

Property Value
text-decoration underline
text-decoration-color red
text-decoration-thickness 2px
a table with several different types of text and numbers on the top, bottom left corner
a table with several different types of text and numbers on the top, bottom left corner

Method 3: Using JavaScript

While not the most common method, you can also underline text in HTML using JavaScript. This method is often used for dynamic underlining effects, such as underlining text that changes or updates in real-time.

a red and black text description for a web page with an arrow pointing to it
a red and black text description for a web page with an arrow pointing to it
HTML Layout Basics: Block vs. Inline Elements 🧱
HTML Layout Basics: Block vs. Inline Elements 🧱
a person typing on a laptop with the text how to code a link in html
a person typing on a laptop with the text how to code a link in html
How to Disable Copy Text in Javascript & CSS
How to Disable Copy Text in Javascript & CSS
Plantpot | Akira Haga's portfolio
Plantpot | Akira Haga's portfolio
text formatting in html info
text formatting in html info
an image of a web page with the text bold and itallic text
an image of a web page with the text bold and itallic text
3 Ways To Create Rainbow Text In HTML CSS
3 Ways To Create Rainbow Text In HTML CSS
an image with the text how to place text over image in html css
an image with the text how to place text over image in html css
How To Make DISCORD COLOR TEXT and Text Formats (Bold Italics Underline) 2021
How To Make DISCORD COLOR TEXT and Text Formats (Bold Italics Underline) 2021
Html notes
Html notes
📝 Create Text Input Forms and Submit Button in HTML
📝 Create Text Input Forms and Submit Button in HTML
How to Underline Text in Illustrator | Envato Tuts+
How to Underline Text in Illustrator | Envato Tuts+
Transparent Text In HTML CSS
Transparent Text In HTML CSS
a poster with some text on it and an image of a computer coder in the background
a poster with some text on it and an image of a computer coder in the background
How do I get a custom colored underline that will span multiple lines?
How do I get a custom colored underline that will span multiple lines?
How To Create Text Slider With Pure HTML CSS
How To Create Text Slider With Pure HTML CSS
a screenshot of the text editor for paragraph and text formating on an iphone
a screenshot of the text editor for paragraph and text formating on an iphone
How to underline text in Google Spreadsheets Shortcut
How to underline text in Google Spreadsheets Shortcut
HOW TO CREATE LINKS IN HTML
HOW TO CREATE LINKS IN HTML

To use JavaScript to underline text, you'll need to select the text element and then add the underline styles using the `textDecoration` property. For example:

const textElement = document.querySelector('.underline');
textElement.style.textDecoration = 'underline';

Best Practices

When underlining text in HTML, there are a few best practices to keep in mind to ensure a smooth user experience:

  • Use underlining sparingly, as it can be distracting and overwhelming.
  • Choose a consistent underlining style throughout your web page.
  • Avoid underlining links, as this can create a conflicting visual cue.
  • Test your underlining effects in different browsers and devices to ensure consistency.

Conclusion

Underlining text in HTML is a simple yet effective way to add emphasis and draw attention to specific text elements. Whether you choose to use the `` tag, CSS, or JavaScript, there's a method that suits your needs. By following the best practices outlined above, you can create a visually appealing and user-friendly web page that effectively communicates your message.

© 2026 Gerald Ideas. All rights reserved.