Text Properties — CSS

text-align aligns text: left, center, right or justify (both left and right). text-transform changes how letters look, for example uppercase (all capitals)…

Here is what you will make: a paragraph that is centred, all in capitals and underlined, without changing a single letter of its HTML.

In the typography lesson you set the font. This lesson sets other details of text: aligned left or centred, capital letters, underlines and the space between letters. All the properties in this lesson only change how the text looks. The original text in the HTML stays the same.

Alignment, capitals and lines

This rule changes three things about a paragraph:

p {
  text-align: center;
  text-transform: uppercase;
  text-decoration: underline;
}

The capitals are only how the text looks: the text in the HTML stays as you typed it. So you don't need to retype the text.

text-align sets where text is placed inside its element's own box. The boxes of headings and paragraphs are as wide as the page, so center puts the text in the middle of the page.

Letter spacing, and the line on links

The browser already underlines an <a> link, and text-decoration: none removes that line. If you remove the line, give the link another sign, such as a colour different from the text around it, so the link still looks clickable.

⚠️ Centring that doesn't work, and gaps that grow too wide

TL;DR: text-align aligns text: left, center, right or justify (both left and right). text-transform changes how letters look, for example uppercase (all capitals), lowercase (all small letters) or capitalize (a capital at the start of each word), without changing the text in the HTML. text-decoration adds or removes a line: underline (a line under the text), line-through (a line through it) or none (no line). letter-spacing sets the space between letters, for example 2px.

⚡ Alignment, capitals, lines

Write:

p {
  text-align: center;
  text-transform: uppercase;
  text-decoration: underline;
}
Guess first: after you add uppercase, does the text in the HTML turn into capitals too?

No. The text in the HTML stays as you typed it. CSS only shows it in capitals.

Meaning: text-align: center centres the text. text-transform: uppercase shows every letter as a capital. text-decoration: underline adds a line under the text. All three only change how the paragraph looks.

⚡ Centred inside its own box

Guess first: text-align: center is written on an <a>. Does the link move to the middle?

No. The box of an <a> is only as wide as its text, so there is no room to move the text. Write text-align on its parent, such as a <p>.

Meaning: text-align sets where text is placed inside its element's own box. A paragraph's box is as wide as the page, so center puts its text in the middle of the page.

⚡ The line on links

Write:

a {
  text-decoration: none;
}

Meaning: text-decoration sets the lines on text. The browser already underlines an <a> link, and none removes that line. If you remove the line, give the link another sign, such as a different colour, so it still looks clickable.

What you will learn