Css don t break hyphenated words

I'm looking to prevent a line break after a hyphen - on a case-by-case basis that is compatible with all browsers.

Example:

I have this text: 3-3/8" which in HTML is this: 3-3/8”

The problem is that near the end of a line, because of the hyphen, it breaks and wraps to the next line instead of treating it like a full word...

3-
3/8"

I've tried inserting the "zero width no break character",  with no luck...

3-3/8”

I'm seeing this in Safari and thinking it will be the same in all browsers.

The following is my doctype and character encoding...




    

Is there any way I can prevent these from line-breaking after the hyphen? I do not need any solution that applies to the whole page... just something I can insert as needed, like a "zero width no break character", except one that works.

Here is a Demo. Simply make the frame narrower until the line breaks at the hyphen.

http://jsfiddle.net/RagKH/

The hyphens CSS property specifies how words should be hyphenated when text wraps across multiple lines. It can prevent hyphenation entirely, hyphenate at manually-specified points within the text, or let the browser automatically insert hyphens where appropriate.

Try it

Note: In the above demo, the string "An extraordinarily long English word!" contains the hidden ­ (soft hyphen) character: An extra­ordinarily long English word!. This character is used to indicate a potential place to insert a hyphen when hyphens: manual; is specified.

Hyphenation rules are language-specific. In HTML, the language is determined by the lang attribute, and browsers will hyphenate only if this attribute is present and the appropriate hyphenation dictionary is available. In XML, the xml:lang attribute must be used.

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.

If supported, hyphenate-character may be used to specify an alternative hyphenation character to use at the end of the line being broken.

Syntax

/* Keyword values */
hyphens: none;
hyphens: manual;
hyphens: auto;

/* Global values */
hyphens: inherit;
hyphens: initial;
hyphens: revert;
hyphens: revert-layer;
hyphens: unset;

The hyphens property is specified as a single keyword value chosen from the list below.

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 Suggesting line break opportunities below for details.

auto

The browser is free to automatically break words at appropriate hyphenation points, following whatever rules it chooses. However, suggested line break opportunities (see Suggesting line break opportunities below) will override automatic break point selection when present.

Note: The auto setting's behavior depends on the language being properly tagged to select the appropriate hyphenation rules. You must specify a language using the lang HTML attribute to guarantee that automatic hyphenation is applied in that language.

Suggesting line break opportunities

There are two Unicode characters 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 marks a place where the browser should break the word if hyphenation is necessary. In HTML, use ­ to insert a soft hyphen.

Note: When the HTML element leads to a line break, no hyphen is added.

Formal definition

Formal syntax

hyphens = 
none |
manual |
auto

Examples

Specifying text hyphenation

This example uses three classes, one for each possible configuration of the hyphens property.

HTML

<dl>
  <dt><code>nonecode>: no hyphen; overflow if neededdt>
  <dd lang="en" class="none">An extreme­ly long English worddd>
  <dt>
    <code>manualcode>: hyphen only at &hyphen; or &shy; (if needed)
  dt>
  <dd lang="en" class="manual">An extreme­ly long English worddd>
  <dt><code>autocode>: hyphens where the algorithm decides (if needed)dt>
  <dd lang="en" class="auto">An extreme­ly long English worddd>
dl>

CSS

dd {
  width: 55px;
  border: 1px solid black;
}
dd.none {
  hyphens: none;
}
dd.manual {
  hyphens: manual;
}
dd.auto {
  hyphens: auto;
}

Result

Specifications

Specification
Unknown specification
# hyphens-property

Browser compatibility

BCD tables only load in the browser

See also

How do I stop words breaking in CSS?

If you want to prevent the text from wrapping, you can apply white-space: nowrap; Notice in HTML code example at the top of this article, there are actually two line breaks, one before the line of text and one after, which allow the text to be on its own line (in the code).

Is there a non

The answer to this dilemma is to use non-breaking hyphens instead of regular dashes when you don't want Word to break a line at the hyphen. To do this, hold down the Ctrl and Shift keys as you type the dash (this is the same as typing Ctrl and an underscore). Word will then not break the line at that point.

Does hyphen do not break HTML?

Non-Breaking Hyphen.
UNICODE. U+02011..
HEX CODE. ‑.
HTML CODE. ‑.
HTML ENTITY. —.
CSS CODE. \2011. // html example. // css example. span { content: "\2011"; }.

How do I stop word breaking?

To stop words from splitting across lines in a paragraph or paragraphs by turning off automatic hyphenation:.
Select the paragraph or paragraphs..
Click the Home tab in the Ribbon..
Click the dialog box launcher on the bottom right corner of the Paragraph group. ... .
Click Line and Page Breaks..
Select or check Don't Hyphenate..