text-align
Quick Summary for text-align
The text-align CSS property sets the horizontal alignment of the content inside a block element or table-cell box. This means it works like vertical-align but in the horizontal direction.
Code Usage for text-align
/* Keyword values */ text-align: start; text-align: end; text-align: left; text-align: right; text-align: center; text-align: justify; text-align: justify-all; text-align: match-parent;  /* Character-based alignment in a table column */ text-align: "."; text-align: "." center;  /* Block alignment values (Non-standard syntax) */ text-align: -moz-center; text-align: -webkit-center;  /* Global values */ text-align: inherit; text-align: initial; text-align: revert; text-align: unset; 
More Details for text-align

text-align

The text-align CSS property sets the horizontal alignment of the content inside a block element or table-cell box. This means it works like vertical-align but in the horizontal direction.

Syntax

/* Keyword values */ text-align: start; text-align: end; text-align: left; text-align: right; text-align: center; text-align: justify; text-align: justify-all; text-align: match-parent;  /* Character-based alignment in a table column */ text-align: "."; text-align: "." center;  /* Block alignment values (Non-standard syntax) */ text-align: -moz-center; text-align: -webkit-center;  /* Global values */ text-align: inherit; text-align: initial; text-align: revert; text-align: unset; 

The text-align property is specified in one of the following ways:

Using the keyword values start, end, left, right, center, justify, justify-all, or match-parent. Using a <string> value only, in which case the other value defaults to right. Using both a keyword value and a <string> value.

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.

justify

The inline contents are justified. Text should be spaced to line up its left and right edges to the left and right edges of the line box, except for the last line.

justify-all

Same as justify, but also forces the last line to be justified.

match-parent

Similar to inherit, but the values start and end are calculated according to the parent's direction and are replaced by the appropriate left or right value.

<string>

When applied to a table cell, specifies the alignment character around which the cell's contents will align.

Accessibility concerns

The inconsistent spacing between words created by justified text can be problematic for people with cognitive concerns such as Dyslexia.

MDN Understanding WCAG, Guideline 1.4 explanations Understanding Success Criterion 1.4.8 | Understanding WCAG 2.0

Formal definition

Initial valuestart, 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 toblock containers
Inheritedyes
Computed valueas 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
Animation typediscrete

Formal syntax

start | end | left | right | center | justify | match-parent

Examples

Start alignment

HTML
<p class="example">   Integer elementum massa at nulla placerat varius.   Suspendisse in libero risus, in interdum massa.   Vestibulum ac leo vitae metus faucibus gravida ac in neque.   Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p> 
CSS
.example {   text-align: start;   border: solid; } 
Result

Centered text

HTML
<p class="example">   Integer elementum massa at nulla placerat varius.   Suspendisse in libero risus, in interdum massa.   Vestibulum ac leo vitae metus faucibus gravida ac in neque.   Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p> 
CSS
.example {   text-align: center;   border: solid; } 
Result

Example using "justify"

HTML
<p class="example">   Integer elementum massa at nulla placerat varius.   Suspendisse in libero risus, in interdum massa.   Vestibulum ac leo vitae metus faucibus gravida ac in neque.   Nullam est eros, suscipit sed dictum quis, accumsan a ligula. </p> 
CSS
.example {   text-align: justify;   border: solid; } 
Result

Specifications

Specification
CSS Logical Properties and Values Level 1 # text-align
CSS Text Module Level 3 # text-align-property

See also

margin: auto, margin-left: auto, vertical-align Select your preferred language English (US)DeutschFrançais日本語한국어Português (do Brasil)Русский中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote

"Olivia, my eldest daughter, caught measles when she was seven years old. As the illness took its usual course I can remember reading to her often in bed and not feeling particularly alarmed about it. Then one morning, when she was well on the road to recovery, I was sitting on her bed showing her how to fashion little animals out of coloured pipe-cleaners, and when it came to her turn to make one herself, I noticed that her fingers and her mind were not working together and she couldn’t do anything. 'Are you feeling all right?' I asked her. 'I feel all sleepy,' she said. In an hour, she was unconscious. In twelve hours she was dead. The measles had turned into a terrible thing called measles encephalitis and there was nothing the doctors could do to save her. That was...in 1962, but even now, if a child with measles happens to develop the same deadly reaction from measles as Olivia did, there would still be nothing the doctors could do to help her. On the other hand, there is today something that parents can do to make sure that this sort of tragedy does not happen to a child of theirs. They can insist that their child is immunised against measles. ...I dedicated two of my books to Olivia, the first was ‘James and the Giant Peach’. That was when she was still alive. The second was ‘The BFG’, dedicated to her memory after she had died from measles. You will see her name at the beginning of each of these books. And I know how happy she would be if only she could know that her death had helped to save a good deal of illness and death among other children."

I just checked google books for BFG, and the dedication is there. 

https://www.google.com.au/books/edition/_/quybcXrFhCIC?hl=en&gbpv=1 


Roald Dahl, 1986
Random CSS Property

<angle>

The <angle> CSS data type represents an angle value expressed in degrees, gradians, radians, or turns. It is used, for example, in <gradient>s and in some transform functions.
angle#turn css reference