← Learning Hub
Beginner

Text and Fonts

CSS controls how text looks: its font, size, weight, spacing and alignment.

Most of a website is text, so good typography makes a huge difference to how easy and pleasant a page is to read. A few simple choices - a clean font, a comfortable size (16px or more for body text), enough line spacing, and lines that aren't too long - make any page look more professional.

Fonts must be installed on the visitor's device, or downloaded by the page. Services like Google Fonts offer hundreds of free fonts you can link to, including fonts for Hindi and other Indian scripts. Always list fallback fonts in case the main one doesn't load.

  • font-family picks the font. List fallbacks, ending with a generic family such as sans-serif.
  • font-size sets size. rem units scale with the visitor's browser settings, which is kind to people who need larger text.
  • font-weight makes text bolder or lighter.
  • line-height sets the space between lines; about 1.5 is comfortable for reading.
  • text-align aligns text left, right or centre.
Example
<!DOCTYPE html>
<html>
  <head>
    <style>
      body { font-family: Georgia, serif; }
      h1 { font-family: Arial, sans-serif; font-size: 2rem; text-align: center; letter-spacing: 2px; }
      p { font-size: 1.1rem; line-height: 1.6; max-width: 40ch; }
      .note { font-style: italic; color: #6b7280; text-transform: uppercase; font-size: 0.8rem; }
    </style>
  </head>
  <body>
    <h1>Reading Corner</h1>
    <p>Good typography makes long text easy to read. Keep lines short and give them room to breathe.</p>
    <p class="note">This line is small, italic and in capitals.</p>
  </body>
</html>
▶ Try it yourself
Key points
  • font-family with fallbacks, ending in a generic family.
  • Use rem for sizes so text respects user settings.
  • line-height around 1.5 makes paragraphs easy to read.

📝 Test yourself

1. Why list several fonts in font-family?
2. Which unit respects the visitor's preferred text size?
3. Fill in the value that centres text:
text-align: ;