How to underline a text in HTML?


Underlined text is used to help draw attention to the text.

We use the <u> tag, to underline a text in HTML. It represents a text in a different style from another text in the content of the web page.

We can also use the style attribute, to underline a text in HTML. The style attribute specifies an inline style for an element. This attribute is used inside the HTML <p> tag, with the CSS property text-decoration property.

Syntax

Following is the syntax to underline a text in HTML.

<u>The content to be underlined</u>

Example

Following is the example program to underline a text in HTML.

<!DOCTYPE html> <html> <head> </head> <body> <p>DLF stands for <u>Delhi Land and Finance </u>. <br> Delhi Land and Finance is one of the largest commercial real estate developer in India.</p> </body> </html>

Example

In the example below, we underlined the text inside the <h1> element.

<!DOCTYPE html> <html> <head> <title>HTML u tag</title> </head> <body> <h1><u>we are underlining the text inside the '<h>' element.</u></h1> </body> </html>

Underlining text by inline CSS

Underlining text using CSS property. This property is used inside the <p> tag.

Syntax

Following is the syntax for underlining a text using CSS property.

<p style="text decoration:underline;">The content to be underlined</p>

Example

Following is the example program to underline a text using CSS property.

<!DOCTYPE html> <html> <head> </head> <body> <p>DLF stands for</p><p style="text-decoration:underline;">Delhi Land and Finance. </p> <p> Delhi Land and Finance is one of the largest commercial real estate developer in India.</p> </body> </html>

Updated on: 02-Sep-2023

65K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements