CSS Text Properties

2008 Oct 17


text-align vertical-align
direction unicode-bidi text-decoration text-indent text-transform
line-height letter-spacing white-space word-spacing

Text is the content, fonts are used to display the content.


text-align
Values left | center | right | justify | inherit
Initial Value depend on agent and writing direction of language
Applies to block-level elements

left

To be or not to be.

center

To be or not to be.

right

To be or not to be.

justify

To be or not to be.

The center value for text-align is different than the <center> because the latter affected elements other than text.

CSS does not define or implement that a hyphenated word is split at the hyphen.


vertical-align
Values baseline | sub | super | top | text-top | middle |
bottom | text-bottom | <percentage> | <length> | inherit
Initial Value baseline
Applies to inline elements and table cells
Percentages of font-size
Note For table cells, only the values: baseline, top, middle, and bottom are allowed.

text-decoration lines added to emphasize relative vertical position.
baseline - align baselines

One two three.

sub - move downward

One two three.

middle - align vertical midpoint at 0.5ex

One two three.

super - raise up

One two three.

top - align top box with containing box

One two three.

text-top - align top of inline box with top of parent's content

One two three.

bottom - align bottom of inline box with bottom of containing box

Onetwo three.

text-bottom - align bottom of elment's inline box with bottom of parent's content area

Onetwo three.

The middle value aligns the middle of the inline element's box 0.5ex above the baseline of the parent element, where 1.0ex is defined relative to the font-size for the parent element. Since 1.0ex is typically 0.5em, middle is 0.25em (although some use x-height).

The percentage value raises or lower the baseline of the element (or the bottom edge of a replaced element) by the specified amount - not of the parent.


direction
Values ltr | rtl | inherit
Initial Value ltr
Applies to all elements

Affects all block-level elements, table columns, and position of last line of a justified element. For inline elements direction applies only if unicode-bidi is embed or unicode-bidi.

CSS+HTML Results
<p style="direction: ltr;">left to right.</p>

left to right.

<p style="direction: rtl;">right to left.</p>

right to left.


unicode-bidi
Values normal | embed | bidi-override | inherit
Initial Value normal
Applies to all elements

following is from CSS2.1 specification.


text-decoration
Values none | [ underline || overline || line-through || blink ] | inherit
Initial Value none
Applies to all elements

CSS+HTML Results
.dec { color: teal; 
       text-decoration: underline 
                        line-through
                        overline; }
...
<p>Example of 
  <span class="dec">all</span> lines.</p>

Example of all lines.

Note that blink has never been supported by IE.


text-indent
Values <length> | <precentage> | inherit
Can be negative - but usually requires margin or padding.
Initial Value 0
Applies to block-level elements
Percentages of width of containing block

CSS+HTML Results
<p style="text-indent: 2em; 
  border: 1px dashed;">Indent me.</p>

Indent me.


text-transform
Values uppercase | lowercase | capitalize | none | inherit
Initial Value none
Applies to all elements
Percentages of width of containing block

line-height
Values <length> | <percentage>| <number>| normal | inherit
Initial Value normal (typically 1.2*font-size)
Applies to all elements
Percentages of font-size

The line-height is the distance between the baslines of text (not the size of the font). It determines how much the height of each element's box is increased or decreased. Typical use is to alter the spacing of lines. Actually, this property controls the leading, which is the extra space between lines of text beyond the font's size.

leading = line-height - font-size

The line-height specifies a minimum, the actual value can be larger.

Any non zero line-height (which can be negative) is split in half and applied before and after the line.


letter-spacing
Values <length> | normal | inherit
Initial Value normal
Applies to all elements

This value is added (can be negative) to the normal space between letters of 0.

CSS+HTML Results
.ls { word-spacing: 6px; color: teal; }
...
<p>Example of 
  <span class="ls"> ABCDE</span> l-s.</p>

Example of ABCDE l-s.

.lsn { word-spacing: -3px; color: teal; }
...
<p>Example of 
  <span class="lsn"> ABCDE</span> neg l-s.</p>

Example of ABCDE neg l-s.


white-space
Values normal | nowrap | pre | pre-wrap | pre-line | inherit
Initial Value normal
Applies to all elements (CSS2.1); block-level elements (CSS1 and CSS2)

value whitespace linefeeds auto line wrapping
normal collapsed ignored allowed
nowrap collapsed ignored prevented
pre-line collapsed honored allowed
pre preserved honored prevented
pre-wrap preserved honored allowed
word-spacing
Values <length> | normal | inherit
Initial Value normal
Applies to all elements

This value is added (can be negative) to the normal space between words of 0. A word is defined as non-whitespace characters surrounded by whitespace.

CSS+HTML Results
.ws { word-spacing: 6px; color: teal; }
...
<p>Example of 
  <span class="ws">AA BB CC</span> w-s.</p>

Example of AA BB CC w-s.

.wsn { word-spacing: -8px; color: teal; }
...
<p>Example of 
  <span class="wsn"> AAAA BBBB CCCC </span> w-s.</p>

Example of AAAA BBBB CCCC w-s.