89

A   character is a space which doesn't allow for line breaking.

<p>lorem ipsum here&nbsp;are&nbsp;some&nbsp;words and so on</p>

| lorem ipsum                |
| here are some words and so |
| on                         |

What's the opposite of that? That is, a character which is NOT rendered as a space, but CAN be used for line breaking.

<p>foo supercalifragilisticexpialidocious bar</p>
<!--   put char here ^   and here ^ -->

|foo supercalifragi |
|listicexpiali      |
|docious bar        |

or with wider size:

|foo supercalifragilisticexpiali   |
|docious bar                       |

I'm aware of the soft-hyphen character, but for my purposes, I specifically do not want a hyphen added at the break.

nickf
  • 537,072
  • 198
  • 649
  • 721

6 Answers6

96

You want the unicode character ZERO-WIDTH SPACE (\u200B).

You can get it in HTML with &#8203; or &#x200b;.

Explicit breaks and non-breaks:

LB7 : Do not break before spaces or zero width space.
LB8 : Break before any character following a zero-width space, even if one or more spaces intervene.
http://unicode.org/reports/tr14/

Community
  • 1
  • 1
Anon.
  • 58,739
  • 8
  • 81
  • 86
  • I tested this, it does not produce a line break in Firefox 3.5.7. – Noon Silk Jan 12 '10 at 03:35
  • 19
    It's not meant to produce an explicit linebreak. It's meant to indicate a point where the line *can* be wrapped if it's too long to fit in wherever it's supposed to go. – Anon. Jan 12 '10 at 03:37
  • 2
    So.... this character can be evil because if you copy content around that contains it (in unicode-aware editors that will happily play along) you will be unaware of its presence, and it will cause e.g. compilers to choke on it. hard. For example Chrome will tell you "ILLEGAL CHARACTER" but not point out to you where it is. I'd use this admittedly neat trick as a very last resort – Steven Lu Aug 21 '13 at 17:04
  • It should be called a "Non Space Break" – jackreichert Aug 05 '14 at 13:04
  • 1
    It's visible alternative is a Hyphen. – davidcondrey Mar 10 '15 at 08:27
38

There also is the little-known wbr tag, which lets the browser to decide whether to break the line or not.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
Matt Hampel
  • 5,088
  • 12
  • 52
  • 78
17

There's a nice page over at quirksmode.org that answers this question quite nicely IMHO. http://www.quirksmode.org/oddsandends/wbr.html

In short: use <wbr /> or &#8203; (or &shy; but you mentioned you don't want the dash).

fredden
  • 465
  • 5
  • 8
  • Not all of these possibilities are supported by all browsers. I guess ​ is the best solution as most browsers should be able to recognize Unicode. – AndiDog Jan 12 '10 at 09:51
  • and IE6 users get an ugly glyph apparently... my heart weeps. – nickf Jan 12 '10 at 11:51
4

use <wbr>.

jrharshath
  • 25,975
  • 33
  • 97
  • 127
3

You can use CSS3 property called word-wrap

p.test {word-wrap:break-word;}

Hope it helps!

guettli
  • 25,042
  • 81
  • 346
  • 663
Swanidhi
  • 2,029
  • 1
  • 20
  • 21
-5

theres a lot of discussion about this but it has become more or less standard to use &shy;

The Surrican
  • 29,118
  • 24
  • 122
  • 168