507

How can I underline text in Markdown?

2
  • 12
    I wish _ somehow would stand for _underlined_ text, unfortunately it does not Commented Apr 9, 2024 at 11:30
  • Sometimes, you can get away with using an in-built LaTeX renderer using the mathmode \text{...} and \underline{...} LaTeX commands. This only works for markdown that renders LaTeX and is inelegant imo. On the plus side, you can use the \boxed{...} command which I think looks pretty unique. Edit: I just noticed this is a 15 year old question lmaoo Commented Jul 22 at 6:22

9 Answers 9

540

Markdown syntax doesn't support underline text on its own. You should be able to use HTML tags with some caution (see linked documentation).

All this said ...

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

Sign up to request clarification or add additional context in comments.

10 Comments

And in BitBucket too... (as well as <u>text</u>)
<u>text</u> doesn't work, but I never heard about <ins> tag lol, - it's seems because it's so unpopular, it still works (normally it's not very good to underline text)
In case anyone wanted to know <ins>text</ins> works fine in Jupyter notebooks too
I prefer <u>. Here's a little more info: stackoverflow.com/a/66595330/4561887.
From Mardown specs: 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...
|
265

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.

5 Comments

"it's usually used for hyperlinks" says someone who probably enters links in markdown input boxes daily.
@zylstra Were you trolling when you wrote your comment or did you actually think that you made a good point?
@HelloGoodbye, looking back now I'm not sure what I meant. :/
I don't think it's particularly hard to read... Bold text is more difficult to notice in dark mode than underline in my opinion
Do any studies support the idea that underlined text is hard to read? I'm genuinely curious
145
+200

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.

6 Comments

The semantic analogue of <u> is <ins>; that's never been deprecated.
@TobyBartels I'm not sure what you mean. "The <u> element represents a span of text with an unarticulated, though explicitly rendered, non-textual annotation," whereas "the <ins> element represents an addition to the document." These are two semantically very different things.
I mean that <u> is not particularly a semantic tag at all, while <ins> is. Yet they are traditionally rendered in the same way. So <ins> is the semantic analogue of <u>, while <u> is the syntactic analogue of <ins>. Well, even if you don't like how I describe it, the point is that we have this analogy: <u> : <ins> :: <i> : <em> :: <b> : <strong>. (Also <s> : <del>.)
@TobyBartels Ah, I misinterpreted you. I thought you were saying that <u> and <ins> were semantically equivalent. The HTML5 spec has actually given semantic meanings to <u>, <i>, <b>, and <s> that are different from their stylistically similar counterparts, but I see your point.
I would have thought it not good practice to use an <ins> tag since it represents inserted text (with <del> 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 <ins> 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.
|
102

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

13 Comments

Wow, one really can have <b> and <i> but not <u>? Why that? :(
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.
It's probably because <u> shouldn't be used for simple underlining in HTML5 any longer ...
@s.krueger Please read html.spec.whatwg.org/multipage/semantics.html#the-u-element. <u> can be used for underlining, but is discouraged "where it could be confused for a hyperlink."
@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, <u> is your best option for explicitly rendered underlining. Of course, more semantic elements should be used when possible.
|
72

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

7 Comments

@NoChance, use ### <ins>Underlined Heading 3</ins>. That works! I've updated my answer and added a link to a demo file I tried on Github directly.
Super! thanks much for taking the time to answer this.
<u> did not work in GitHub issue comments, at least in my case. <ins> did work
<u> also does not appear to work in PR descriptions at the time of writing this comment. <ins> does work.
@GabrielStaples apologies, referring to Github
|
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;
}

3 Comments

-1 This seems like a hack to me, I'd prefer to understand the motivation behind it, underlines exclusion won't be an accident.
nice hack. for situations you can't use html tags this is great.
Looks like an overkill.
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>

Comments

6

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.

Comments

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 #

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.