NelsonLabs
CSS Styling/Colors & Typography

Colors & Typography

Color and typography are where design meets code. Get these right and your pages look professional. Get them wrong and great content becomes hard to read.

CSS color formats

Ways to specify color
css
/* Named colors */
color: red;
color: tomato;
color: cornflowerblue;

/* Hexadecimal โ€” 6 digits: #RRGGBB */
color: #C96A30;    /* burnt orange */
color: #EDE8DC;    /* warm cream */

/* Shorthand hex โ€” 3 digits (each digit doubles) */
color: #fff;       /* same as #ffffff */
color: #000;       /* same as #000000 */

/* RGB */
color: rgb(201, 106, 48);

/* RGBA โ€” with transparency (0 = transparent, 1 = opaque) */
color: rgba(201, 106, 48, 0.5);

/* HSL โ€” Hue (0-360) Saturation (%) Lightness (%) */
color: hsl(25, 61%, 49%);

/* Modern oklch โ€” perceptually uniform, great for design systems */
color: oklch(55% 0.15 40);

Typography

Font properties
css
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;       /* base size โ€” other elements use rem relative to this */
  line-height: 1.6;      /* unitless = 1.6x the font size. 1.5โ€“1.8 is readable */
  color: #EDE8DC;
}

h1 {
  font-size: 3rem;        /* 3x the base = 48px */
  font-weight: 700;       /* bold */
  letter-spacing: -0.03em; /* tight tracking for large headings */
  line-height: 1.1;       /* tight line-height for headings */
}

p {
  font-size: 1rem;        /* equals base = 16px */
  font-weight: 400;       /* regular */
  max-width: 65ch;        /* optimal reading line length (characters) */
}

.caption {
  font-size: 0.875rem;    /* 14px */
  font-style: italic;
  color: #998870;
}

rem vs em vs px

UnitWhat it's relative toBest used for
pxScreen pixels (absolute)Borders, box shadows โ€” things that shouldn't scale
remRoot element font-size (usually 16px)Font sizes, spacing โ€” scales with user preferences
emParent element font-sizePadding/margin that should scale with its own text
%Parent element dimensionWidths, responsive containers
vw/vhViewport width/heightFull-screen sections, hero heights
chWidth of the '0' characterOptimal text column widths

TIP

Use rem for font sizes. Using rem for font sizes respects the user's browser font size preference (some users bump it up for accessibility). Using px overrides their preference. Default browser font size is 16px, so 1rem = 16px, 1.5rem = 24px, etc.