Loading
CSS Text Alignment
In CSS, the text-align property is used to control the horizontal alignment of text inside an element. It helps designers and developers present content in a visually appealing and readable format.



What is text-align ?

The text-align property sets the horizontal alignment of inline content (like text) within a block-level element.



Available Values of text-align

ValueDescription
leftAligns text to the left edge (default for most languages).
rightAligns text to the right edge.
centerCenters the text horizontally.
justifySpreads text so that it aligns with both the left and right edges. Commonly used for paragraphs.
startAligns text based on the start of the writing direction (left in left to right, right in right to left)
end
Aligns text based on the end of the writing direction (right in left to right, left in right to left).



Syntax:

.text-left {
  text-align: left;
}
.text-right {
  text-align: right;
}
.text-center {
  text-align: center;
}
.text-justify {
  text-align: justify;
}



Example: 

<!DOCTYPE html>
<html>
  <head>
    <title>CSS Text Alignment Example</title>
  </head>
  <body>
    <h2>Setting Text Alignment using CSS</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>

Output:

Uploaded Image




Key Point

  • text-align is useful for headings, paragraphs, and content blocks.
  • justify improves readability for large blocks of text.
  • start and end are logical properties that respect language direction (good for multilingual sites).