Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

text-align — aligning line content

`text-align` aligns inline content inside a block container. Logical values `start` and `end` account for text direction; the property does not center the block itself.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

text-align: start | end | left | right | center | justify | match-parent | justify-all;
/* Additional CSS Text Level 4 draft value: <string> */

text-align controls the alignment of inline content within a block container’s line boxes, not the position of the container itself. It is inherited; its initial value is start.

start and end mean logical start and end. In horizontal text, start means left for direction: ltr and right for direction: rtl. left and right refer to the line-left and line-right edges, respectively. In the vertical writing modes vertical-rl and vertical-lr, these are the top and bottom edges, respectively. center centers line content.

justify distributes content to fill the line; the last line is start-aligned by default. text-align-last controls that line. match-parent resolves inherited logical alignment using the parent’s direction instead of reinterpreting it using the child’s direction.

CSS Text Level 3 already defines justify-all, which justifies every line, including the last. The CSS Text Level 4 draft describes text-align as a shorthand for text-align-all and text-align-last. In that draft, a single-character <string> aligns table-cell contents on the specified character. A specification does not establish browser support for these features; support must be verified separately.

Examples

<!doctype html>
<meta charset="utf-8">
<title>text-align</title>
<style>
  .box {
    width: 240px;
    border: 1px solid;
    margin: 8px;
    text-align: start;
  }
</style>
<div class="box" dir="ltr">ABC</div>
<div class="box" dir="rtl">ABC</div>

Result

LTR: ABC at the left edge.
RTL: ABC at the right edge.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources