CSS Colors, Typography, Backgrounds, Borders, Shadows and Gradients: Make Pages Look Professional
Color Formats
css
.a { color: tomato; } /* named */
.b { color: #1d3557; } /* hex */
.c { color: rgb(29 53 87); } /* rgb */
.d { color: hsl(215 50% 23%); } /* hue, saturation, lightness */
.e { background: rgb(29 53 87 / 0.1); } /* with transparency */
Why hsl? In
hsl you can make a lighter or darker version by changing only the lightness number. That makes color systems easy.
Typography
css
body {
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
font-size: 1rem; /* 16px by default */
line-height: 1.6;
color: #222;
}
h1 { font-size: 2.25rem; line-height: 1.2; font-weight: 700; }
.lead { font-size: 1.25rem; letter-spacing: .01em; }
a { text-decoration-thickness: 2px; text-underline-offset: 3px; }
| Property | Tip |
|---|---|
font-family | Give a stack: your font, then safe fallbacks, ending with a generic family |
font-size | Use rem. Body text at least 16px |
line-height | 1.5 to 1.7 for body text, tighter for headings |
font-weight | 400 normal, 700 bold, use fewer weights to load faster |
text-align | Left align long text. Avoid justified text on the web |
Web Fonts
Load a font with a link from a font provider or host the files yourself. Always limit the number of weights and add a fallback.
css
@font-face {
font-family: "Inter";
src: url("../fonts/inter-var.woff2") format("woff2");
font-weight: 100 900;
font-display: swap; /* show fallback text first, then swap */
}
Backgrounds, Borders, Shadows
css
.hero {
background: linear-gradient(135deg, #1d3557, #457b9d);
color: white;
}
.card {
background: #fff;
border: 1px solid #e5e7eb;
border-radius: 12px;
box-shadow: 0 4px 12px rgb(0 0 0 / .08);
}
.avatar { border-radius: 50%; }
.photo {
background-image: url("../images/cake.jpg");
background-size: cover;
background-position: center;
}
A Styled Card
html
<article class="card">
<h3>Chocolate truffle</h3>
<p>Rich and soft with dark chocolate.</p>
<a class="btn" href="/order.html">Order now</a>
</article>
css
.card { padding: 1.5rem; max-width: 22rem; }
.btn {
display: inline-block;
padding: .75rem 1.25rem;
background: #e63946;
color: #fff;
border-radius: 8px;
text-decoration: none;
font-weight: 600;
}
.btn:hover { background: #c1121f; }
Check contrast White text on
#e63946 is readable. Light gray on white is not. We will measure contrast with code in the accessibility section.
Practice
- Style the card above and add a hover and focus state to the button
- Build a gradient hero section
- Pick a font stack with one web font and a fallback
Conclusion
Color, type, backgrounds and shadows make pages look polished. Use hsl, rem, generous line-height and fewer font weights.
Quick Summary: Color formats; typography; web fonts; backgrounds; card.

