Skip to the workspace
Pebellslearn by building
Fonts and Text Styling  ›  Lesson

Colour, Alignment and Direction

Text Alignment 12 mincolor sets inherited text colour, text-align arranges inline content within a block and should use start and end, and text direction belongs in the HTML dir attribute.

css / Colour, Alignment and Direction

Explore each scene at your own pace.

01 · The rule

The rule

Colour, Alignment and Direction

color sets inherited text colour, text-align arranges inline content within a block and should use start and end, and text direction belongs in the HTML dir attribute.

Apply inherited color and logical alignment while leaving text direction explicit in HTML.

The café opens a second branch in Dubai, and the menu page gets an Arabic version. Arabic runs right to left, so "align to the left" is suddenly the wrong instruction. The properties in this lesson decide what colour text is and which way it lines up, and the modern ones adapt to the language for you.

The rule

color paints text; text-align lines it up from the start; direction comes from the HTML.

color sets the text colour (and, by default, the colour of borders and text decorations). It is inherited, so setting it on a container colours everything inside unless a child sets its own:

.dish {
  color: #2b2d42;
}
.price {
  color: seagreen;
}

Every piece of text in a card is dark slate, except the price, which has its own rule.

text-align lines up the text and other inline content inside a block: start, end, left, right, center or justify. It moves the lines within the box, not the box itself.

  • start and end follow the writing direction: in English start is the left edge; in Arabic or Hebrew it is the right edge.
  • left and right are fixed, whatever the language.

Direction of the text itself should be set in the HTML with the dir attribute, because it is part of the content's meaning, not its style:

<html lang="ar" dir="rtl">

CSS has a direction property, but the recommendation is to leave it to dir and use it in CSS only for rare cases where the markup cannot say it.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.