iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

CSS Text

CSS gives you a dozen properties for tuning text: colour, alignment, decoration, spacing, transformation. Most of them are intuitive once you know the name.

Common text properties

PropertyPurposeExample
colorText colour.#333
text-alignHorizontal alignment.left, center, right, justify
text-decorationUnderline, line-through, none.underline dotted
text-transformForce case.uppercase, capitalize
letter-spacingSpace between letters.0.05em
word-spacingSpace between words.4px
line-heightVertical rhythm. Unitless multiplier is ideal.1.5
text-indentFirst-line indent in a paragraph.2em
white-spaceHow whitespace and line breaks are handled.nowrap, pre

A tiny demo of alignment

left aligned Lorem ipsum dolor sit amet, consectetur center aligned Lorem ipsum dolor sit amet, consectetur
Fig 1. The same paragraph aligned left and centred.
Tip: Use a unitless line-height (e.g. 1.5). It scales with the element's font-size; line-height: 24px does not.

Example

Example
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Verdana, sans-serif; }
.box { background: #04AA6D; color: #fff; padding: 20px; border-radius: 6px; }
</style>
</head>
<body>

<h1>CSS Text</h1>
<div class="box">Edit the CSS on the left, then click Run &raquo;</div>

</body>
</html>
Try it Yourself »

Exercise

Remove the underline from this link.

a { text-decoration: ; }

Test yourself

Q1. Which property removes the underline from a link?
Q2. Which value of `text-transform` turns text ALL CAPS?
Q3. What is the recommended way to express line-height?

Discussion

Loading…