I am using this
<a href="#" title="select from 1: this 2: that" > Click here </a>
When someone hover over it I see all the text in one line.
Is there any way to show it on new line?
Just use the entity code 
 for a linebreak in a title attribute.
To do a line break in HTML, use the <br> tag. Simply place the tag wherever you want to force a line break. Since an HTML line break is an empty element, there's no closing tag. Below is an HTML file with a <p> and <br> element.
Just use the entity code 
 for a linebreak in a title attribute.
You can't style an actual title attribute How the text in the title attribute is displayed is defined by the browser and varies from browser to browser. It's not possible for a webpage to apply any style to the tooltip that the browser displays based on the title attribute.
You can use 
or 

.
<a href="#" title="select from 1: this 
 2: that" >Click here</a>
<a href="#" title="select from 1: this 
 2: that" >Click here</a>
If you are generating it dynamically put < br/> in html part and \n in non html part
$("td").attr("title", "One \n Two \n Three");
$("td").html("One <br/> Two \n <br/>Three <br/>");
$("td").append("One \n Two \n Three");
$("td").append("<br/>One <br/> Two \n Three");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tbody>
<tr>
<td></td>
</tr>
<tbody>
</table>
This is using Jquery framework.
As you tagged this with accessibility, I would say the most robust approach is not to rely on the title for information.
The current HTML spec discourages this use as people using who cannot use a mouse (e.g. due to mobility impairment) but use a keyboard and see the screen will never see your tooltip/title text. People using touch screens cannot access it.
Most people using a screen reader will not be aware of the title text either, although it is possible to access in most screen readers it is not read out by default, and someone would have to know to look for it. (And there are more issues.)
The spec suggests using this for line breaks:
If the title attribute's value contains "LF" (U+000A) characters, the content is split into multiple lines. Each "LF" (U+000A) character represents a line break.
However, the display of the new lines is dependant on the browser (How can I use a carriage return in a HTML tooltip).
I suspect that the overall UI approach needs a little more thought, as many people would be confused by the sort of instruction in your example, i.e. what does clicking on it achieve if there are multiple options?
If your situation makes it difficult to write good link text then I would post up more about the interaction at the UX stackexchange.
<a href="#" title="select from
1: this
2: that" >Click here</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With