CSS - text-align Property



The text-align property determines the alignment of the text with the margin of the page.

Possible Values

  • left: Aligned with the left-margin.

  • right: Aligned with the right-margin.

  • justify: Aligned with both the margins.

  • center: Aligned at the center of the page.

Applies to

All the block-level elements.

DOM Syntax

 object.style.textAlign = "justify"; 

CSS text-align - Basic Example

Here is an example:

 <html> <head> </head> <body> <h2>Text Alignment</h2> <p style="text-align: left;">Text Left Alignment.</p> <p style="text-align: right;">Text Right Alignment.</p> <p style="text-align: center;">Text Center Alignment.</p> <p style="text-align: justify; border: 2px solid red; width: 200px; height: 100px;"> Text Justify Alignment. This alignment aligns the text based on both the margins, left and right. </p> </body> </html> 
Advertisements