Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
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.

Colour, Alignment and Direction

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.

The shortcut

Write start and end, not left and right, unless something really must stay on one physical side. Then the same stylesheet works for every language.

Aligning prices on both menusStep 1 of 4
  1. The goal

    Prices should hug the far edge of each card, away from where reading begins.

Drills

Answer fast — trust the rule.

quick drill

.dish has color: navy. The h3 inside it has no colour rule. What colour is the dish name?

quick drill

On a page with dir="rtl", where does text-align: start put the text?

quick drill

A p with a fixed width has text-align: center. What is centred?

quick drill

Where should the direction of an Arabic page be declared?

Remember

  • color paints text and is inherited by everything inside.
  • Prefer text-align: start and end; they follow the writing direction.
  • Declare direction in HTML with dir; text-align only lines up content inside a box.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainOne stylesheet, two directions

The café's stylesheet uses text-align: right for prices. Explain what happens when the same stylesheet is used for the Arabic menu, and how to write it so both languages look right.