Text Orphans

Applying the data-orphans attribute will wrap prevent the last two words from breaking to a new line.

A red border is shown around the <span class="u-nowrap"> elements below to make it easy to visualize what’s happening. With JavaScipt disabled, all lines have a single word orphan.

Defaults to wrapping last 2 words:

  1. First second third fourth fifth sixth.
  2. First second third fourth fifth sixth.
  3. First second third fourth fifth sixth.
  4. First second third fourth fifth sixth.
  5. First second third fourth fifth sixth.
  6. First second third fourth fifth sixth.
  7. First second third fourth fifth sixth.
  8. First second third fourth fifth sixth.

Inline SVGs count as words:

  1. First second third fourth fifth sixth. <%= svg "icons/globe", width: 16 %>
  2. First second third fourth fifth sixth. <%= svg "icons/globe", width: 16 %>
  3. First second third fourth fifth sixth. <%= svg "icons/globe", width: 16 %>
  4. First second third fourth fifth sixth. <%= svg "icons/globe", width: 16 %>
  5. First second third fourth fifth sixth. <%= svg "icons/globe", width: 16 %>
  6. First second third fourth fifth sixth. <%= svg "icons/globe", width: 16 %>

Can define custom word count using data-orphans="3":

  1. First second third fourth fifth sixth.
  2. First second third fourth fifth sixth.
  3. First second third fourth fifth sixth.
  4. First second third fourth fifth sixth.
  5. First second third fourth fifth sixth.
  6. First second third fourth fifth sixth.
  7. First second third fourth fifth sixth.
  8. First second third fourth fifth sixth.
  9. First second third fourth fifth sixth.
  10. First second third fourth fifth sixth.

The script will never break child elements, so these examples will do nothing.

  1. First second third fourth fifth sixth.
  2. First second third fourth fifth sixth. <%= svg "icons/globe", width: 16 %>
  3. First second third fourth fifth sixth. <%= svg "icons/globe", width: 16 %>