Peter
Peter

Reputation: 4819

Get underlined text with Markdown

How can I underline text in Markdown?

Upvotes: 481

Views: 775709

Answers (9)

Paw in Data
Paw in Data

Reputation: 1604

Both <ins>text</ins> and <span style="text-decoration:underline">text</span> work perfectly in Joplin, although I agree with @nfm that underlined text looks like a link and can be misleading in Markdown.

Upvotes: 6

Gabriel Staples
Gabriel Staples

Reputation: 53225

Just use the HTML <u> tag (recommended) or the <ins> tag inside your markdown for this.

The HTML tag <ins> is the HTML "insert tag", and is usually displayed as underlined. Hence, you can use it for underlining, as @BlackMagic recommends in his answer here. It is the opposite of the <del> delete tag.

But, I'd prefer and I recommend to just use the HTML <u> underline tag, since that's exactly what it's for:

<u>this is underlined text in HTML or markdown, which accepts HTML</u>

@zed_0xff also recommends using the <u> tag in his answer here.

You can try it out live online here: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_u.

What about underlined headings on GitHub?

@NoChance left in the comments:

I guess the <u> does not work with #, for example, let's say you have Header 3 and you want to make it bold and underline - what can one do?

In this case, for it to work on GitHub, you have to use <ins> in place of <u>.

Do this:

# <ins>Underlined Heading 1</ins>
## <ins>Underlined Heading 2</ins>
### <ins>Underlined Heading 3</ins>
#### <ins>Underlined Heading 4</ins>
<!-- etc. -->

That works on GitHub too! Sample output on GitHub:

enter image description here

Using <u> in place of <ins> there will work on most markdown viewers, but not on GitHub.

See a full demo and trial file in my eRCaGuy_hello_world repo here: eRCaGuy_hello_world/markdown/underline.md.

Can I use CSS too?

It depends. On your custom Jekyll website? Sure. In GitHub readmes and other GitHub markdown files? No!

HTML tags work fine in GitHub readmes too, because GitHub accepts HTML tags just fine. BUT, custom CSS in GitHub does NOT work since GitHub blocks and rejects all custom CSS you may try to add. I talk about this in my other answer here: How do I center an image in the README.md file on GitHub?.

Upvotes: 69

Hugo Laguna
Hugo Laguna

Reputation: 202

that is NOT best practice because is a link but you can do this in some libraries

[example link with #](#)

but for example, here on stackoverflow doesn't work

example link with #

Upvotes: 1

BlackMagic
BlackMagic

Reputation: 5788

In GitHub markdown <ins>text</ins> works just fine.

Upvotes: 515

Colonel_Old
Colonel_Old

Reputation: 942

In Jupyter Notebooks you can use Markdown in the following way for underlined text. This is similar to HTML5: (<u> and </u>).

<u>Underlined Words Here</u>

Upvotes: 17

You can wrote **_bold and italic_** and re-style it to underlined text, like this:

strong>em,
em>strong,
b>i,
i>b {
    font-style:normal;
    font-weight:normal;
    text-decoration:underline;
}

Upvotes: 20

jordanbtucker
jordanbtucker

Reputation: 6088

Another reason is that <u> tags are deprecated in XHTML and HTML5, so it would need to produce something like <span style="text-decoration:underline">this</span>. (IMHO, if <u> is deprecated, so should be <b> and <i>.) Note that Markdown produces <strong> and <em> instead of <b> and <i>, respectively, which explains the purpose of the text therein instead of its formatting. Formatting should be handled by stylesheets.

Update: The <u> element is no longer deprecated in HTML5.

Upvotes: 139

zed_0xff
zed_0xff

Reputation: 33257

The simple <u>some text</u> should work for you.

Upvotes: 97

nfm
nfm

Reputation: 20747

Markdown doesn't have a defined syntax to underline text.

I guess this is because underlined text is hard to read, and that it's usually used for hyperlinks.

Upvotes: 261

Related Questions