Scanner class Methods in Java

CSS text-align Property

The text-align Property

In CSS, we can align text horizontally using the text-align property. It defines the horizontal alignment of text for example, left, right ,center.
The text-align property specifies the horizontal alignment of the text in an element. By default, text is aligned to left. However,sometimes you may require a different alignment.

The text-align property can have four values as follows:-

  • left:-  It aligns the text to left.
  • right:-  It aligns the text to right.
  • center:-  It aligns the text to center of page.
  • Justify:-  It aligns the text to justified alignment.
Example:- In the example below we will use text alignment.

 HTML Code:

<body>
<p class="left"This paragraph is aligned to<strong>left</strong></p>
<p class="right"This paragraph is aligned to<strong>right</strong>.</p>
<p class="center"This paragraph is aligned to <strong>center</strong>.</p>
</body>

 CSS Code:
p.left{
    text-align:left;
}
p.right{
    text-align:right;
}
p.center{
    text-align:center;
}

Result:



When text-align is set to "justify" , each line is stretched so that every line has equal width, and left and right margins are straight(as in magazines and newspapers). Try it Yourself!

Comments