8.1 CSS Typography & Text Styling

Lesson 4: CSS Typography & Text Styling

  1. CSS Fonts & Text Properties

  • Font Families: A font family defines the typeface used to display text. You can specify multiple fonts, where the browser picks the first available one.

     body {
      font-family: "Arial", "Helvetica", sans-serif;
    }
  • Font Size: Defines the size of the text. It can be set using various units such as pixels (px), ems (em), or percentages (%).

    css코드 복사h1 {
      font-size: 24px;
    }
  • Font Weight: Adjusts the thickness of the text, ranging from normal (400) to bold (700).

    p {
      font-weight: bold;
    }
  • Importing and Using Google Fonts: Google Fonts provides a wide variety of font families that can be easily integrated into your project. To use a Google Font:

    1. Choose a font, copy the <link> provided, and add it to the <head> of your HTML file.

    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">

    Then, use the font in your CSS:

    body {
      font-family: 'Roboto', sans-serif;
    }
  1. Text Color & Formatting

  • Setting Text and Background Color: You can use predefined color names, HEX codes, RGB, or HSL values to style text.

  • Text Formatting Options:

    • Bold: font-weight: bold;

    • Italic: font-style: italic;

    • Underline: text-decoration: underline;

  1. Text Alignment & Decoration

  • Aligning Text: The text-align property aligns text within an element. Values can be left, right, center, or justify.

  • Text Decoration: You can add decorations such as underlining, overlining, or striking through text.

  1. Text Transformation & Spacing

  • Text Transformations: Change the case of text using text-transform. Common values include uppercase, lowercase, and capitalize.

  • Line Height and Spacing: Control the spacing between lines, letters, and words.

Last updated