Codectionary / Developer documentation / CSS

Text Properties

Beyond font selection, CSS offers properties to control text alignment, decoration, spacing, and casing. text-align positions text horizontally, text-decoration adds underlines/strikethroughs, text-transform changes casing, and letter-spacing/word-spacing adjust character and word gaps.

Syntax

text-align: left | center | right | justify;
text-decoration: none | underline | line-through;

Examples

Alignment and Decoration

Common text formatting properties.

.centered { text-align: center; }
.no-underline { text-decoration: none; } /* commonly used to remove default link underlines */
.strikethrough { text-decoration: line-through; }
.underline-offset { text-decoration: underline; text-underline-offset: 3px; }

Casing and Spacing

Transforming text case and adjusting spacing without editing the actual content.

.uppercase-label { text-transform: uppercase; letter-spacing: 0.05em; }
.capitalize { text-transform: capitalize; } /* Capitalizes The First Letter Of Each Word */
.tight { letter-spacing: -0.02em; } /* subtly tighter character spacing, common in large headings */

Parameters and values

  • text-align (left | center | right | justify): Horizontal alignment of text within its container
  • text-decoration (none | underline | overline | line-through): Adds or removes decorative lines
  • text-transform (none | uppercase | lowercase | capitalize): Changes displayed casing without altering the actual text
  • letter-spacing (length): Adjusts spacing between characters

Best practices

  • Use text-transform: uppercase for visual styling rather than typing text in all caps directly - screen readers may pronounce all-caps text differently
  • Avoid text-align: justify for body text on the web - unlike print, it often creates uneven, distracting gaps between words
  • Use letter-spacing sparingly and subtly - even small values like 0.05em have a noticeable effect at scale
  • Set text-decoration: none on links intentionally, and consider adding a distinct visual style (like color or an underline on hover) to preserve link affordance

At a glance

Purpose
Presentation and layout
File extension
.css
Runs in
Web browsers
Usually used with
HTML and JavaScript

Specifications & further reading

Related CSS documentation