339

How can I underline text in Markdown?

PotatoFarmer
  • 2,755
  • 2
  • 16
  • 26
Peter
  • 3,399
  • 2
  • 16
  • 3

9 Answers9

376

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

Naman
  • 27,789
  • 26
  • 218
  • 353
BlackMagic
  • 4,378
  • 1
  • 21
  • 14
  • 8
    And in BitBucket too... (as well as text) – рüффп Jul 09 '20 at 08:49
  • 4
    text doesn't work, but I never heard about tag lol, - it's seems because it's so unpopular, it still works (normally it's not very good to underline text) – Jerry Green Nov 04 '20 at 06:39
  • 7
    In case anyone wanted to know `text` works fine in Jupyter notebooks too – Hawklaz Nov 08 '20 at 09:04
  • 6
    I prefer ``. Here's a little more info: https://stackoverflow.com/a/66595330/4561887. – Gabriel Staples Mar 12 '21 at 06:44
  • From [Mardown specs](https://daringfireball.net/projects/markdown/syntax#html): _For any markup that is not covered by Markdown’s syntax, you simply use HTML itself. There’s no need to preface it or delimit it to indicate that you’re switching from Markdown to HTML; you just use the tags._ Specs are clear. Implementations vary... – Pierre Jun 16 '21 at 21:26
  • 1
    Also works in obsidian – jason Feb 28 '22 at 23:01
  • 2
    Also works with Gitlab markdown. The tag DOES NOT work in Gitlab. – Mujeeb Ishaque Aug 11 '22 at 14:34
  • `...` is no longer deprecated in XHTML, but still doesn't work on GitHub. Still going with `...` as of mid-2023, but the semantics are just incorrect, of course. – Chiarcos May 16 '23 at 16:04
221

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.

nfm
  • 19,689
  • 15
  • 60
  • 90
  • "it's usually used for hyperlinks" says someone who probably enters links in markdown input boxes daily. – zylstra Apr 29 '21 at 16:56
  • 3
    @Shredder2794: That's not how markdown is supposed to work. If you find yourself frequently having to write html code inside of markdown, you're probably not using it for the purpose it was meant to be used for. There are edge cases which require html tags and code other than markdown, but again those are edge cases. – Saturn K Sep 22 '21 at 20:51
  • 2
    @zylstra Were you trolling when you wrote your comment or did you actually think that you made a good point? – HelloGoodbye Nov 02 '22 at 13:06
  • 1
    @HelloGoodbye, looking back now I'm not sure *what* I meant. :/ – zylstra Nov 03 '22 at 22:05
115

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.

jordanbtucker
  • 5,768
  • 2
  • 30
  • 43
  • 3
    The semantic analogue of `` is ``; that's never been deprecated. – Toby Bartels Nov 20 '13 at 20:24
  • 6
    @TobyBartels I'm not sure what you mean. "The element represents a span of text with an unarticulated, though explicitly rendered, non-textual annotation," whereas "the element represents an addition to the document." These are two semantically very different things. – jordanbtucker Nov 21 '13 at 00:44
  • 9
    I mean that `` is not particularly a semantic tag at all, while `` is. Yet they are traditionally rendered in the same way. So `` is the semantic analogue of ``, while `` is the syntactic analogue of ``. Well, even if you don't like how I describe it, the point is that we have this analogy: `` : `` :: `` : `` :: `` : ``. (Also `` : ``.) – Toby Bartels Nov 21 '13 at 02:10
  • 5
    @TobyBartels Ah, I misinterpreted you. I thought you were saying that and were semantically equivalent. The HTML5 spec has actually given semantic meanings to , , , and that are different from their stylistically similar counterparts, but I see your point. – jordanbtucker Nov 21 '13 at 16:42
  • I would have thought it not good practice to use an `` tag since it represents inserted text (with `` representing deleted text). In diff tools, including those online, I've mostly seen inserted text rendered as green text (sometimes blue) or with a green background, and deleted text rendered as red text or with a red background. So I think you shouldn't count on `` being rendered as underlined text. Maybe it's an unofficial convention in markdown but there are plenty of places where it wouldn't make sense. – Simon Elms Dec 02 '22 at 00:26
  • 1
    @SimonTewsi You're correct. You should not use `` unless you intend to represent inserted content. Using `` was suggested because, at the time, `` was a deprecated HTML 5 element, but it has since been reinstated and is the recommended way to represent underlined content in Markdown. – jordanbtucker Dec 03 '22 at 01:56
78

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
zed_0xff
  • 32,417
  • 7
  • 53
  • 72
  • I forgot to say that I use the :escape_html option so an user cannot destroy my layout or inject some javascripts. I render that way: `BlueCloth.new("foo", :escape_html => true).to_html`. That will escape the tag. – Peter Jun 09 '10 at 06:37
  • then you cannot have a underlined text. only to manually unescape produced `<u>` and `</u>` back to `` and `` – zed_0xff Jun 09 '10 at 06:54
  • 10
    Wow, one really can have and but not ? Why that? :( – Peter Jun 09 '10 at 09:19
  • 5
    I agree: Why is that? Markdown (or any language like it) should make it *easier* to do common things that people want to do (like underline words), not harder or impossible. – Tyler Rick Sep 27 '11 at 20:37
  • 2
    It's probably because shouldn't be used for simple underlining in HTML5 any longer ... – s.krueger Jul 03 '13 at 09:18
  • 2
    @s.krueger Please read https://html.spec.whatwg.org/multipage/semantics.html#the-u-element. `` can be used for underlining, but is discouraged "where it could be confused for a hyperlink." – jordanbtucker Oct 08 '14 at 18:02
  • @jordanbtucker "The u element represents a span of text with an unarticulated, [...] non-textual annotation, such as labeling the text as being a proper name in Chinese text [...] or labeling the text as being misspelt." Doesn't sound to me as the usual case people here are discussing about :) – s.krueger Oct 08 '14 at 22:16
  • 1
    @s.krueger I think the terms "unarticulated" and "explicitly rendered" are exactly the cases discussed here. When you can't rely on CSS, which can be the case with Markdown, `` is your best option for explicitly rendered underlining. Of course, more semantic elements should be used when possible. – jordanbtucker Oct 09 '14 at 02:31
  • 1
    @Peter: may be because `` and `` are available in HTML5 for italic and bold respectively, but there is no semantic markup for underline – nishanthshanmugham Jun 30 '15 at 11:09
  • 1
    How about `some text`? – Aaron Jul 09 '17 at 22:14
  • 1
    `` doesn't work in some Markdown flavors (like GitHub)... – mropp Jul 27 '21 at 19:44
  • this doesn't underline text in GitHub Markdown – tmillr Oct 25 '22 at 17:52
44

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?.

Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265
  • I guess the 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? Thanks. – NoChance Oct 26 '22 at 00:49
  • 1
    @NoChance, use `### Underlined Heading 3`. That works! I've updated my answer and added a link to [a demo file](https://github.com/ElectricRCAircraftGuy/eRCaGuy_hello_world/blob/master/markdown/underline.md) I tried on Github directly. – Gabriel Staples Oct 26 '22 at 06:52
  • 1
    Super! thanks much for taking the time to answer this. – NoChance Oct 26 '22 at 21:39
  • 1
    `` did not work in GitHub issue comments, at least in my case. `` did work – Guillermo J. Aug 25 '23 at 07:47
20

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;
}
17

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>

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
Colonel_Old
  • 852
  • 9
  • 15
5

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.

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
Paw in Data
  • 1,262
  • 2
  • 14
  • 32
1

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 #

Hugo Laguna
  • 165
  • 1
  • 4