15 Text

Contents

  1. Indentation: the 'text-indent' property
  2. Alignment the 'text-align' property
  3. Decoration
    1. Underlining, over lining, striking, and blinking: the 'text-decoration' property
    2. Text shadows: the 'text-shadow' property
  4. Letter and word spacing: the 'letter-spacing' and 'word-spacing' properties
  5. Case
    1. Capitalization: the 'text-transform' property
    2. Special first letter/first line
  6. White space: the 'white-space' property
  7. Text in HTML
    1. Forcing a line break

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

15.1 Indentation: the 'text-indent' property

'text-indent'

Property name:  'text-indent'
Value:  <length> | <percentage> | inherit
Initial:  0
Applies to:  block-level elements
Inherited:  yes
Percentage values:  refer to parent element's width
Media groups:  visual

The property, which only applies to block-level elements that contain inline elements, specifies the indentation of the first line of text in the block. 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 should render this indentation as blank space.

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. A line is not indented if the previous line was broken explicitly (e.g., the BR element in HTML).

The following example causes a 3em text indent.

  P { text-indent: 3em }

15.2 Alignment the 'text-align' property

'text-align'

Property name:  'text-align'
Value:  left | right | center | justify | inherit
Initial:  depends on user agent
Applies to:  block-level elements
Inherited:  yes
Percentage values:  N/A
Media groups:  visual

This property describes how a paragraph of text is aligned. More precisely, it specifies how boxes in each line box of a block align width respect to the line box. (Note that alignment is not with respect to the viewport but the current containing block.)

In this example, note that since 'text-align' inherits, all block-level elements inside the DIV element with 'class=center' will be centered.

  DIV.center { text-align: center }

Note. The actual justification algorithm used is user-agent and human-language dependent.

Conforming HTML 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.

15.3 Decoration

15.3.1 Underlining, over lining, striking, and blinking: the 'text-decoration' property

'text-decoration'

Property name:  'text-decoration'
Value:  none | [ underline || overline || line-through || blink ] | inherit
Initial:  none
Applies to:  all elements
Inherited:  no (see prose)
Percentage values:  N/A
Media groups:  visual

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 children. If it is specified for (or affects) an inline element, it affects all boxes generated by the element. If the element has no content or no text content (e.g., the IMG element in HTML), user agents must skip this property.

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 are not required to support this value.

The color(s) required for the text decoration should be derived from the 'color' property value.

This property is not inherited, but descendant boxes of a block-level box should be rendered with the same decoration (e.g., they should all be underlined). The color of decorations should remain the same even if descendant elements have different 'color' values.

In the following example for HTML, the text content of all A elements acting as hyperlinks will be underlined:

  A:link, A:visited, A:active { text-decoration: underline }

15.3.2 Text shadows: the 'text-shadow' property

'text-shadow'

Property name:  'text-shadow'
Value:  none | [<color> || <length> <length> <length>? ,]* [<color> || <length> <length> <length>?] | inherit
Initial:  none
Applies to:  all
Inherited:  no (see prose)
Percentage values:  N/A
Media groups:  visual

The 'text-shadow' property accepts a comma-separated list of shadow effects to be applied to the text of the element. The shadow effects are applied in the order specified and may thus overlay each other, but they will never overlay the text itself. Shadow effects do not alter the size of the element, but may extend beyond its boundaries. The Z-order of the shadow effects is the same as for 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 indicate the distance from the text. The first length value specifies the horizontal distance to the right of the text. A negative horizontal length value places the shadow to the left of the text. The second length value specifies the vertical distance below the text. A negative vertical length value places the shadow above the text.

A blur radius may optionally be specified after the shadow offset. The blur radius is a length value that indicates the boundaries of the blur effect. The exact algorithm for computing the blur effect is not specified.

A color value may optionally be specified before or after the length values of the shadow effect. The color value will be used as the basis for the shadow effect. If no color is specified, the value of the 'color' property will be used instead.

The example below will set a text shadow to the right and below the element's text. Since no color has been specified, the shadow will have the same color as the element itself, 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 }

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:

Solar eclipse effect

Note. This property is not defined in CSS1. Some shadow effects may render text invisible in UAs that only support CSS1.

15.4 Letter and word spacing: the 'letter-spacing' and 'word-spacing' properties

'letter-spacing'

Property name:  'letter-spacing'
Value:  normal | <length> | auto | inherit
Initial:  normal
Applies to:  all elements
Inherited:  yes
Percentage values:  N/A
Media groups:  visual

This property specifies spacing behavior between text characters. Values have the following meanings:

normal
This value allows the user agent to alter the space between characters in order to justify text.
<length>
This value indicates inter-character space in addition to the default space between characters. Values may be negative, but there may be implementation-specific limits.
auto
This value tells the user agent to adjust the spacing between characters so that the entire text of an element fits on one line. This value should only be used with special elements (e.g., headlines). See also the 'font-size' property for related 'auto' behavior.

Character spacing algorithms are user agent-dependent. Character spacing may also be influenced by justification (see the 'text-align' property).

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

  BLOCKQUOTE { letter-spacing: 0.1em }

This will not happen if 'letter-spacing' is explicitly set to a <length> value, as in:

  BLOCKQUOTE { letter-spacing: 0 }
  BLOCKQUOTE { letter-spacing: 0cm }

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

Conforming HTML user agents may consider the value of the 'letter-spacing' property to be 'normal'.

'word-spacing'

Property name:  'word-spacing'
Value:  normal | <length> | inherit
Initial:  normal
Applies to:  all elements
Inherited:  yes
Percentage values:  N/A
Media groups:  visual

This property specifies spacing behavior between words. Values have the following meanings:

normal
This value allows the user agent to alter the space between words in order to justify text.
<length>
This value indicates inter-word space in addition to the default space between words. Values may be negative, but there may be implementation-specific limits.

Word spacing algorithms are user agent-dependent. Word spacing may also be influenced by justification (see the 'text-align' property).

In this example, the word-spacing between each word in H1 elements is increased by '1em'.

  H1 { word-spacing: 1em }

Conforming HTML user agents may consider the value of the 'word-spacing' property to be 'normal'.

15.5 Case

15.5.1 Capitalization: the 'text-transform' property

'text-transform'

Property name:  'text-transform'
Value:  capitalize | uppercase | lowercase | none | inherit
Initial:  none
Applies to:  all elements
Inherited:  yes
Percentage values:  N/A
Media groups:  visual

This property controls capitalization effects of an element's text. Values have the following meanings:

capitalize
Puts the first character of each word in uppercase.
uppercase
Puts all characters of each word in uppercase.
lowercase
Puts all characters of each word in lowercase.
none
No capitalization effects.

The actual transformation in each case is human language- dependent. See [RFC2070] for ways to find the language of an element.

Conforming HTML user agents may consider the value of 'text-transform' to be 'none' for characters that are not from the Latin-1 repertoire and for elements in languages for which the transformation is different from that specified by the case-conversion tables of [UNICODE].

In this example, all text in an H1 element is transformed to uppercase text.

  H1 { text-transform: uppercase }

15.5.2 Special first letter/first line

Please consult the sections on first line and first letter for information on specially formatting the first letter or line of a paragraph.

15.6 White space: the 'white-space' property

'white-space'

Property name:  'white-space'
Value:  normal | pre | nowrap | inherit
Initial:  normal
Applies to:  block-level elements
Inherited:  yes
Percentage values:  N/A
Media groups:  visual

This property declares how whitespace inside the element is handled. Values have the following meanings:

normal
This value allows user agents to collapse sequences of white space. Line breaks may be created by characters or elements (e.g., the BR element in HTML).
pre
This value prevents user agents from collapsing sequences of white space.
nowrap
This value suppresses line breaks within text except for those created by other elements (e.g., the BR element in HTML).

The following examples show what whitespace behavior is expected from the PRE and P elements in HTML.

  PRE { white-space: pre }
  P   { white-space: normal }

Conforming HTML user agents may skip the 'white-space' property in author and user style sheets but must specify a value for it in the default style sheet.

15.7 Text in HTML

15.7.1 Forcing a line break

The current CSS2 properties and values cannot describe the behavior of the BR element; the BR element specifies a line break between words. In effect, the element is replaced by a line break. Future versions of CSS may handle added and replaced content, but CSS2-based formatters must treat BR specially.