All topics › Unit 3 · Cascading Style Sheets
Topic 27 · 27 of 43
Text Styling
All in one: every text style, side by side
What this example compares
- Where the lines sit:
text-align: leftvsrightvscentervsjustify, and notext-alignat all - Centre the words or the box:
text-align: centervsmargin: 0 autovs both - Lines on text:
underlinevsoverlinevsline-throughvsnone - The style of the line:
solid,double,dotted,dashed,wavyinunderline wavy #E07B1E - Thickness and gap:
underline 3pxvstext-underline-offset: 4px, and four longhands vs one shorthand - A link without an underline: colour only vs bold vs a bottom border vs the underline back on
:hoverand:focus - Meaning or look:
<del>vsline-through,<strong>vsfont-weight, with<em>and<mark> - Letter case:
text-transform: nonevsuppercasevslowercasevscapitalize - Typed by hand or made by CSS: typed capitals vs
uppercase, a hand-typed title vscapitalize - The four values of a shadow: soft vs hard vs no blur vs negative vs glow vs two shadows
- Where a shadow helps: white text over the campus picture vs a shadow on body text
- The first line or the gap:
text-indent: 2emvs space between paragraphs - Spaces and line breaks:
white-space: normalvsnowrapvsprevspre-wrap - A word too long for its box: nothing vs
overflow-wrap: break-wordvs the cut with an ellipsis - The ellipsis recipe: why
text-overflow: ellipsisneedswhite-space: nowrapandoverflow: hidden - Space between letters:
letter-spacing: 0vs0.06emvs0.15emvs0.3em - Everything together: Asha Kumar's profile from the Build it section
Point at any word in the code to see what it means (tap on a phone); click a word to keep its meaning on screen. Read the comment above each numbered panel, press Run, then Edit & experiment to try the TRY lines yourself.
Loading the example…
What you should see
You should see seventeen panels (scroll inside the result to reach them all). Panel 1 shows the same paragraph four ways, with white gaps in the justified one, then marks that line up on the right and a centred heading. In panel 2 only the second and third boxes move to the middle. Panels 3 to 6 show underlines of every kind; in panel 6 the first link is hard to find in its sentence. In panel 7 the cards look the same in pairs. Panel 8 shows one line of HTML in four different cases, and in panel 9 the first two cards look identical. Panel 10 shows six shadows on the word Asha, and in panel 11 the white words are only easy to read on the second picture. Panel 13 shows the extra spaces only in the last two boxes, and in panels 14 and 15 the long address sticks out of its box everywhere except where it is broken onto several lines or cut off. Panel 17 is Asha's profile with tags in capitals and a long link cut off with three dots. There is no JavaScript on this page, so the Console prints nothing.
Quick check: in panel 15, why does the first box show no dots even though it has text-overflow: ellipsis?
Because nothing has been cut off. text-overflow: ellipsis only says what to draw where text is cut. The cutting is done by overflow: hidden, and white-space: nowrap keeps the text on one line, so you need all three together.