hyphens

  • Revision slug: CSS/hyphens
  • Revision title: hyphens
  • Revision id: 26624
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment add example; 101 words added, 1 words removed

Revision Content

{{ CSSRef() }}

{{ SeeCompatTable() }}

Summary

The hyphens property tells the browser how to go about splitting words to improve the layout of text when line-wrapping.

Note: The rules defining how hyphenation is performed are not explicitly defined by the specification, so the exact hyphenation may vary from browser to browser.
  • {{ Xref_cssinitial() }}: manual
  • Applies to: all elements
  • {{ Xref_cssinherited() }}: yes
  • Percentages: n/a
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}: as specified

Syntax

hyphens:  none | manual | auto

Values

none
Words are not broken at line breaks, even if characters inside the words suggest line break points. Lines will only wrap at whitespace.
manual
Words are broken for line-wrapping only where characters inside the word suggest line break opportunities. See {{ anch("Suggesting line break opportunities") }} for details.
auto
The browser is free to automatically break words at appropriate hyphenation points, following whatever rules it chooses to use. Suggested line break opportunities, as covered in {{ anch("Suggesting line break opportunities") }}, should be preferred over automatically selecting break points whenever possible.
Note: The auto setting's behavior depends on the language being properly tagged so that the appropriate hyphenation rules can be selected. You must specify a language using the lang HTML attribute in order to have automatic hyphenation applied.

Suggesting line break opportunities

There are two Unicode character that can be used to manually specify potential line break points within text:

U+2010 (HYPHEN)
The "hard" hyphen character indicates a visible line break opportunity. Even if the line is not actually broken at that point, the hyphen is still rendered.
U+00AD (SHY)
An invisible, "soft" hyphen. This character is not rendered visibly; instead, it suggests a place where the browser might choose to break the word if necessary. In HTML, you can use ­ to insert a soft hyphen.

Example

This CSS snippet creates three classes, one for each possible configuration of the hyphens property.

p.none {
  hyphens: none;
  -moz-hyphens: none;
}
p.manual {
  hyphens: manual;
  -moz-hyphens: manual;
}
p.auto {
  hyphens: auto;
  -moz-hyphens: auto;
}

Take a look at the live example to see these configurations in action; resize the window while looking at them to see them in action.

{{ CSSLiveSample("hyphens.html") }}

Specifications

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatUnknown() }}

{{ CompatGeckoDesktop("6.0") }}

-moz-hyphens currently supports only English for automatic hyphenation.

{{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }}

{{ CompatGeckoMobile("6.0") }}

-moz-hyphens currently supports only English for automatic hyphenation.

{{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

See also

{{ Cssxref("content") }}

Revision Source

<p>{{ CSSRef() }}</p>
<p>{{ SeeCompatTable() }}</p>
<h3 name="Summary">Summary</h3>
<p>The <code>hyphens</code> property tells the browser how to go about splitting words to improve the layout of text when line-wrapping.</p>
<div class="note"><strong>Note:</strong> The rules defining how hyphenation is performed are not explicitly defined by the specification, so the exact hyphenation may vary from browser to browser.</div>
<ul> <li>{{ Xref_cssinitial() }}: <code>manual</code></li> <li>Applies to: all elements</li> <li>{{ Xref_cssinherited() }}: yes</li> <li>Percentages: n/a</li> <li>Media: {{ Xref_cssvisual() }}</li> <li>{{ Xref_csscomputed() }}: as specified</li>
</ul>
<h3 name="Syntax">Syntax</h3>
<pre class="eval">hyphens:  none | manual | auto
</pre>
<h3 name="Values">Values</h3>
<dl> <dt><code>none</code></dt> <dd>Words are not broken at line breaks, even if characters inside the words suggest line break points. Lines will only wrap at whitespace.</dd> <dt><code>manual</code></dt> <dd>Words are broken for line-wrapping only where characters inside the word suggest line break opportunities. See {{ anch("Suggesting line break opportunities") }} for details.</dd> <dt><code>auto</code></dt> <dd>The browser is free to automatically break words at appropriate hyphenation points, following whatever rules it chooses to use. Suggested line break opportunities, as covered in {{ anch("Suggesting line break opportunities") }}, should be preferred over automatically selecting break points whenever possible.</dd>
</dl>
<div class="note"><strong>Note:</strong> The <code>auto</code> setting's behavior depends on the language being properly tagged so that the appropriate hyphenation rules can be selected. You must specify a language using the <code>lang</code> HTML attribute in order to have automatic hyphenation applied.</div>
<dl> <h3>Suggesting line break opportunities</h3> <p>There are two Unicode character that can be used to manually specify potential line break points within text:</p> <dl> <dt>U+2010 (HYPHEN)</dt> <dd>The "hard" hyphen character indicates a visible line break opportunity. Even if the line is not actually broken at that point, the hyphen is still rendered.</dd> <dt>U+00AD (SHY)</dt> <dd>An invisible, "soft" hyphen. This character is not rendered visibly; instead, it suggests a place where the browser might choose to break the word if necessary. In HTML, you can use <code>&amp;shy;</code> to insert a soft hyphen.</dd> </dl> <h3 name="Examples">Example</h3>
<p>This CSS snippet creates three classes, one for each possible configuration of the <code>hyphens</code> property.</p>
<pre class="brush: dekiscript">p.none {
  hyphens: none;
  -moz-hyphens: none;
}
p.manual {
  hyphens: manual;
  -moz-hyphens: manual;
}
p.auto {
  hyphens: auto;
  -moz-hyphens: auto;
}
</pre>
<p>Take a look at the live example to see these configurations in action; resize the window while looking at them to see them in action.</p>
<p>{{ CSSLiveSample("hyphens.html") }}</p><h3>Specifications</h3> <ul> <li><a class=" external" href="http://www.w3.org/TR/2011/WD-css3-text-20110412/#hyphens" title="http://www.w3.org/TR/2011/WD-css3-text-20110412/#hyphens">CSS 3 Text: hyphens</a></li> <li><a class=" external" href="http://www.w3.org/TR/css3-gcpm/#hyphenation" title="http://www.w3.org/TR/css3-gcpm/#hyphenation">CSS 3 Generated content: hyphens</a></li> </ul> <h3 name="Browser_compatibility">Browser compatibility</h3> <p>{{ CompatibilityTable() }}</p> <div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatUnknown() }}</td> <td> <p>{{ CompatGeckoDesktop("6.0") }}</p> <p><code>-moz-hyphens</code> currently supports only English for automatic hyphenation.</p> </td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> </tbody> </table> </div> <div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Mobile</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatUnknown() }}</td> <td> <p>{{ CompatGeckoMobile("6.0") }}</p> <p><code>-moz-hyphens</code> currently supports only English for automatic hyphenation.</p> </td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> <td>{{ CompatUnknown() }}</td> </tr> </tbody> </table> </div> <h3 name="See_also">See also</h3> <p>{{ Cssxref("content") }}</p></dl>
Revert to this revision