text-align - HTML CSS CSS Property

HTML CSS examples for CSS Property:text-align

Description

The text-align CSS property sets the horizontal alignment of the inline content like text and images.

The following table summarizes the text-align Property.

Item Value
Default value: left if direction is 'ltr', right if direction is 'rtl'
Applies to:Block level elements, table cells and inline-blocks
Inherited: Yes
Animatable: No.

Syntax

The syntax of the property is as follows:

text-align:      left | right | center | justify | initial | inherit

Property Values

The following table describes the values of this property.

Value Description
leftAligns the inline text to the left.
right Aligns the inline text to the right.
center Centers the inline text.
justify The text is justified.
initial Sets this property to its default value.
inherit take the value of its parent element text-align property.

The example below shows the text-align property.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html lang="en">
 <head>
  <title>Example of CSS text-align property</title>
  <style type="text/css">
    h1 {<!--   w w w  .  j  ava2 s  . co  m-->
      text-align: center;
    }
    p {
      width: 400px;
      text-align: justify;
    }
    </style>
 </head>
 <body>
  <h1>Text-align Effect</h1>
  <p>This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. This is a test. </p>
 </body>
</html>

Related Tutorials