Logo hdtoledo
hdtoledo.dev
Módulos_del_Sistema
MÓDULO_TEÓRICO

Design System: CSS Variables, Colors, and Typography

Design System

Building a Professional Visual Identity

In modern web apps, we do not repeat hex codes hundreds of times across files. Instead, we establish a centralized Design System powered by CSS Variables (Custom Properties).

This lets you restyle the entire application, support dark/light modes, and tune typography scales by modifying a single line.


1. CSS Variables in :root

The :root pseudo-selector represents the top-level HTML document node (the perfect home for global tokens):

css
:root { /* Modern Dark Palette */ --bg-app: #08090e; --bg-card: rgba(18, 20, 32, 0.75); --bg-card-hover: rgba(26, 29, 46, 0.85); --border-glow: rgba(0, 240, 255, 0.25); /* Accent Colors */ --primary: #00f0ff; /* Neon Cyan */ --primary-glow: #00f0ff66; --secondary: #ff007f; /* Magenta */ --success: #00ff88; --warning: #ffb800; --danger: #ff3366; /* Typography Tokens */ --font-main: 'Inter', system-ui, sans-serif; --text-primary: #f8fafc; --text-secondary: #94a3b8; --text-muted: #64748b; /* Radii & Shadows */ --radius-sm: 6px; --radius-md: 12px; --radius-lg: 20px; --shadow-neon: 0 0 20px rgba(0, 240, 255, 0.15); }

To use any token, call the var() function:

css
.btn-access { background: var(--primary); color: var(--bg-app); border-radius: var(--radius-sm); box-shadow: var(--shadow-neon); }

2. Color Spaces: Why HSL is Superior

  • HEX (#00f0ff): Cryptic and hard to tune programmatically.
  • RGB (rgb(0, 240, 255)): Easy to read, but difficult to lighten/darken.
  • HSL (hsl(184, 100%, 50%)): Hue (0-360°), Saturation (0-100%), Lightness (0-100%).

With HSL, creating a brighter :hover state only requires altering Lightness (L):

css
/* Base */ --btn-color: hsl(184, 100%, 50%); /* Hover: We simply increase lightness from 50% to 60% */ --btn-color-hover: hsl(184, 100%, 60%);

3. Modern Typography and Glassmorphism

Import Google Fonts directly at the top of your CSS:

css
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;600&display=swap'); /* Glassmorphism Effect */ .glass-card { background: var(--bg-card); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border: 1px solid var(--border-glow); border-radius: var(--radius-md); }