text-align

Jump to: navigation, search

text-align

This article is Ready to Use.


W3C Working Draft

Summary

The text-align CSS property describes how inline content like text is aligned in its parent block element. text-align does not control the alignment of block elements itself, only their inline content.

Overview table

Initial value start, or a nameless value that acts as left if direction is ltr, right if direction is rtl, if start is not supported by the browser.
Applies to block containers
Inherited Yes
Media visual
Computed value as specified, except for the match-parent value which is calculated against its parent's direction value and results in a computed value of either left or right
Animatable No
CSS Object Model Property textAlign

Syntax

  • text-align: <string>
  • text-align: center
  • text-align: end
  • text-align: justify
  • text-align: left
  • text-align: match-parent
  • text-align: right
  • text-align: start
  • text-align: start end


Values

start
The same as left if direction is left-to-right and right if direction is right-to-left.
end
The same as right if direction is left-to-right and left if direction is right-to-left.
left
The inline contents are aligned to the left edge of the line box.
right
The inline contents are aligned to the right edge of the line box.
center
The inline contents are centered within the line box.
<string>
The first occurrence of the one-char string is the element used for alignment. the keyword that follows or precedes it indicates how it is aligned. This allows to align numeric values on the decimal point, for instance.
justify
The text is justified. Text should line up their left and right edges to the left and right content edges of the paragraph.
match-parent
Similar to inherit with the difference that the value start and end are calculated according the parent's direction and are replaced by the adequate left or right value.
start end
Specifies start alignment of the first line and any line immediately after a forced line break; and end alignment of any remaining lines not affected by text-align-last.

Compatibility

Desktop

FeaturesChromeFirefoxInternet ExplorerOperaSafari
Basic support (left, right, center and justify)
1.0
Yes
1.0
Yes
3.0
Yes
3.5
Yes
1.0
Yes
Block alignment values [1] Non-standard
1.0
prefix
1.0
prefix
?
none
?
none
1.3
prefix
start
1.0
Yes
1.0
Yes
?
none
?
Yes
3.1
Yes
end
1.0
Yes
?
Unknown
?
none
?
none
3.1
Yes
match-parent
16
Yes
?
none
?
none
?
none
?
none
<string> value
?
none
?
none
?
none
?
none
?
none

Mobile

FeaturesAndroidChrome for AndroidFirefox MobileIE MobileOpera MobileSafari Mobile
Basic support
?
Unknown
?
Unknown
?
Unknown
?
Unknown
?
Unknown
?
Unknown
Block alignment values [1] Non-standard
?
Unknown
?
Unknown
?
Unknown
?
Unknown
?
Unknown
?
Unknown
start
?
Unknown
?
Unknown
?
Unknown
?
Unknown
?
Unknown
?
Unknown
end
?
Unknown
?
Unknown
?
Unknown
?
Unknown
?
Unknown
?
Unknown
match-parent
?
Unknown
?
Unknown
?
Unknown
?
Unknown
?
Unknown
?
Unknown
<string> value
?
Unknown
?
Unknown
?
Unknown
?
Unknown
?
Unknown
?
Unknown


Examples

View live exampleThis just shows the four possible types of text-alignment.

HTML

<p class="left"> This paragraph is aligned to the left. </p>

<p class="centered"> This paragraph is centered. </p>

<p class="right"> This paragraph is aligned to the right. </p>

<p class="justified">This paragraph needs to be really long in order to show how to justify text. It only works because we set a width for this paragraph though.</p>

CSS

.left { text-align: left;}
.cenetered{ text-align: center;}
.right { text-align: right;}
.justified { width: 200px; text-align: justify;}

Notes

The standard-compatible way to center a block itself without centering its inline content is setting the left and right margin to auto, e.g.: margin:auto; or margin:0 auto; or margin-left:auto; margin-right:auto;


Related specifications

Specification Status Related Changes
CSS Text Level 3 Working Draft Added the start and end keyword. Changed the unnamed initial value to start (which it was). Added the <string> value, the match-parent value and the start end double value.

Compatibility

Desktop

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic Support 1.0
1.0
3.0
3.5
1.0

Mobile

Feature Android BlackBerry Chrome for mobile Firefox Mobile (Gecko) IE Mobile Opera Mobile Opera Mini Safari Mobile
Basic Support Supported (when?)
Supported (when?)
Supported (when?)
Supported (when?)
Supported (when?)
Supported (when?)
Supported (when?)
Supported (when?) -o
Supported (when?)

See also

Other articles

Attribution

This article contains content originally from external sources.

Portions of this content come from the Mozilla Developer Network cc-by-sa-small-wpd.svg: Article

Portions of this content come from the Microsoft Developer Network: Article