CSS TEXT-ALIGN
The text-align property aligns the text in an element.
Inherited: Yes
Examples
| p {text-align: center} |
Possible Values
| Value | Description |
|---|---|
| left | Aligns the text to the left |
| right | Aligns the text to the right |
| center | Centers the text |
| [string] | Specifies a string around which cells in a table column will align. Only applies to table cells. If used for other element types, it will be treated as as “left” or “right” depending on the current language writing direction (“left” for English.) |
| inherit | Explicitly sets the value of this property to that of the parent. |
| justify | justified text |


7 Responses
Ok, I may be an idiot here, but does the example go up in the css/style sheet area or is it an inline command in front of the actual text in a webpage? Most tutorials never give enough examples to help beginners understand the command.
Thank you
yes you are an idiot. CSS stands for Cascading Style Sheets. You obviously don’t understand the concept of the cascade. Get out. Now.
Jeff,
You might want to view source on some simple pages to begin learning about css…
Hope this helps!
Jeff,
You can do it in both places. This applies to everything in css. Here’s how you’d do the above example both ways:
::: How to do with is style tag
<style type=”text/css” >
p {text-align: center}
</style>
<p>hello world</p>
::how to do the same one inline in a tag:
<p style=”text-align:center”>hello world</p>
both of the above will do the same thing.
Hi,
I have a problems with this text-align thing.. As an Arabic native I have to build Bi Lingual webistes (Arabic/English). Dealing with text-align is a tedious job because we have to build two different style sheets (one for each langauge) which are identical except for the text-align statemts were it is reversed (text-align: left in english should be covnerted to text-align: right to cop with langaug flow direction). text-align always defaults to left which I think is the origin of the problem. Why doesn’t it follow the direction attribute so if direction: rtl is set text-align will automatically defaults to right or better drop left-right convention and use something like near-far:
so text-align: near will align text to the start direction of the langauge while far will do the opposite (Microsoft ha done that in .Net text drawing functions).
if it is done it will sure make my life and others much much easier.
Saleh you’re right but it’s easy to fix right?
الله أكبر
arabic {
direction: ltr;
text-align: right;
}
etc..
Bas;
This workaround doesn’t eliminate the extra work.. You still need two different stylesheets..
What I was talking about is in modern world we use dynamic page generation techniques and serving HTML through unified templates and I18N..
Under current css implementation we need to keep RightToLeft langauges in a separate template to handle text alignment properly..
What i suggest is dropping the left-right scheme and use near-far scheme where the text is aligned according to the BiDi mode and also for float attribute..
Imagine this I have an invoice where the date is right aligned (or floated)
when I change BiDi to RTL the date would still be right aligned when it should be left aligned…
I hope I made my self clear on this mater