.container {
width: 250px;
background-color: red;
}
.hyphenate {
width: 230px;
font-size: 40px;
margin-bottom: 0.6em;
text-align: left;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
this
internationalization
I'm currently working on a web page, I have this tag in which I want to apply hyphenation, I used multiple combinations of attributes in CSS
.hyphenate {
font-size: 40px;
margin-bottom: 0.6em;
text-align: left;
hyphens: auto;
-ms-hyphens: auto;
-webkit-hyphens: auto;
-moz-hyphens: auto;
}
this combination works perfectly in Firefox and Safari in both desktop and mobile versions, but I cannot get it to work in chrome, I have also tried other combination with word-break, word-wrap and overflow-wrap but the problem is still there. I have also read that it is a chrome bug but according to the last information from //caniuse.com/?search=hyphens, it states that there is partial support with the auto value.
Here is the example I'm using: this is the text breaking properly on Safari and firefox
this what I get when I open the page on chrome [both desktop and mobile] the Hyphenation works properly in chrome only when the header contains at least 3 words. and this what I get when I only use two words in chrome, it causes an overflow and does not break, but it breaks correctly in firefox and safari I'm using chrome on a mac with version 87.0.4280.88 which is currently the latest and android chrome version 87.0.4280.101 I would be thankful for any help.
asked Dec 29, 2020 at 12:42
1
This looks like crbug.com/1022415, which was fixed in Chrome 89. It works as expected when I tried in my local test. For your snippet, you need to add the lang="en"
attribute.
.container {
width: 250px;
background-color: red;
}
.hyphenate {
width: 230px;
font-size: 40px;
margin-bottom: 0.6em;
text-align: left;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
this
internationalization
answered Apr 21, 2021 at 19:32
1
Chrome does not support hyphens: auto; [as on 2021-01-12] only FireFox, Edge classic do this.
answered Jan 12, 2021 at 14:27
theking2theking2
1,6281 gold badge22 silver badges28 bronze badges
2
The Note: In the above demo, the string "An extraordinarily long English word!" contains the hidden Hyphenation rules are language-specific. In HTML, the language is determined by the
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, 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
[soft hyphen] character: An extraordinarily long English word!
. This character is used to indicate a potential place to insert a hyphen when hyphens: manual;
is specified.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.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
none: no hyphen; overflow if needed
An extremely long English word
manual: hyphen only at ‐ or ­ [if needed]
An extremely long English word
auto: hyphens where the algorithm decides [if needed]
An extremely long English word
CSS
dd {
width: 55px;
border: 1px solid black;
}
dd.none {
hyphens: none;
}
dd.manual {
hyphens: manual;
}
dd.auto {
hyphens: auto;
}
Result
Specifications
Unknown specification # hyphens-property |
Browser compatibility
BCD tables only load in the browser