How do you underline html text so that the line beneath the text is dotted rather than the standard underline? Preferably, I would like to do this without using a separate CSS file. I'm a novice at html.
-
13Why why can you not use CSS? Maybe create the page as one image and add the line with mspaint? – epascarello Mar 06 '13 at 16:20
-
I don't think it can be done without CSS – Cfreak Mar 06 '13 at 16:21
-
You have to use css, but it could be done using background images, border bottom is the best approach – kingdomcreation Mar 06 '13 at 16:22
-
7Dudes. I think he said "without using a separate CSS file", not "without CSS". Worship the newbies. – Stefan Reich May 29 '17 at 13:38
11 Answers
It's impossible without CSS. In fact, the <u>
tag is simply adding text-decoration:underline
to the text with the browser's built-in CSS.
Here's what you can do:
<html>
<head>
<!-- Other head stuff here, like title or meta -->
<style type="text/css">
u {
border-bottom: 1px dotted #000;
text-decoration: none;
}
</style>
</head>
<!-- Body, content here -->
</html>

- 4,406
- 2
- 23
- 34
-
-
2
-
Nice solution and it is possible. Don't make me code js for it ;) – Ahmet Can Güven Jul 13 '16 at 16:56
-
1Here's the answer with multi line text support http://stackoverflow.com/a/4365458/1078641 – electroid Aug 21 '16 at 13:12
-
Use the following CSS codes...
text-decoration:underline;
text-decoration-style: dotted;

- 1,526
- 17
- 22
-
8This should be the accepted answer. Following the box model, using a dotted `border` will be placed outside of `padding` and will thus be distant from the text. – Ryan Walker Mar 25 '20 at 22:38
-
18There is a short syntax: `text-decoration: underline #000 dotted;` where the first attribute is line, second is color and the third is style. – Sos Sargsyan May 22 '20 at 14:59
-
Without CSS, you basically are stuck with using an image tag. Basically make an image of the text and add the underline. That basically means your page is useless to a screen reader.
With CSS, it is simple.
HTML:
<u class="dotted">I like cheese</u>
CSS:
u.dotted{
border-bottom: 1px dashed #999;
text-decoration: none;
}
Example page
<!DOCTYPE HTML>
<html>
<head>
<style>
u.dotted{
border-bottom: 1px dashed #999;
text-decoration: none;
}
</style>
</head>
<body>
<u class="dotted">I like cheese</u>
</body>
</html>

- 53,861
- 28
- 137
- 147

- 204,599
- 20
- 195
- 236
HTML5 element can give dotted underline so the beneath text will have dotted line rather than regular underline. And the title attribute creates a tool tip for the user when they hover their cursor over the element:
NOTE: The dotted border/underline is shown by default in Firefox and Opera, but IE8, Safari, and Chrome need a line of CSS:
<abbr title="Hyper Text Markup Language">HTML</abbr>

- 151
- 1
- 2
-
-
-
2This should only be used for abbreviations. Otherwise screen readers might do the wrong thing. – equaeghe Nov 12 '21 at 17:44
Maybe I’m a bit late, but just use text-decoration: underline dotted
,
it’s a single CSS property that you can use everywhere.
Inline HTML
<u style="text-decoration:underline dotted">I have a dotted underline</u>
For a dashed underline, use text-decoration: underline dashed
.
<u style="text-decoration:underline dashed">I have a dashed underline</u>
As said by Darshana Gunawardana, you can use text-underline-position: under
, to have more space between the text and the line:
<u style="text-decoration:underline dotted;text-underline-position:under">I have a dotted underline</u>
In a separate CSS file
u {
text-decoration: underline dotted;
}

- 326
- 3
- 11
If the content has more than 1 line, adding a bottom border won't help. In that case you'll have to use,
text-decoration: underline;
text-decoration-style: dotted;
If you want more breathing space in between the text and the line, simply use,
text-underline-position: under;

- 86
- 1
- 3
You can make use of text-decoration
properties:
text-decoration: underline;
text-decoration-style: dotted;
text-decoration-line: underline;
text-decoration-thickness: 1px;

- 676
- 7
- 12
Reformatted the answer by @epascarello:
u.dotted {
border-bottom: 1px dashed #999;
text-decoration: none;
}
<!DOCTYPE html>
<u class="dotted">I like cheese</u>

- 19,847
- 9
- 124
- 140
You can use border bottom with dotted
option.
border-bottom: 1px dotted #807f80;

- 9,352
- 23
- 87
- 128
You can try this method:
<h2 style="text-decoration: underline; text-underline-position: under; text-decoration-style: dotted">Hello World!</h2>
Please note that without text-underline-position: under;
you still will have a dotted underline but this property will give it more breathing space.
This is assuming you want to embed everything inside an HTML file using inline styling and not to use a separate CSS file or tag.

- 34,860
- 64
- 239
- 408
It's not impossible without CSS. For example as a list item:
<li style="border-bottom: 1px dashed"><!--content --></li>

- 1,370
- 1
- 12
- 25

- 107
- 12
-
6It is impossible without CSS. The `style` attribute is simply a way of applying CSS properties directly to an element. See the [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) on the style attribute. – mirichan Sep 01 '15 at 07:31
-
Adding CSS in this way is a way of effectively thinking about html styling. Of course you can argue there's no such thing but for an easy to describe method this is a possible solution. – Davington III Sep 18 '15 at 14:58
-
It's still CSS though, and the real preference given was to not have a separate file. The best way to go about solving the problem with that restriction is ` – mirichan Sep 18 '15 at 15:46
-
Well at the time I created that post it was because I had to use inline styles. It seemed worthwhile noting that possibility to others imo just incase they might not have thought of it, It's not really an appropriate topic for war & peace... They presumably found what they needed and our suggestions are there for those and any others that might need them, when I post from work I don't take into account someone pointing out something already obvious about the suggestion when it is a suggestion not a "you must do it this way" so yeah take a chill pill bro :) – Davington III Sep 21 '15 at 13:18
-
1You mistake my intentions. I was making a technical observation relevant to the question asked. I had no intention of calling you out, and I apologise for it coming across that way. – mirichan Sep 21 '15 at 13:41