
How to Create a Parallax Effect with HTML and CSS
11/10/2019
CSS Font Properties: Family, Style, Variant, Weight, and Size
11/10/2019
Text properties control how words and lines appear inside an element. This lesson covers indentation, alignment, decoration, spacing, capitalization, line height, and vertical alignment.
6. CSS text properties
Table 6.1 lists the most common text properties.
| Property | Description | Values |
|---|---|---|
text-indent | First-line indentation | length | percentage |
text-align | Text alignment | left | right | center | justify |
text-decoration | Underlines, overlines, and strikethrough | none | underline | overline | line-through |
letter-spacing | Spacing between characters | normal | length |
word-spacing | Spacing between words | normal | length |
text-transform | Letter casing | capitalize | uppercase | lowercase | none |
line-height | Height of each line | length | percentage |
vertical-align | Vertical alignment | top | middle | bottom baseline | sub | super | length or percentage |
6.1. Indent the first line with text-indent
text-indent: 2em indents the first formatted line of text in a block. Accepts lengths and percentages. A negative value can produce a hanging first line.
.a { text-indent: 50px; }
.b { text-indent: 3em; }
.c { text-indent: 30%; }
.d { text-indent: -50px; }6.2. Align text with text-align
Use left, right, center, or justify to align inline content in its block. Prefer start or end when the result should follow the writing direction.
.a { text-align: center; }
.b { text-align: right; }
.c { text-align: left; }
.d { text-align: justify; }6.3. Add lines with text-decoration
Common values are underline, overline, line-through, and none. The shorthand can also set color, style, and thickness. If you remove a link underline, make sure links remain recognizable.
.a { text-decoration: underline; }
.b { text-decoration: overline; }
.c { text-decoration: line-through; }Try the text-decoration example
6.4. Set character spacing with letter-spacing
letter-spacing: 0.08em adds space between characters. A negative length tightens spacing. Read the result in context, especially at small sizes.
.a { letter-spacing: 3px; }
.b { letter-spacing: 10px; }
.c { letter-spacing: 15px; }Try the letter-spacing example
6.5. Set word spacing with word-spacing
word-spacing: 0.2em increases the space between words. normal uses the font’s customary spacing.
.a { word-spacing: 5px; }
.b { word-spacing: 20px; }
.c { word-spacing: 50px; }6.6. Change displayed case with text-transform
Use uppercase, lowercase, capitalize, or none. These values change how text appears, while the source text keeps its original spelling.
.a { text-transform: capitalize; }
.b { text-transform: uppercase; }
.c { text-transform: lowercase; }Try the text-transform example
6.7. Set line height with line-height
The unitless value line-height: 1.5 makes each line 1.5 times the element’s font size. A unitless value lets descendants calculate line height using their own font size.
.a { line-height: 50px; }
.b { line-height: 3em; }
.c { line-height: 30%; }6.8. Align inline content vertically with vertical-align
This property aligns inline-level boxes inside a line and content inside table cells. Use values such as baseline, middle, top, and bottom. For example, vertical-align: middle can help align an inline icon with text. To center a separate block vertically inside a container, use layout tools such as Flexbox or Grid.
.a { vertical-align: top; }
.b { vertical-align: middle; }
.c { vertical-align: bottom; }Try the vertical-align example
.a { vertical-align: baseline; }
.b { vertical-align: sub; }
.c { vertical-align: super; }
.d { vertical-align: -10px; }Open the additional example from the lesson
Try it yourself
Give article paragraphs comfortable line spacing, center the title, and add an underline to article links.
Show one solution
article p { line-height: 1.5; }
article h1 { text-align: center; }
article a { text-decoration: underline; }