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;
}
pis the selector: the rule is for every<p>. Each line inside{ }is one declaration.text-align: center;centres the text. The other values areleft(aligned left),right(aligned right) andjustify(aligned on both the left and the right). The default isstart, which is the same as aligned left for text read from left to right, like English.text-transform: uppercase;shows every letter as a capital. The other values arelowercase(all small letters),capitalize(the first letter of each word as a capital) andnone(as typed).text-decoration: underline;adds a line under the text. The other values areline-through(a line through the text) andnone(no line).
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
letter-spacing: 2px;adds 2 pixels of space between every letter. It suits headings in capitals or short links, but it is too wide for long paragraphs.word-spacingsets the space between words the same way.
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
- Made-up values. The browser doesn't know
text-align: middleortext-decoration: underlined. Writecenterandunderline. text-alignon a link. The box of an<a>is only as wide as its text, so there is no room to move the text. That is whytext-align: centeron the<a>shows no effect. Writetext-alignon its parent, such as a<p>.justifyin a narrow column. In a narrow column,justifymakes wide gaps between words. For text on the web,leftis usually easier to read.
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.