16 Text

Contents

The properties defined in the following sections affect the visual presentation of characters, spaces, words, and paragraphs.

16.1 Indentation: the 'text-indent' property

'text-indent'
Value:  <length> | <percentage> | inherit
Initial:  0
Applies to:   block-level elementsblock containers
Inherited:  yes
Percentages:  refer to width of containing block
Media:  visual
Computed value:  the percentage as specified or the absolute length

This property specifies the indentation of the first line of text in a block.block container. More precisely, it specifies the indentation of the first box that flows into the block's first line box. The box is indented with respect to the left (or right, for right-to-left layout) edge of the line box. User agents shouldmust render this indentation as blank space.

'Text-indent' only affects a line if it is the first formatted line of an element. For example, the first line of an anonymous block box is only affected if it is the first child of its parent element.

Values have the following meanings:

<length>
The indentation is a fixed length.
<percentage>
The indentation is a percentage of the containing block width.

The value of 'text-indent' may be negative, but there may be implementation-specific limits. If the value of 'text-indent' is either negative or exceeds the width of the block, that first box, described above, can overflow the block. The value of 'overflow' will affect whether such text that overflows the block is visible.

Example(s):

The following example causes a '3em' text indent.


p { text-indent: 3em }

Note: Since the 'text-indent' property inherits, when specified on a block element, it will affect descendant inline-block elements. For this reason, it is often wise to specify 'text-indent: 0' on elements that are specified 'display:inline-block'.

16.2 Alignment: the 'text-align' property

'text-align'
Value:  left | right | center | justify | <string> |inherit
Initial:   depends on user agent and writing directiona nameless value that acts as 'left' if 'direction' is 'ltr', 'right' if 'direction' is 'rtl'
Applies to:   block-level elementsblock containers
Inherited:  yes
Percentages:  N/A
Media:  visual
Computed value:  the initial value or as specified

This property describes how inlineinline-level content of a block container is aligned. Values have the following meanings:

left , right , center , andleft, right, center, justify
Left, right, center, and doublejustify text, respectively. <string> Specifies a string on which cellsrespectively, as described in a table column will align (seethe section on horizontal alignment in a column for details and an example). This value applies only to table cells. If set on other elements, it will be treated as 'left' or 'right', depending on whether 'direction' is 'ltr', or 'rtl', respectively.inline formatting.

A block of text is a stack of line boxes. In the case of 'left', 'right' and 'center', this property specifies how the inlineinline-level boxes within each line box align with respect to the line box's left and right sides; alignment is not with respect to the viewport. In the case of 'justify', this property specifies that the UA may stretch the inlineinline-level boxes in additionare to adjusting their positions. (See also 'letter-spacing' and 'word-spacing' .) Example(s): In this example, note that since 'text-align' isbe made flush with both sides of the line box if possible, by expanding or contracting the contents of inline boxes, else aligned as for the initial value. (See also 'letter-spacing' and 'word-spacing'.)

If an element has a computed value for 'white-space' of 'pre' or 'pre-wrap', then neither the glyphs of that element's text content nor its white space may be altered for the purpose of justification.

Note: CSS may add a way to justify text with 'white-space: pre-wrap' in the future.

Example(s):

In this example, note that since 'text-align' is inherited, all block-level elements inside theDIV elementelements with 'class=center'a class name of 'important' will have their inline content centered.


 DIV.centerdiv.important { text-align: center }

Note. The actual justification algorithm used isdepends on the user-agent and written language dependent.the language/script of the text.

Conforming user agents may interpret the value 'justify' as 'left' or 'right', depending on whether the element's default writing direction is left-to-right or right-to-left, respectively.

16.3 Decoration

16.3.1 Underlining, overlining, striking, and blinking: the 'text-decoration' property

'text-decoration'
Value:  none | [ underline || overline || line-through || blink ] | inherit
Initial:  none
Applies to:  all elements
Inherited:  no (see prose)
Percentages:  N/A
Media:  visual
Computed value:  as specified

This property describes decorations that are added to the text of an element. If the property is specified for a block-level element, it affects all inline-level descendants ofelement using the element. If it iselement's color. When specified for (or affects)on or propagated to an inline-levelinline element, it affects all the boxes generated by that element, and is further propagated to any in-flow block-level boxes that split the element. Ifinline (see section 9.2.1.1). But, in CSS 2.1, it is undefined whether the element has no content or no text content (e.g.,decoration propagates into block-level tables. For block containers that establish an inline formatting context, the IMGdecorations are propagated to an anonymous inline element in HTML), user agents must ignore this property. Values havethat wraps all the following meanings: none Produces no text decoration. underline Each linein-flow inline-level children of textthe block container. For all other elements it is underlined. overline Each line of text has a line above it. line-through Each line ofpropagated to any in-flow children. Note that text has a line throughdecorations are not propagated to floating and absolutely positioned descendants, nor to the middle blinkcontents of atomic inline-level descendants such as inline blocks and inline tables.

Underlines, overlines, and line-throughs are applied only to text blinks (alternates between visible(including white space, letter spacing, and invisible). Conformingword spacing): margins, borders, and padding are skipped. User agents aremust not required to support this value. The color(s) required for therender these text decoration should be derived from the 'color' property value. This propertydecorations on content that is not inherited, buttext. For example, images and inline blocks must not be underlined.

Note. If an element E has both 'visibility: hidden' and 'text-decoration: underline', the underline is invisible (although any decoration of E's parent is visible.) However, CSS 2.1 does not specify if the underline is visible or invisible in E's children:

<span style="visibility: hidden; text-decoration: underline">
 <span style="visibility: visible">
  underlined or not?
 </span>
</span>

This is expected to be specified in level 3 of CSS.

The 'text-decoration' property on descendant boxeselements cannot have any effect on the decoration of the ancestor. In determining the position of and thickness of text decoration lines, user agents may consider the font sizes of and dominant baselines of descendants, but must use the same baseline and thickness on each line. Relatively positioning a block box should be formatteddescendant moves all text decorations affecting it along with the samedescendant's text; it does not affect calculation of the decoration's initial position on that line.

Values have the following meanings:

none
Produces no text decoration.
underline
Each line of text is underlined.
overline
Each line of text has a line above it.
line-through
Each line of text has a line through the middle.
blink
Text blinks (alternates between visible and invisible). Conforming user agents may simply not blink the text. Note that not blinking the text is one technique to satisfy checkpoint 3.3 of WAI-UAAG.

The color(s) required for the text decoration (e.g., they should allmust be underlined).derived from the 'color' property value of the element on which 'text-decoration' is set. The color of decorations shouldmust remain the same even if descendant elements have different 'color' values.

Some user agents have implemented text-decoration by propagating the decoration to the descendant elements as opposed to preserving a constant thickness and line position as described above. This was arguably allowed by the looser wording in CSS2. SVG1, CSS1-only, and CSS2-only user agents may implement the older model and still claim conformance to this part of CSS 2.1. (This does not apply to UAs developed after this specification was released.)

Example(s):

In the following example for HTML, the text content of all A elements acting as hyperlinks (whether visited or not) will be underlined:


 A[href]a:visited,a:link { text-decoration: underline }

16.3.2 Text shadows :Example(s):

In the 'text-shadow' property 'text-shadow' Value:    none | [ <color> || <length> <length> <length> ? ,]* [ <color> || <length> <length> <length> ?] | inherit Initial:    none Applies to:    all elements Inherited:    no (see prose) Percentages:    N/A Media:    visual This property accepts a comma-separated list of shadow effects to be appliedfollowing style sheet and document fragment:


   blockquote { text-decoration: underline; color: blue; }
   em { display: block; }
   cite { color: fuchsia; }

   <blockquote>
    <p>
     <span>
      Help, help!
      <em> I am under a hat! </em>
      <cite> —GwieF </cite>
     </span>
    </p>
   </blockquote>

...the underlining for the blockquote element is propagated to an anonymous inline element that surrounds the span element, causing the text of"Help, help!" to be blue, with the blue underlining from the anonymous inline underneath it, the color being taken from the blockquote element. The shadow effects are applied<em>text</em> in the order specified and may thus overlay each other, but they will never overlayem block is also underlined, as it is in an in-flow block to which the text itself. Shadow effects do not alterunderline is propagated. The sizefinal line of a box,text is fuchsia, but may extend beyond its boundaries.the stack level of the shadow effectsunderline underneath it is still the same as forblue underline from the element itself. Each shadow effect must specify a shadow offset and may optionally specify a blur radius and a shadow color. A shadow offset is specified with two <length> values that indicateanonymous inline element.

Sample rendering of the above underline example

This diagram shows the distance fromboxes involved in the text.example above. The first length value specifiesrounded aqua line represents the horizontal distance toanonymous inline element wrapping the rightinline contents of the text. A negative horizontal length value placesparagraph element, the shadow torounded blue line represents the left ofspan element, and the text.orange lines represent the blocks.

16.4 Letter and word spacing: the second'letter-spacing' and 'word-spacing' properties

'letter-spacing'
Value:  normal | <length> | inherit
Initial:  normal
Applies to:  all elements
Inherited:  yes
Percentages:  N/A
Media:  visual
Computed value:  'normal' or absolute length

valueThis property specifies spacing behavior between text characters. Values have the vertical distance belowfollowing meanings:

normal
The text. A negative vertical length value placesspacing is the shadow abovenormal spacing for the text. A blur radius may optionally be specified aftercurrent font. This value allows the shadow offset.user agent to alter the blur radius is a lengthspace between characters in order to justify text.
<length>
This value thatindicates inter-character space in addition to the boundaries ofdefault space between characters. Values may be negative, but there may be implementation-specific limits. User agents may not further increase or decrease the inter-character space in order to justify text.

Character spacing algorithms are user agent-dependent.

Example(s):

In this example, the blur effect.space between characters in BLOCKQUOTE elements is increased by '0.1em'.


blockquote { letter-spacing: 0.1em }

In the exact algorithm for computingfollowing example, the blur effectuser agent is not specified. A colorpermitted to alter inter-character space:


blockquote { letter-spacing: 0cm }   /* Same as '0' */

When the resultant space between two characters is not the same as the default space, user agents should not use ligatures.

'word-spacing'
Value:  normal | <length> | inherit
Initial:  normal
Applies to:  all elements
Inherited:  yes
Percentages:  N/A
Media:  visual
Computed value:  for 'normal' the value may optionally be specified before or after'0'; otherwise the absolute length

This property specifies spacing behavior between words. Values ofhave the shadow effect.following meanings:

normal
The color value will be usednormal inter-word space, as defined by the basis for the shadow effect. If no color is specified,current font and/or the UA.
<length>
This value ofindicates inter-word space in addition to the 'color' property willdefault space between words. Values may be used instead. Text shadowsnegative, but there may be used withimplementation-specific limits.

Word spacing algorithms are user agent-dependent. Word spacing is also influenced by justification (see the :first-letter'text-align' property). Word spacing affects each space (U+0020) and :first-line pseudo-elements. Example(s):non-breaking space (U+00A0), left in the example below will set atext shadow to the right and belowafter the element's text. Since no color haswhite space processing rules have been specified,applied. The shadow will haveeffect of the same colorproperty on other word-separator characters is undefined. However general punctuation, characters with zero advance width (such as the element itself,zero with space U+200B) and since no blur radius is specified, the text shadow will not be blurred: H1 { text-shadow: 0.2em 0.2em } The next example will place a shadow to the right and below the element's text. The shadow will have a 5px blur radius and will be red. H2 { text-shadow: 3px 3px 5px red } The next example specifies a list of shadow effects. The first shadow will be to the right and below the element's text and will be red with no blurring. The second shadow will overlay the first shadow effect, and it will be yellow, blurred, and placed to the left and below the text. The third shadow effect will be placed to the right and above the text. Since no shadow color is specified for the third shadow effect, the value of the element's 'color' property will be used: H2 { text-shadow: 3px 3px red, yellow -3px 3px 2px, 3px -3px } Example(s): Consider this example: SPAN.glow { background: white; color: white; text-shadow: black 0px 0px 5px; } Here, the 'background' and 'color' properties have the same value and the 'text-shadow' property is used to create a "solar eclipse" effect:     [D] Note. This property is not defined in CSS1. Some shadow effectsfixed-width spaces (such as the oneU+3000 and U+2000 through U+200A) are not affected.

Example(s):

In this example, the last example) may render text invisible in UAs that only support CSS1. 16.4 Letter andword-spacing between each word spacingin H1 elements is increased by '1em'.


h1 { word-spacing: 1em }

16.5 Capitalization: the 'letter-spacing' and 'word-spacing' properties 'letter-spacing''text-transform' property

'text-transform'
Value:   normalcapitalize | <length>uppercase | lowercase | none | inherit
Initial:   normalnone
Applies to:  all elements
Inherited:  yes
Percentages:  N/A
Media:  visual
Computed value:  as specified

This property specifies spacing behavior between text characters.controls capitalization effects of an element's text. Values have the following meanings:

normal The spacing is the normal spacing for the current font. This value allows the user agent to altercapitalize
Puts the space between charactersfirst character of each word in order to justify text. <length> This value indicates inter-character spaceuppercase; other characters are unaffected.
uppercase
Puts all characters of each word in addition to the default space between characters. Values may be negative, but there may be implementation-specific limits. User agents may not further increase or decreaseuppercase.
lowercase
Puts all characters of each word in lowercase.
none
No capitalization effects.

The inter-character spaceactual transformation in ordereach case is written language dependent. See BCP 47 ([BCP47]) for ways to justify text. Character spacing algorithms are user agent-dependent. Character spacing may also be influenced by justification (seefind the 'text-align' property).language of an element.

Only characters belonging to "bicameral scripts" [UNICODE] are affected.

Example(s):

In this example, the space between characters in BLOCKQUOTE elements is increased by '0.1em'. BLOCKQUOTE { letter-spacing: 0.1em }all text in the following example, the user agentan H1 element is not permittedtransformed to alter inter-character space: BLOCKQUOTEuppercase text.


h1 {  letter-spacing: 0cmtext-transform: uppercase }

/* Same as '0' */ When the resultant16.6 White space between two characters is not the same as the default space, user agents should not use ligatures. Conforming user agents may consider the value of: the 'letter-spacing''white-space' property

to be 'normal'. 'word-spacing''white-space'
Value:  normal | <length>pre | nowrap | pre-wrap | pre-line | inherit
Initial:  normal
Applies to:  all elements
Inherited:  yes
Percentages:  N/A
Media:  visual
Computed value:  as specified

This property specifies spacing behavior between words.declares how white space inside the element is handled. Values have the following meanings:

normal
The normal inter-wordThis value directs user agents to collapse sequences of white space, and break lines as defined by the current font and/or the UA. <length>necessary to fill line boxes.
pre
This value indicates inter-word space in addition to the defaultprevents user agents from collapsing sequences of white space. Lines are only broken at preserved newline characters.
nowrap
This value collapses white space between words. Values may be negative,as for 'normal', but there may be implementation-specific limits. Word spacing algorithmssuppresses line breaks within text.
pre-wrap
This value prevents user agents from collapsing sequences of white space. Lines are broken at preserved newline characters, and as necessary to fill line boxes.
pre-line
This value directs user agent-dependent. Word spacing is also influenced by justification (see the 'text-align' property). Example(s):agents to collapse sequences of white space. Lines are broken at preserved newline characters, and as necessary to fill line boxes.

Newlines in this example,the word-spacing between each word in H1 elements is increasedsource can be represented by '1em'. H1 { word-spacing: 1em } Conforming user agents may considera carriage return (U+000D), a linefeed (U+000A) or both (U+000D U+000A) or by some other mechanism that identifies the valuebeginning and end of document segments, such as the 'word-spacing' property to be 'normal'. 16.5 Capitalization :SGML RECORD-START and RECORD-END tokens. The 'text-transform' property 'text-transform' Value:    capitalize | uppercase | lowercase | none | inherit Initial:    none Applies to:   CSS 'white-space' processing model assumes all elements Inherited:    yes Percentages:    N/A Media:    visual This property controls capitalization effects of an element's text. Valuesnewlines have been normalized to line feeds. UAs that recognize other newline representations must apply the following meanings: capitalize Putswhite space processing rules as if this normalization has taken place. If no newline rules are specified for the first character ofdocument language, each wordcarriage return (U+000D) and CRLF sequence (U+000D U+000A) in uppercase. uppercase Puts allthe document text is treated as single line feed character. This default normalization rule also applies to generated content.

UAs must recognize line feeds (U+000A) as newline characters. UAs may additionally treat other forced break characters of each word in uppercase. lowercase Puts allas newline characters per UAX14.

Example(s):

The following examples show what white space behavior is expected from the PRE and P elements and the "nowrap" attribute in HTML.


pre        { white-space: pre }
p          { white-space: normal }
td[nowrap] { white-space: nowrap }

In addition, the effect of an HTML PRE element with the non-standard "wrap" attribute is demonstrated by the following example:


pre[wrap]  { white-space: pre-wrap }

16.6.1 The 'white-space' processing model

For each word in lowercase. none No capitalization effects.inline element (including anonymous inline elements), the actual transformation infollowing steps are performed, treating bidi formatting characters as if they were not there:

  1. Each casetab (U+0009), carriage return (U+000D), or space (U+0020) character surrounding a linefeed (U+000A) character is removed if 'white-space' is set to 'normal', 'nowrap', or 'pre-line'.
  2. If 'white-space' is set to 'pre' or 'pre-wrap', any sequence of spaces (U+0020) unbroken by an element boundary is written language dependent. See RFC 2070 ( [RFC2070] )treated as a sequence of non-breaking spaces. However, for ways to find'pre-wrap', a line breaking opportunity exists at the languageend of an element. Conforming user agents may considerthe value of 'text-transform'sequence.
  3. If 'white-space' is set to be 'none' for'normal' or 'nowrap', linefeed characters thatare not from the Latin-1 repertoire and for elements in languagestransformed for whichrendering purpose into one of the transformationfollowing characters: a space character, a zero width space character (U+200B), or no character (i.e., not rendered), according to UA-specific algorithms based on the content script.
  4. If 'white-space' is different fromset to 'normal', 'nowrap', or 'pre-line',
    1. every tab (U+0009) is converted to a space (U+0020)
    2. any space (U+0020) following another space (U+0020) — even a space before the inline, if that space also has 'white-space' set to 'normal', 'nowrap' or 'pre-line' — is removed.

Then, the block container's inlines are laid out. Inlines are laid out, taking bidi reordering into account, and wrapping as specified by the case-conversion tables of ISO 10646 ( [ISO10646] ). Example(s): In this example, all'white-space' property. When wrapping, line breaking opportunities are determined based on the text in an H1 element is transformedprior to uppercase text. H1 { text-transform: uppercase } 16.6 Whitespace :the white space collapsing steps above.

As each line is laid out,

  1. If a space (U+0020) at the beginning of a line has 'white-space' property 'white-space' Value:    normal | pre | nowrap | inherit Initial:    normal Applies to:    block-level elements Inherited:    yes Percentages:    N/A Media:    visual This property declares how whitespace insideset to 'normal', 'nowrap', or 'pre-line', it is removed.
  2. All tabs (U+0009) are rendered as a horizontal shift that lines up the elementstart edge of the next glyph with the next tab stop. Tab stops occur at points that are multiples of 8 times the width of a space (U+0020) rendered in the block's font from the block's starting content edge.
  3. If a space (U+0020) at the end of a line has 'white-space' set to 'normal', 'nowrap', or 'pre-line', it is handled. Values havealso removed.
  4. If spaces (U+0020) or tabs (U+0009) at the following meanings: normal This value directs user agentsend of a line have 'white-space' set to 'pre-wrap', UAs may visually collapse sequences of whitespace,them.

Floated and break lines as necessary to fillabsolutely-positioned elements do not introduce a line boxes. Additionalbreaking opportunity.

Note. CSS 2.1 does not fully define where line breaks may be created by occurrencesbreaking opportunities occur.

16.6.2 Example of "\A" in generated content (e.g.,bidirectionality with white space collapsing

Given the following markup fragment, taking special note of spaces (with varied backgrounds and borders for emphasis and identification):


 
     <ltr>A <rtl> B </rtl> C</ltr>

...where the BR<ltr> element in HTML). pre This value prevents user agents from collapsing sequences of whitespace. Lines are only broken at newlines inrepresents a left-to-right embedding and the source, or at occurrences of "\A"<rtl> element represents a right-to-left embedding, and assuming that the 'white-space' property is set to 'normal', the above processing model would result in generated content. nowrapthe following:

This value collapses whitespace as for 'normal', but suppresses line breaks within text except for those created by "\A"would leave two spaces, one after the A in generated content (e.g., forthe BR elementleft-to-right embedding level, and one after the B in HTML). Example(s):the following examples show what whitespace behaviorright-to-left embedding level. This is expected fromthen rendered according to the PREUnicode bidirectional algorithm, with the end result being:


     A  BC

Note that there are two spaces between A and P elements,B, and none between B and C. This can sometimes be avoided by using the "nowrap" attributenatural bidirectionality of characters instead of explicit embedding levels. Also, it is good to avoid spaces immediately inside start and end tags, as these tend to do weird things when dealing with white space collapsing.

16.6.3 Control and combining characters' details

Control characters other than U+0009 (tab), U+000A (line feed), U+0020 (space), and U+202x (bidi formatting characters) are treated as characters to render in HTML. PRE { white-space: pre } P { white-space:the same way as any normal } TD[nowrap] { white-space: nowrap } Conforming user agents may ignorecharacter.

Combining characters should be treated as part of the 'white-space' property in author and user style sheets but must specify a valuecharacter with which they are supposed to combine. For example, :first-letter styles the entire glyph if you have content like "o<span>&#x308;</span>"; it indoes not just match the default style sheet.base character.