Text color and basic properties
The most fundamental text property is color, which sets the text color. You can use color names, hex codes, RGB, or HSL.
Beyond color, CSS gives you control over alignment, decoration, transformation, and spacing โ all essential for professional typography.
Text spacing and effects
Fine-tune text spacing with letter-spacing, word-spacing, and line-height. Add visual flair with text-shadow and text-indent.
Font family and web-safe fonts
The font-family property sets which typeface to use. Always provide a fallback font stack โ if the first font isn't available, the browser tries the next one.
Common web-safe fonts include Arial, Verdana, Georgia, Times New Roman, and Courier New. These are available on almost all devices.
Font size, weight, and style
Font size can be set in pixels (px), em, rem, or percentages. Font weight controls boldness (100โ900 or bold/normal). Font style adds italics.
Google Fonts
Google Fonts offers hundreds of free, open-source typefaces. Import them in your HTML <head>, then use them in CSS like any font.
Visit fonts.google.com to browse fonts. You can filter by weight and preview them before importing.
Custom fonts with @font-face
Use @font-face to load custom font files. This allows you to use any typeface, even if it's not installed on the user's device.
Try it yourself: Typography playground
Edit the CSS in the left pane to see text styling changes in real-time. Try different values for text-align, text-transform, letter-spacing, line-height, and text-shadow.
Try it yourself: Google Fonts demo
This example imports two Google Fonts and demonstrates different font weights. Modify the font-family lines to switch fonts, or change font-weight to see how typefaces look at different weights.
Task: Create and style a magazine article with:
- Import two different Google Fonts (one for headings, one for body text)
- Style the main heading with text-shadow and text-transform: uppercase
- Use justify text-align on the article body
- Add letter-spacing to the subtitle
- Style a pull-quote with italic and larger font-size
- Use different font-weights to show emphasis
Use the editors above to experiment, or create your own HTML file. Start simple and build complexity!
Hint: Visit fonts.google.com to find fonts you like. Copy the import link into your HTML head. For the pull-quote, wrap it in a <blockquote> or <p> with a class, then apply italics and increase font-size. Use text-shadow: 1px 1px 3px rgba(0,0,0,0.2) for the heading.
Key takeaways
colorsets text color;text-alignaligns text;text-decorationadds underlines or strikethroughs.text-transformchanges case (uppercase, lowercase, capitalize);text-shadowadds shadows.font-familyselects typeface; always use a fallback stack (e.g., 'Open Sans', sans-serif).font-sizeuses px, em, rem, or %;font-weightcontrols boldness (100โ900);font-styleadds italics.- Import Google Fonts via <link> in the <head>; use
@font-facefor custom font files. letter-spacing,word-spacing, andline-heightcontrol text spacing for readability.
Test your knowledge
You just mastered CSS typography.
Your design skills are growing fast.
Join the Best AI Programs โ three 5-month courses, fully online, with placement assistance. Week 1 is free.
Explore our AI-era courses โ