CSS Tutorial

Colors & Typography

Choosing palettes and mastering web fonts

1. Working with Colors

In CSS, there are many ways to define a color.
MethodSyntaxDescription
Namedcolor: red;Basic browser-defined colors
Hexcolor: #ff0000;6-digit hex code (RRGGBB)
RGBrgb(255, 0, 0)Red, Green, Blue (0-255)
HSLhsl(0, 100%, 50%)Hue, Saturation, Lightness
Wait! HSL is the preferred method for modern web design because it's much easier to understand. You can change the "Lightness" to create hover states without needing a whole new color.

2. Typography

The way you display text is critical for readability and "feel."
css
body {
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  font-weight: 400;
}

Google Fonts

Wait! You aren't limited to the basic "System Fonts" (Arial, Times New Roman). You can import thousands of high-quality fonts from Google Fonts using the @import rule or a <link> tag in your HTML.

Line Height and Spacing

  • line-height: The space between lines of text. 1.5 is standard for body text.
  • letter-spacing: The space between characters.
  • text-align: Left, Center, Right, or Justify.

Summary

TermDescription
font-familyThe name of the font typeface
font-weightThe thickness of the letters (100 to 900)
line-heightThe vertical spacing of text
opacityHow transparent an element is (0 to 1)
RGBA / HSLAColors with an "Alpha" channel for transparency
Best ForSetting the mood and readability of your site
Logic"Visual aesthetics and hierarchy"
SafetyEnsure high contrast between text and background for accessibility
ModernVariable fonts allow for infinite weights and styles in one file
StandardUse rem for font sizes to support user accessibility settings
IdentityTypography is 90% of web design