Word hyphenation in HTML. Word hyphenation What is the difference between one property and another
The white-space property sets how to display spaces between words. Under normal circumstances, any number of spaces in HTML code appear as one on a web page. The exception is the element , the text placed in this container is displayed with all spaces, as it was formatted by the user. Thus, white-space mimics work
But unlike it, it does not change the font to monospaced.short info
Designations
Description | Example | |
---|---|---|
<тип> | Indicates the type of value. | <размер> |
A && B | The values must be displayed in the order shown. | <размер> && <цвет> |
A | B | Indicates that only one of the suggested values should be selected (A or B). | normal | small-caps |
A || B | Each value can be used alone or in conjunction with others in any order. | width || count |
Groups values. | [crop || cross] | |
* | Repeat zero or more times. | [,<время>]* |
+ | Repeat one or more times. | <число>+ |
? | The specified type, word or group is optional. | inset? |
(A, B) | Repeat at least A, but no more than B times. | <радиус>{1,4} |
# | Repeat one or more times, separated by commas. | <время># |
The values
normal Text is displayed in the browser window as usual, line breaks are set automatically. nowrap Spaces are ignored, line breaks in HTML code are ignored, all text is displayed on one line; however, adding
wraps the text to a new line. pre The text is shown including all spaces and hyphens as they were added by the developer in the HTML code. If the line is too long to fit in the browser window, a horizontal scroll bar will be added. pre-line Spaces are not counted in the text, the text is automatically wrapped to the next line if it does not fit into the specified area. pre-wrap All spaces and breaks are preserved in the text, but if the line width does not fit into the specified area, the text will automatically wrap to the next line.
The effect of the values on the text is presented in table. 1.
Example
Example
Fermat's Last Theorem
X n+ Y n= Z n
where n is an integer> 2
The result of this example is shown in Fig. 1.
Rice. 1. Applying the white-space property
Object Model
An object.style.whiteSpace
Note
Internet Explorer up to and including 7.0 does not support pre-line and pre-wrap values. For
Opera prior to version 9.5 does not support the pre-line value. For
In Firefox for
Specification
Each specification goes through several stages of approval.
- Recommendation - This specification is endorsed by the W3C and recommended as a standard.
- Candidate Recommendation ( Possible recommendation) - the group responsible for the standard is satisfied that it meets its objectives, but the help of the developer community is required to implement the standard.
- Proposed Recommendation ( Suggested recommendation) - At this point, the document is submitted to the W3C Advisory Council for final approval.
- Working Draft - A more mature version of the draft after discussion and revision for community review.
- Editor "s draft ( Editorial draft) - a draft version of the standard after editing by the project editors.
- Draft ( Draft specification) is the first draft of the standard.
Automatic clumsy hyphenation (without adding hyphens).
Property values of interest:
- break-all
Automatic transfer of all words, the text looks like it is justified. - break-word (used on this site in headers)
Wrap individual words that do not fit within the specified block width.
Bright future. СSS property hyphens
The hyphenation rules are determined by a dictionary built into the browser. The property works when there is a lang attribute with a language code at the level of the entire document or its individual parts.
Values of interest:
- manual (default)
Words are wrapped only in those places of the text where the special character & shy (soft wrap) or tag is added... Special characters are manually placed in the text, they are not visible in normal text, and if the word does not fit, the browser creates a hyphenation at the location of the special character. The special character & shy when hyphenating a word (as taught at school), but no tag. - auto
The browser adds hyphenations automatically based on the built-in dictionary. Until now, poor browser support, does not work in chrome (.
Program
Prevent hyphenation
There is an inverse problem - to prohibit hyphenation. For example, do not separate the initials from the surname or the unit of measurement from the values (100 kg). To prevent the browser from adding hyphens, instead of the usual space, write a non-breaking space & nbsp
Also, the hyphens CSS property has a value of none, when words are not hyphenated, even if there are soft hyphens in the text.
short info
CSS versions
CSS 1 | CSS 2 | CSS 2.1 | CSS 3 |
---|---|---|---|
Description
The white-space property sets how to display spaces between words. Under normal circumstances, any number of spaces in HTML code appear as one on a web page. An exception is the tag
Text placed in this container is displayed with all spaces as it was formatted by the user. Thus, white-space mimics how the tag works.But unlike it, it does not change the font to monospaced.Syntax
white-space: normal | nowrap | pre | pre-line | pre-wrap | inherit
The values
normal Text is displayed in the browser window as usual, line breaks are set automatically. nowrap Spaces are ignored, line breaks in HTML code are ignored, all text is displayed on one line; however, adding a tag
wraps the text to a new line. pre The text is shown including all spaces and hyphens as they were added by the developer in the HTML code. If the line is too long to fit in the browser window, a horizontal scroll bar will be added. pre-line Spaces are not counted in the text, the text is automatically wrapped to the next line if it does not fit into the specified area. pre-wrap All spaces and breaks are preserved in the text, but if the line width does not fit into the specified area, the text will automatically wrap to the next line. inherit Inherits the value from the parent.The effect of the values on the text is presented in table. 1.
HTML5 CSS2.1 IE Cr Op Sa Fx
white-space Example
Fermat's Last Theorem
X n+ Y n= Z n
where n is an integer> 2The result of this example is shown in Fig. 1.
Rice. 1. Applying the white-space property
Object Model
document.getElementById ("elementID") .style.whiteSpace
Browsers
Internet Explorer up to and including 7.0 does not support pre-line, pre-wrap, and inherit. For
Opera prior to version 9.5 does not support the pre-line value. For
Safari prior to 3.0 and iOS do not support pre-wrap and pre-line values.
Firefox up to and including version 2.0 does not support pre-line and pre-wrap values. For
Vlad Merzhevich
Unlike text in printing, hyphenation is rarely used on a web page, since we are not rigidly tied to the paper size. Websites can be viewed on different monitors, with different resolutions, in different operating systems and browsers. All this gives rise to such a combination of combinations that it is impossible to predict how the final text will look for the user. Because of this, text is usually left-aligned, and hyphenation occurs with entire words. But still, hyphenation is necessary in some cases, for example, when long chemical or medical terms are used, in narrow columns of a given width, for the sake of aesthetics. In HTML and CSS, there are not so many manual or automatic ways to add hyphenations, so I'll list them all.
Using the tag
Tag
introduced in HTML5 and creates word wrap if needed. In those places where, according to the rules of the Russian language, a transfer is allowed, we insert (example 1). If the entire word fits into the allotted width, this tag will not manifest itself in any way and we will not even know about its presence. If the word does not fit, the browser is at the location of the tag creates a carry. Example 1. Tag
Transfers One
supradiclass snitch Angelica after graduating from school chose the profession of business production driver faces. The result of this example is shown in Fig. 1.
Rice. 1. Text with word wrapping
Soft transfer
Application
has a serious drawback - it is impossible to understand whether a hyphen is in front of us or a separate word on another line. Because of this, the meaning of the sentence can be lost and misunderstood. The hyphenation should be done according to the rules of typography, namely: add a hyphen at the end of the line. Soft hyphenation does an excellent job of this, there is a special symbol for it in the HTML code -. It serves the same role as the tag - is not visible in normal text and wraps the word to another line, while adding a hyphen (example 2). Example 2. Soft carry
Transfers One-eleventh-class-snitsa Angelica, after graduating from school, chose the profession of business-producer-driver.
The result of this example is shown in Fig. 2. Notice how much more aesthetically pleasing and understandable the text has become in comparison with fig. 1.
Rice. 2. Text with word wrapping
The word-break property
To automate the process of creating hyphens, use the word-break property with the break-all value (example 3). There is no need to add any symbols or tags to HTML, everything is taken over by the styles.
Example 3. Using word-break
Transfers Eleventh grader Angelica after graduating from school chose the profession of a clerk.
The result of this example is shown in Fig. 3. The rules of hyphenation are not taken into account in this case, so words can be hyphenated in a very bizarre way.
Rice. 3. Text with word wrapping
Of all the listed methods "semi-manual" using - gives the best result - the rules of the Russian language are observed, the text looks the most aesthetically pleasing. Use it when there are long words in the text.
The hyphens property
And finally, the most powerful and convenient property for automatically adding hyphens is hyphens. Its action is based on the browser's built-in hyphenation dictionary, therefore it gives the best result. Supported in IE10, Firefox, Android and iOS. Chrome and Opera don't support. To make it all work, for the tag add the lang attribute with the value ru (example 4).
Example 4. Using hyphens
Transfers Eleventh grader Angelica after graduating from school chose the profession of a clerk.
The result of this example is shown in Fig. 4.
Rice. 4. Text with word wrapping
Prevent hyphenation
The inverse problem often arises - to prohibit hyphenation in those places where, according to the rules of the language, they are unacceptable. For example, you cannot separate the units of measurement from the number (10 ml), the designation of the year (54 BC), the initials from the surname, break persistent abbreviations (etc.), etc. So that the browser does not add hyphens in the space, its should be replaced with a non-breaking space (example 5).
Example 5. Usage
Transfers Lake at coordinates 70 ° 58 ′ 19 ″ s. NS. 97 ° 24 ′ 5 ″ E The village is located in the Taimyr Dolgano-Nenets District of the Krasnoyarsk Territory of Russia.
In this example, for the correct spelling of coordinates, it is used that does not allow the text to be wrapped.