41

Possible Duplicate:
How can I use a carriage return in a HTML tooltip?

I would like to display the "title" attribute tooltip in several lines, so it looks like this:

Line 1
Line 2

I tried to do:

<div title="Line 1\nLine 2">Secret</div>

but it didn't work.

Is that possible?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
  • what is the sence? it wont be displayed in any browser since they all have single-line caption bar. – heximal Mar 04 '11 at 11:58
  • If you have so much information that it needs to word wrap, then you have too much information for a tooltip. – Quentin Mar 04 '11 at 12:01
  • I have very few information. It just looks better in several lines! – Misha Moroshko Mar 04 '11 at 12:03
  • @Quentin, what's the alternative, make a bunch of extra elements to show documentation on what the controls are for or how to use them? – Synetech Apr 14 '23 at 00:25
  • I found a small issue with multiline tooltips & mouseleave event which I detailed [here](https://stackoverflow.com/q/76498447/6908282) – Gangula Jun 17 '23 at 23:05

3 Answers3

110

You can enter &#10;. In other words:

<div title="Line 1&#10;Line 2">Secret</div>
anothershrubery
  • 20,461
  • 14
  • 53
  • 98
8

As stated in How can I use a carriage return in a HTML tooltip? you can just do it like this:

<div title="Line 1  
Line 2">Secret</div>

Though it is said that it doesn't work with Firefox.

Community
  • 1
  • 1
nollfem
  • 150
  • 1
  • 7
  • 6
    This can cause browser incompatibilities and validation errors. – anothershrubery Mar 04 '11 at 12:14
  • I just tested this in chrome (108.0.5359.125), Firefox (108.0.1), opera (94.0.4606.38), and edge (108.0.1462.54) and it does seem to work nicely. – Jay Jan 05 '23 at 04:40
  • 1
    Note that this considers indentation as well - which would be present in most of the code for readability. So it may not give desired results – Gangula Jun 17 '23 at 08:56
2

Either add new lines within the HTML content itself

<div title="Line 1
Line 2">Secret</div>

Or make your own tooltip using JavaScript and CSS.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
AlanFoster
  • 8,156
  • 5
  • 35
  • 52