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
Font Properties
Core typography properties control how text is displayed. font-family sets the typeface (with fallbacks), font-size controls size, font-weight controls boldness, font-style controls italics, and the font shorthand can set several of these at once. Well-chosen typography is one of the highest-impact, lowest-effort improvements you can make to a design.line-height and Vertical Spacing
line-height controls the vertical space a line of text occupies, directly affecting readability. Unitless values (like 1.5) are generally preferred over fixed units, since they scale proportionally with font-size rather than creating an inconsistent fixed gap.List Styling
list-style controls how list markers (bullets or numbers) appear on <ul>/<ol> elements. list-style-type sets the marker style, list-style-position controls whether markers sit inside or outside the content box, and list-style: none is the standard way to remove markers entirely, commonly used when repurposing a list for navigation.Flexbox
Flexbox (Flexible Box Layout) is a powerful one-dimensional layout system in CSS that makes it easy to design flexible and responsive layouts. It provides an efficient way to distribute space and align items in a container, even when their sizes are unknown or dynamic. Flexbox is particularly useful for creating navigation bars, card layouts, and centering content.
Core typography properties control how text is displayed. font-family sets the typeface (with fallbacks), font-size controls size, font-weight controls boldness, font-style controls italics, and the font shorthand can set several of these at once. Well-chosen typography is one of the highest-impact, lowest-effort improvements you can make to a design.line-height and Vertical Spacing
line-height controls the vertical space a line of text occupies, directly affecting readability. Unitless values (like 1.5) are generally preferred over fixed units, since they scale proportionally with font-size rather than creating an inconsistent fixed gap.List Styling
list-style controls how list markers (bullets or numbers) appear on <ul>/<ol> elements. list-style-type sets the marker style, list-style-position controls whether markers sit inside or outside the content box, and list-style: none is the standard way to remove markers entirely, commonly used when repurposing a list for navigation.Flexbox
Flexbox (Flexible Box Layout) is a powerful one-dimensional layout system in CSS that makes it easy to design flexible and responsive layouts. It provides an efficient way to distribute space and align items in a container, even when their sizes are unknown or dynamic. Flexbox is particularly useful for creating navigation bars, card layouts, and centering content.