Extensible HyperText Markup Language

text-align

Definition

The text-align property specifies the alignment of inline content (text and images) for block elements such as paragraphs and headings, as well as tables cells. The screen shot below shows an image center-aligned because it is contained by a heading with text-align set to center.

Screen shot of a Web browser showing a center aligned image.

Below is the markup for the screen shot above.

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  3. <head>
  4. <title>CSS Example</title>
  5. <style type="text/css">
  6. h1 {text-align: center}
  7. </style>
  8. </head>
  9. <body>
  10. <h1><img src="logo.gif" alt="Pink Flower Web Design" /></h1>
  11. </body>
  12. </html>

Example

  1. h1 {text-align: center}

Characteristics

Possible values

left
Align left.
right
Align right.
center
Align center.
justify
Align left and right.
inherit
Use the same computed value as the parent element for this property.

Default value

left if text direction is ltr; right if direction is rtl

Applies to

Block-level elements, table cells (th and td) and elements with display property set to inline-block.

Inherited

Yes

See also