The hyphens Property
The CSS hyphens property controls how words are broken into lines when text is too long to fit on a single line. It improves the readability of text that wraps across multiple lines. The property only applies to block-level elements.
Syntax
The syntax for the hyphens property is as follows:
hyphens: none | manual | auto | initial | inherit;
Property Values
Value | Description |
---|---|
none | It disables the hyphenation. |
manual | It is the default value that specifies manual hyphenation behavior for text at &hyphen or ­. |
auto | It allows hyphenation at appropriate hyphenation points, as determined by the browser. |
initial | This sets the property to its default value. |
inherit | This inherits the property from the parent element. |
Prevent Hyphenation with hyphens: none in CSS
To prevent the hyphenation of words, we use the none value. The words will not be broken into lines, even if they are too long to fit on a single line.
Example
In this example, we have used hyphens: none; to prevent automatic hyphenation of words.
<!DOCTYPE html><html><head><style>.container { border: 2px solid #12782f; background-color: coral; width: 70px; padding: 10px; }
</style></head><body><h2>.hyphenated-none { hyphens: none; }
</h2><h4>CSS hyphens property
</h4><div class="container"><p class="hyphenated-none">hyphens: none
This is a muchmuchmuch larger building. </p></div></body></html></pre>
Manual Hyphenation with hyphens: manual in CSS
To allow hyphenation only at points where we have explicitly inserted hyphens using &hyphen or ­, we use the manual value. This is a default value.
Example
In this example, we have used the hyphens: manual, to allow hyphenation only where we have manually inserted using soft hyphens ().
<!DOCTYPE html><html><head><style>.container { border: 2px solid #12782f; background-color: coral; width: 70px; padding: 10px; }
</style></head><body><h2>.hyphenated-none { hyphens: manual; }
</h2><h4>CSS hyphens property
</h4><div class="container"><p class="hyphenated-none">hyphens: manual
This is a muchmuchmuch larger building. </p></div></body></html></pre>
Automatic Hyphenation with hyphens:auto in CSS
To let the browser automatically hyphenate words at points that are considered to be appropriate, according to the language's hyphenation rules, we use the auto value.
Example
Here is an example using hyphens: auto value.
<!DOCTYPE html><html><head><style>.container { border: 2px solid #12782f; background-color: coral; width: 70px; padding: 10px; }
</style></head><body><h2>.hyphenated-none { hyphens: auto; }
</h2><h4>CSS hyphens property
</h4><div class="container"><p class="hyphenated-none">hyphens: auto
This is a muchmuchmuch larger building. </p></div></body></html></pre>
Leave a Reply