Styling & Typography
Typography and color are the foundation of great visual design. Let's master them.
Colors
Color Systems
RGB Colors
Red, Green, Blue values (0-255 each)
color: rgb(255, 0, 0); /* Red */
color: rgb(0, 255, 0); /* Green */
color: rgb(0, 0, 255); /* Blue */
color: rgb(128, 128, 128); /* Gray */
Hex Colors
Hexadecimal notation (#RRGGBB)
color: #FF0000; /* Red */
color: #00FF00; /* Green */
color: #0000FF; /* Blue */
color: #808080; /* Gray */
color: #FFF; /* White (shorthand) */
color: #000; /* Black (shorthand) */
HSL Colors
Hue, Saturation, Lightness
color: hsl(0, 100%, 50%); /* Red */
color: hsl(120, 100%, 50%); /* Green */
color: hsl(240, 100%, 50%); /* Blue */
color: hsl(0, 0%, 50%); /* Gray */
HSL is great for:
- Creating color schemes
- Adjusting brightness
- Finding complementary colors
RGBA & HSLA
With transparency (alpha 0-1)
color: rgba(255, 0, 0, 0.5); /* Red with 50% opacity */
color: hsla(0, 100%, 50%, 0.8); /* Red with 80% opacity */
Creating Color Schemes
Complementary
Colors opposite on color wheel
color: hsl(0, 100%, 50%); /* Red */
color: hsl(180, 100%, 50%); /* Cyan (opposite) */
Analogous
Colors next to each other
color: hsl(0, 100%, 50%); /* Red */
color: hsl(30, 100%, 50%); /* Orange */
color: hsl(60, 100%, 50%); /* Yellow */
Monochromatic
Different tints/shades of same color
color: hsl(0, 100%, 20%); /* Dark red */
color: hsl(0, 100%, 50%); /* Red */
color: hsl(0, 100%, 70%); /* Light red */
Text Color
p {
color: #333; /* Text color */
background-color: #f0; /* Background */
}
/* Links */
a {
color: #0066cc; /* Normal link */
}
a:visited {
color: #990099; /* Visited link */
}
a:hover {
color: #ff6600; /* Hovered link */
}
Typography
Font Family
body {
font-family: Georgia, 'Times New Roman', serif;
}
h1 {
font-family: 'Arial', sans-serif;
}
Font Stacks
Always include fallbacks:
/* Serif */
font-family: 'Georgia', serif;
/* Sans-serif */
font-family: 'Arial', 'Helvetica', sans-serif;
/* Monospace */
font-family: 'Courier New', monospace;
/* Web safe fonts */
font-family: Arial, Verdana, Tahoma, sans-serif;
Web Fonts
Import fonts from Google Fonts or other sources:
<head>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap" rel="stylesheet">
</head>
<style>
body {
font-family: 'Poppins', sans-serif;
}
</style>
Font Size
/* Absolute sizes */
p {
font-size: 16px;
}
/* Relative sizes */
h1 {
font-size: 2rem; /* 2 × base size */
}
h2 {
font-size: 1.5rem;
}
small {
font-size: 0.875rem;
}
/* Responsive */
@media (min-width: 768px) {
body {
font-size: 18px;
}
}
Font Weight
p {
font-weight: 400; /* Normal */
font-weight: 700; /* Bold */
font-weight: lighter; /* Lighter than parent */
font-weight: bold; /* Bold keyword */
}
/* With web fonts */
font-family: 'Poppins', sans-serif;
font-weight: 400; /* Regular */
font-weight: 700; /* Bold */
Line Height
Space between lines of text
p {
line-height: 1.6; /* 1.6 × font size */
line-height: 24px; /* Fixed size */
line-height: 150%; /* Percentage */
}
/* For readability */
body {
line-height: 1.5;
}
/* For headings */
h1 {
line-height: 1.2;
}
Letter Spacing
Space between letters
h1 {
letter-spacing: 0.05em; /* Increase space */
}
.tight {
letter-spacing: -0.02em; /* Decrease space */
}
Text Alignment
p {
text-align: left; /* Default */
text-align: center; /* Centered */
text-align: right; /* Right aligned */
text-align: justify; /* Stretched to edges */
}
Text Transform
.uppercase {
text-transform: uppercase; /* UPPERCASE */
}
.lowercase {
text-transform: lowercase; /* lowercase */
}
.capitalize {
text-transform: capitalize; /* Capitalize */
}
Text Decoration
a {
text-decoration: underline;
text-decoration: none;
text-decoration: overline;
text-decoration: line-through;
}
Text Shadow
h1 {
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
/* offset-x | offset-y | blur-radius | color */
}
/* Multiple shadows */
h1 {
text-shadow:
1px 1px 2px rgba(0, 0, 0, 0.3),
3px 3px 6px rgba(0, 0, 0, 0.2);
}
Complete Typography System
/* Base styles */
html {
font-size: 16px;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
line-height: 1.6;
color: #333;
}
/* Headings */
h1, h2, h3, h4, h5, h6 {
font-weight: 700;
line-height: 1.2;
margin: 24px 0 12px 0;
}
h1 {
font-size: 2.5rem;
color: #000;
}
h2 {
font-size: 2rem;
color: #111;
}
h3 {
font-size: 1.5rem;
color: #222;
}
/* Paragraphs */
p {
margin: 0 0 16px 0;
}
/* Links */
a {
color: #0066cc;
text-decoration: none;
transition: color 0.3s ease;
}
a:hover {
color: #0052a3;
text-decoration: underline;
}
/* Small text */
small {
font-size: 0.875rem;
}
/* Code */
code {
background-color: #f4f4f4;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
}
/* Lists */
ul, ol {
margin: 0 0 16px 0;
padding-left: 24px;
}
li {
margin-bottom: 8px;
}
/* Responsive */
@media (max-width: 768px) {
html {
font-size: 14px;
}
h1 {
font-size: 2rem;
}
h2 {
font-size: 1.5rem;
}
}
Real-World Example: Blog Post
<style>
.blog-post {
max-width: 800px;
margin: 0 auto;
padding: 40px 20px;
font-family: 'Georgia', serif;
color: #333;
line-height: 1.8;
}
.blog-post h1 {
font-size: 2.5rem;
margin-bottom: 10px;
color: #000;
line-height: 1.2;
}
.blog-post .meta {
font-size: 14px;
color: #666;
margin-bottom: 30px;
border-bottom: 1px solid #eee;
padding-bottom: 20px;
}
.blog-post h2 {
font-size: 1.8rem;
margin-top: 40px;
margin-bottom: 15px;
color: #111;
}
.blog-post p {
margin-bottom: 20px;
}
.blog-post code {
background-color: #f4f4f4;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
color: #d63384;
}
.blog-post a {
color: #0066cc;
}
.blog-post a:hover {
text-decoration: underline;
}
</style>
<article class="blog-post">
<h1>The Art of Typography</h1>
<div class="meta">
By John Doe | Published Jan 28, 2024
</div>
<p>Great typography is the foundation of good design...</p>
<h2>Choosing the Right Font</h2>
<p>When selecting fonts for your project, consider...</p>
<h2>Best Practices</h2>
<p>Always maintain sufficient <code>line-height</code> for readability.</p>
</article>
Best Practices
- Use Semantic Font Sizes - Use rem for responsive typography
- Maintain Contrast - Ensure text is readable on background
- Limit Fonts - Use 2-3 fonts maximum
- Line Height - Use 1.5-1.8 for body text
- Font Size - 16px base is standard
- Color Psychology - Colors evoke emotions
- Consistency - Use consistent typography system
- Accessibility - Ensure sufficient contrast ratio
Next Steps
Master typography and styling, then learn:
- Animations & Transitions - Add motion
- Advanced Techniques - Advanced effects