Typically, the site creator decides which letters will be uppercase and which lowercase, based on spelling rules and their own preferences. However, the process of changing the case of characters can be automated using the property text-transform. This property can take four values:
- none - the text is written without changes;
- capitalize- each word will start with a capital character;
- lowercase - all characters become lowercase (lower case);
- upper case- all characters become capital (upper case).
For example, the following rule specifies that the H1 heading should be in capital letters:
H1 (text-transform: uppercase;)
It is convenient to set automatic character case change for abbreviations, element names, headings, and others. text elements, where you want to write in uppercase or lowercase characters.
Text decoration: text-decoration property
Property text-decoration allows you to set the text additional design. The values of this property are constants none, underline, overline, line-through and blink, which let you display normal text, draw a line above, below, or through text, or make text blink. An example of using different values of this property is shown in Figure 11.4.
Rice. 11.4.
The most common application of the property text-decoration is to change the default link underlining. For example, the following rule specifies that links should be underlined:
A:link (text-decoration: underline;)
Word spacing: word-spacing property
To set the spacing between words in text, use the word-spacing property. The value of this property can be set using keyword normal , which is the default and sets the standard spacing for the current font. To set the interval, in addition to the standard one, you can specify a value in any available CSS units, and the value can be negative.
So, the following rule increases the spacing between words in the H1 heading by 1em :
H1 (word-spacing: 1em;)
Text alignment: the text-align property
Alignment refers to placing the left or right edge of a block of text along an invisible vertical line. Used to align text. text property-align . Valid values of this property are left, right, center, and justify , which specify left, right, center, and justify alignment, respectively.
The following rule sets the center alignment of all elements contained within a DIV element:
DIV (text-align: center;)
Leading: the line-height property
Leading is the distance between baselines of closely spaced lines. Under normal circumstances, line spacing depends on the type and size of the font and is automatically determined by the browser. But this value can be changed using the line-height property. The default value of normal causes the browser to calculate line spacing automatically. Any number greater than zero is taken as a multiplier of the font size of the current text. It is also possible to use any length units accepted in CSS as values for this property. It is also allowed to use a percentage notation, in which case the font height is taken as 100%. Negative line spacing is not allowed.
Letter spacing: the letter-spacing property
The browser automatically selects character spacing based on font size and type. In some cases, it is necessary to correct the spacing between letters. The letter-spacing property is used to control letter spacing. Any CSS length units can be used as values for this property, but it is recommended to use relative units based on font size (em and ex). Unlike line spacing, the letter-spacing property allows a negative value, but in this case you need to make sure that the readability of the text is preserved.
The following rule increases the spacing between characters in the H1 header by 0.5em .
Module CSS text describes the CSS functions that control source-to-formatted translation and line-breaking. Various properties CSS provides control over case conversion, whitespace handling, hyphenation rules and text and line wrapping, alignment, spacing, and indentation.
The basic unit of text is a character. However, since writing systems are not always as simple as the basic English alphabet, what a character actually is depends on the context in which the term is used. For example, in the Korean writing system, each square representation of a syllable (e.g. 한 = han) can be considered a character. However, the square symbol does indeed consist of several letters, each representing a phoneme (e.g. ㅎ = h, ㅏ = a, ㄴ = n), and each of these can also be considered a symbol.
1. Text transformation: text-transform property
The text-transform property styles the text. It does not affect the underlying content and should not affect the content of a plain text copy and paste operation.
The property is inherited.
Syntax
text-transform: none; text-transform: capitalize; text-transform: uppercase; text-transform: lowercase; text-transform: inherit; text-transform: initial;
2. Handling spaces and line breaks: the white-space property
The white-space property handles spaces between words and line breaks within an element.
The property is inherited.
white space | |
---|---|
Values: | |
normal | Default value. Only one space is inserted between words, additional spaces are discarded. Text wraps only when necessary. |
nowrap | Disables line breaks except when applied . |
pre | Spaces in text are not ignored, the browser displays extra spaces and line breaks. |
pre-wrap | Preserves whitespace in text by making line breaks where necessary. |
pre-line | Removes extra spaces, except for the cases . |
break-spaces | Behavior is identical to pre-wrap , except that: any sequence of non-removable spaces always occupies space, including at the end of a line; the possibility of a line break exists after each non-removable space, including between spaces. |
initial | |
inherit |
Syntax
White-space: normal; white-space: nowrap; white-space: pre; white-space: pre-wrap; white-space: pre-line; white-space: break-spaces; white-space: inherit; white-space: initial;
3. Tab setting: tab-size property
The tab-size property is used to change the amount of indentation obtained with the TAB key. Property values are ignored when one of the three pre-line , normal , or nowrap white-space property values is set.
Only works for elements
The property is inherited.
Syntax
tab-size: 0; tab-size: 10px; tab-size: inherit; tab-size: initial;
4. Line break and word boundaries
When inline-level content is broken into lines, it is broken into inline boxes. Such a split is called a line break.
When a line breaks due to explicit line break controls, such as a newline or tag
, beginning or end of block is a forced line break.
If the line breaks due to content wrapping when the browser creates optional line breaks to fit the content, it's a soft wrap.
4.1. Breaking rules for letters: word-break property
The word-break property defines the possibility of soft wrapping between letters, i.e. when it is acceptable to break lines of text. In particular, it controls whether soft wrapping exists between adjacent typographical characters and/or digits. This does not affect the rules governing soft hyphenation created by spaces.
The property is inherited.
Syntax
Word-break: normal; word-break: break-all; word-break: keep-all; word-break: inherit; word-break: initial;
4.2. Line break: line-break
The line-break property defines the line break rules applied within an element, specifically how the line break interacts with punctuation and symbols.
The property is inherited.
line-break | |
---|---|
Values: | |
auto | The browser defines a set of line break restrictions to use, which may vary depending on the length of the line, such as using a less restrictive set of line break rules for short lines. Default value. |
loose | Breaks text using the least restrictive set of line break rules. Usually used for short lines, such as in newspapers. |
normal | Breaks text using the most common set of line break rules. |
strict | Breaks text using a strict set of line-breaking rules. |
initial | Sets the value of a property to its default value. |
inherit | Inherits property value from parent element. |
Syntax
line-break: auto; line-break: loose; line-break: normal; line-break: strict; line-break: inherit; line-break: initial;
4.3. Hyphenation: the hyphens property
The hyphens property determines whether hyphenation is allowed to create soft hyphenation within a line of text.
Hyphenation is a controlled breaking of words, in which they are usually not allowed to break in order to improve the arrangement of paragraphs. Typically, word splitting occurs along syllabic or morphemic boundaries and when the split is visually indicated (usually by inserting a hyphen, -). In some cases, hyphenation can also change the spelling of a word. In any case, word wrap is only a rendering effect: it should not affect the content of the document, text selection, or search.
CSS Text Level 3 does not define precise hyphenation rules, so it is recommended that you choose appropriate hyphens for the language.
The property is inherited.
hyphens | |
---|---|
Values: | |
none | Words are not hyphenated, even if the characters within the word explicitly define hyphenation. |
manual | Words are wrapped only in those places where there are symbols inside the word that clearly indicate the possibility of word wrapping ( special character-). Default value. |
auto | Words can be broken down into hyphenation capabilities determined automatically by the appropriate hyphenation resource in addition to those explicitly indicated by the conditional hyphen. You must set the language of your content (for example, using the HTML lang attribute or HTTP Content-Language header) to get proper word wrap. |
initial | Sets the value of a property to its default value. |
inherit | Inherits the property value from the parent element. |
Syntax
Hyphens: none; hyphens: manual; hyphens: auto; hyphens: inherit; hyphens: initial;
4.4. Wrap block overflow: overflow-wrap/word-wrap property
The overflow-wrap property (or its deprecated name word-wrap) specifies whether a non-breaking line can break at unresolved points to prevent a line box from overflowing. Works when the white-space property allows wrapping.
The property is inherited.
overflow-wrap, word-wrap | |
---|---|
Values: | |
normal | Non-breaking lines can only break at allowed break points. Default value. |
break word | |
anywhere | A non-breaking sequence of characters can be broken at an arbitrary point if there are no other acceptable break points in the string. Affects only the visual display, without affecting the source text. No hyphen is added at the line break point. The soft wrapping capabilities present anywhere are taken into account when calculating native minimum content sizes. |
initial | Sets the value of a property to its default value. |
inherit | Inherits the property value from the parent element. |
Syntax
overflow-wrap: normal; overflow-wrap: break-word; overflow-wrap: anywhere; overflow-wrap: inherit; overflow-wrap: initial;
5. Line Alignment and Justification
Line alignment and justification controls how inline content is distributed within an inline box.
5.1. Shorthand for text alignment: the text-align property
A block of text is a set of inline blocks. The text-align property specifies the text-align-all and text-align-last properties and describes how the line-level boxes in each inline box align with the inline box's start and end sides. Values other than justify-all or match-parent are assigned to text-align-all and reset to text-align-last by auto .
The property is inherited.
text-align | |
---|---|
Values: | |
start | Line-level content is aligned to the leading edge of the inline box. Default value. |
end | Line-level content is aligned to the end edge of the inline box. |
left | Line-level content is aligned to the left edge of the line box's line. In vertical writing systems, this will be the physical top or bottom, depending on the orientation of the text. |
right | Line-level content is aligned to the right edge of the line box's line. In vertical writing systems, this will be the physical top or bottom, depending on the orientation of the text. |
center | Line-level content is centered within the inline box. |
justify | The text is justified to the width of the inline box to exactly fill the line box, nestled against the left and right edges of the parent element. Unless otherwise specified in text-align-last , the last line before a forced break or the end of a block is start-aligned. Spaces between words and letters are distributed in such a way that the length of all lines is equal. Different browsers can increase both indentation between words and spacing between letters. |
justify-all | Sets text-align-all and text-align-last to justify , also aligning the last line. |
match parent | The value behaves the same as inherit except that the inherited start or end value is interpreted relative to the direction value (or the original containing block if there is no parent) and results in a computed left or right value. |
inherit | Inherits the property value from the parent element. |
Syntax
text-align: start; text-align: end; text-align: left; text-align: right; text-align: center; text-align: justify; text-align: justify-all; text-align: match-parent; text-align: inherit;
5.2. Default text alignment: text-align-all property
The text-align-all property, shorthand for the text-align property, determines the alignment of all lines of content in a block container, except for the last lines overridden by text-align-last . It accepts the values start , end , left , right , center , justify , and match-parent .
The property is inherited.
Syntax
Text-align-all: start; text-align-all:end; text-align-all: left; text-align-all: right; text-align-all: center; text-align-all: justify; text-align-all: match-parent; text-align-all: inherit;
5.3. Last line alignment: text-align-last property
The text-align-last property describes how the last line of a block or line is aligned just before a forced line break.
If set to auto , the content in the corresponding line is aligned to text-align-all , unless text-align-all is set to justify, in which case it is aligned to the start of the block. All other values are interpreted as described for text-align .
Accepts the values auto , start , end , left , right , center , justify , and match-parent .
The property is inherited.
Syntax
Text-align-last: auto; text-align-last: start; text-align-last: end; text-align-last: left; text-align-last: right; text-align-last: center; text-align-last: justify; text-align-last: match-parent;
6. Gaps
CSS allows you to control the spacing between words and typographic characters with the word-spacing and letter-spacing properties.
6.1. Spacing between words: the word-spacing property
The word-spacing property defines additional spacing between words.
Sets the spacing between words. You can use positive and negative values. If the meaning is negative, the words can overlap each other.
The value of word-spacing is affected by the value of the text-align property in the case of justified text.
The property is inherited.
Syntax
Word-spacing: normal; word-spacing: 1px word-spacing: 0.2em word-spacing: 50% word-spacing: inherit; word-spacing: initial;
6.2. Tracking: letter-spacing property
The letter-spacing property specifies additional spacing, or tracking, between adjacent typographic characters. Letter spacing is in addition to and word-spacing . Depending on the alignment rules in force, user agents may further increase or decrease the spacing between typographic character units to align text.
The property is inherited.
Syntax
Letter-spacing: normal; letter-spacing: 0.1em letter-spacing: 2px letter-spacing: inherit; letter-spacing: initial;
7. First line indent: text-indent property
The text-indent property specifies the indentation applied to lines of inline content in a block. The padding is treated as a margin applied to the start edge of the inline box.
If there is an image in the first line of the block element, then it will move along with the rest of the text.
The property is inherited.
Syntax
Text indent: 5mm; text-indent: 20px; text-indent: 5% text-indent: 2em each-line; text-indent: 2em hanging; text-indent: inherit; text-indent: initial;
Sets the alignment of the last line of a block of text.
short information
Notation
Description | Example | |
---|---|---|
<тип> | Specifies the type of the value. | <размер> |
A&&B | The values must be output in the specified order. | <размер> && <цвет> |
A | B | Indicates that only one of the suggested values (A or B) should be selected. | normal | small-caps |
A || B | Each value can be used on its own or in combination 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. | <время># |
Values
auto Matches the alignment specified by the text-align property, except for the value justify . For it, the alignment will be like start . start The line is aligned to the start edge of the block, which can change depending on the direction of the text (left to right or right to left). end The line is aligned with the block's end edge, which is determined by the direction of the text. left The string is left-aligned. right The string is right-aligned. center The string is centered. justify The string is justified in width. If there is only one word in the last line, then it will be left-aligned.
Influence different values the position of the text is shown in Table. one.
Meaning | alignment | Type of text |
---|---|---|
left | Left | |
right | Right | ![]() |
center | Centered | ![]() |
justify | By width | ![]() |
Sandbox
Winnie the Pooh was always not averse to a little refreshment, especially at eleven o'clock in the morning, because at that time breakfast had long since ended, and dinner had not even thought of starting. And, of course, he was terribly glad to see that the Rabbit took out cups and plates.
div ( text-align-last: start ; )
Example
Object Model
An object.style.textAlignLast
Note
Internet Explorer and Edge do not support start and end values.
Firefox prior to version 49 supports the -moz-text-align-last property.
Specification
Each specification goes through several stages of approval.
- Recommendation (Recommendation) - the specification is approved by the W3C and recommended as a standard.
- Candidate Recommendation ( Possible recommendation) - the group responsible for the standard is satisfied that it meets its goals, but the support of the development community is required to implement the standard.
- Proposed Recommendation ( Suggested recommendation) - at this stage, the document is submitted to the W3C Advisory Board for final approval.
- Working Draft - A more mature draft after discussion and amendments for community review.
- Editor's draft ( Editorial draft) is a draft version of the standard after changes have been made by the project editors.
- draft ( Specification draft) is the first draft version of the standard.
HTML tags defining text alignment, indentation
Justified text used in typography
The example below shows how to align text to width pages:
align="left" | align="right" |
---|---|
Every day the number of workers employed in the service sector and the dissemination of information is growing. If the symbols of the past centuries were the farm and the factory, then the symbol of the present 21st century is an office equipped with computers that have access to the information flow. |
|
align="justify" | align="center" |
Every day the number of workers employed in the service sector and the dissemination of information is growing. If the symbols of the past centuries were the farm and the factory, then the symbol of the present 21st century is an office equipped with computers that have access to the information flow. |
Every day the number of workers employed in the service sector and the dissemination of information is growing. If the symbols of the past centuries were the farm and the factory, then the symbol of the present 21st century is an office equipped with computers that have access to the information flow. |
The justify value provides uniform text alignment right and left, that is in width. This method is widely used in print.
Aligning text in HTML to center and justify
Align text in HTML to center, text to the right:
Result:
Attributes and values
- align="left" - defines left text alignment(default).
- align="center" - aligns text to the center.
- align="right" aligns text to the right.
Alignment | HTML text indent
HTML text and its indent on the left of the page
Let's produce text indent on the left in two ways:
Result:
View in a new window.
css | Internet Explorer | Chrome | Opera | safari | Firefox | Android | iOS | |
2.1 | 6.0+ | 8.0+ | 1.0+ | 3.5+ | 1.0+ | 1.0+ | 1.0+ | 1.0+ |
3 | 2.0+ | 11.6+ | 3.1+ | 3.6+ | 2.1+ | 2.0+ |
short information
CSS versions
Values
center Aligns the text to the center. The text is placed horizontally in the browser window or container where the text block is located. Lines of text seem to be strung on an invisible axis that runs through the center of the web page. A similar alignment method is actively used in headings and various captions, such as captions, it gives an official and solid look to the design of the text. In all other cases, center alignment is rarely used for the reason that it is inconvenient to read a large amount of such text. justify Justify, which means left and right justified at the same time. To perform this action, the browser in this case adds spaces between words. left Aligns the text to the left. In this case, the lines of text are aligned to the left, and the right edge is located in a "ladder". This alignment method is the most popular on websites, because it allows the user to easily look for new line and comfortable to read large text. right Aligns text to the right. This alignment method acts as an antagonist to the previous type. Namely, the lines of text are aligned to the right, while the left remains "ragged". Due to the fact that the left edge is not aligned, namely, from which new lines are read, such text is more difficult to read than if it were left-aligned. Therefore, right-alignment is usually used for short headings of no more than three lines. We do not consider specific sites where the text has to be read from right to left, where a similar alignment method may come in handy. auto Does not change the element's position. inherit Inherits the value of the parent. start Same as left if the text is going from left to right and right if the text is going from right to left. end Same as right if the text goes from left to right and left when the text goes from right to left.HTML5 CSS2.1 IE Cr Op Sa Fx
The result of this example is shown in Fig. one.
Rice. 1. Text Alignment in Safari Browser
Internet Explorer up to version 7.0 inclusive interprets a little differently given example, than other browsers, aligning not only text, but also blocks (Fig. 2).
Rice. 2. Align text in Internet browser Explorer 7
Object Model
document.getElementById("elementID ").style.textAlign
Browsers
IE up to and including version 7.0 aligns not only the content of a block element, but the element itself.