CSS Text

Colour, alignment, decoration, transform and spacing.

✍️ 3 exercises + code challenge in this lesson

CSS has many properties for formatting text:

  • color: text colour.
  • text-align: left, right, center, justify.
  • text-decoration: underline, line-through, none.
  • text-transform: uppercase, lowercase, capitalize.
  • letter-spacing, word-spacing, line-height.
  • text-indent: indents the first line.
  • text-shadow: adds a shadow, e.g. 2px 2px 4px #000.

Key Takeaways: CSS Text

Mastering CSS Text helps you write clean and reliable CSS code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

CSS Text Code Example

CSS
<style>
  .center  { text-align: center; }
  .upper   { text-transform: uppercase; letter-spacing: 4px; }
  .strike  { text-decoration: line-through; color: #94A3B8; }
  .shadow  { font-size: 32px; color: #2563EB; text-shadow: 2px 2px 6px rgba(0,0,0,.3); }
  .spaced  { line-height: 2; text-indent: 40px; }
</style>

<p class="center">Centred text</p>
<p class="upper">uppercase with letter spacing</p>
<p class="strike">Crossed out</p>
<p class="shadow">Text shadow</p>
<p class="spaced">This paragraph has a large line height and an indented first line, which makes long text easier to read.</p>
Free sign-in required · Google login available

CSS Text Practice Exercises

Check what you learned in “CSS Text”.

/ 3 solved
Fill in the blank

Make the text uppercase.

h2 {
  text-transform: ;
}
✓ Correct! Not quite. Try again.
Multiple choice

Which property removes the underline from links?

✓ Correct! Not quite. Try again.
Code challenge

Centre the heading text.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services