Chapter 11: Typography, Color, and Spacing
Good design often begins with quiet choices rather than loud tricks. A page becomes pleasant when text breathes, colors support the message and spacing forms gentle paths for the eye to follow. These ideas shape this chapter. You will explore type that works on every screen, color that stays readable and spacing that gives each element a little room to live. By combining these pieces you can shape pages that feel calm and inviting even before the more advanced layout tools arrive.
Readable text for all screens
Text sits at the heart of almost every website, so giving it care is one of the quickest ways to lift a page. Good typography feels like a clear voice in a quiet room. Readers should glide through paragraphs without noticing the shape of the letters too much. That ease comes from three things: a sensible font choice, steady sizing and spacing that lets the lines breathe.
Most devices ship with reliable system fonts, yet each platform draws them with slightly different curves and weights. A font stack lets you guide that choice by listing several families in order. The browser picks the first one it knows, which means your page keeps a consistent personality even when viewed on many screens. Stacks can hint at the tone of your site: rounded sans serif fonts feel friendly, while serif fonts carry a more traditional or bookish character.
Many beginners also explore hosted fonts such as those provided by Google Fonts (fonts.google.com). These give you access to hundreds of well-crafted families that you can include with a single link in your HTML. Choosing a hosted font can help support branding because you can match the tone to your project, whether you want playful curves, steady professionalism or a neutral voice that stays out of the way.
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap">
After linking a hosted font you simply reference it in your CSS. The browser downloads the files automatically and applies them just like any local typeface. This makes it possible to keep typography consistent across phones, tablets, laptops and even smart TVs.
body {
font-family: "Roboto", system-ui, sans-serif;
font-size: 1rem;
line-height: 1.6;
}
Size also matters. Browsers set a default of roughly sixteen pixels for base text, which is usually a good starting point because it remains readable across many screen sizes. Larger sizes can feel relaxed and welcoming, though they may crowd smaller screens. Smaller sizes can feel efficient yet risk forcing readers to squint. The safest path is to work from the default and adjust only when a section truly needs it.
Beginner pages sometimes use too many styles at once, mixing italics, bold weights and decorative faces. This can feel noisy. Instead choose one main font for body text and a second for headings if you want a contrast in tone. Keeping the number low helps the page feel coherent and makes the overall rhythm predictable for readers.
Color choices and contrast
Color shapes the tone of a page and the comfort of the reading experience. It can steer attention toward key elements, soften the look of a layout or strengthen the sense of personality behind a site. To use color well, you need both creative intention and a little practical knowledge about how the browser understands color values. Once these pieces come together you can build palettes that feel balanced, readable and consistent across all screens.
CSS accepts several ways of writing colors. The shortest form uses three hexadecimal digits such as #abc. Each digit expands behind the scenes into a pair… so #abc becomes #aabbcc. The six digit form, such as #1a4f9e, is more common because it offers full control over red, green and blue values. These values always sit in pairs, ranging from 00 for none to ff for full strength. Hex codes are precise and easy to adjust when you need fine control.
Hex colors store their values in a clear order. The first part always represents the red channel, the second part represents green and the third part represents blue. In a three digit code such as #abc, each digit expands into a pair… so a becomes aa, b becomes bb and c becomes cc. In a six digit code such as #33aa55, the pairs appear openly. The first two digits 33 set the red value, the next two aa set the green value and the final two 55 set the blue value. Because hex uses base sixteen, the range runs from 00 for no intensity to ff for full intensity, which gives you smooth control over every channel.
You can also use plain English color names such as red, white or mediumseagreen. Named colors are quick to type, yet they offer less accuracy than hex values. They work well for simple designs or early experiments. Once you begin refining a palette, most designers switch to hex codes or functional color formats such as rgb() and rgba().
Transparency becomes possible with rgba() or its newer cousin hsl() and hsla(). The final value in these functions controls opacity. A low opacity creates soft overlays, tinted backgrounds or subtle shadows. This makes transparency a powerful tool for building depth without overwhelming the page.
/* Hex codes */
.header {
background-color: #224488;
}
/* Short hex */
.badge {
background-color: #fa0;
}
/* Named color */
.notice {
color: darkred;
}
/* Transparent overlay */
.overlay {
background-color: rgba(0, 0, 0, 0.25);
}
Contrast still sits at the center of color design. Readers need a clear difference between text and its background. The easiest approach is to start with one base color for text, such as a deep charcoal, and then choose a light neutral for the background. When you want to build a palette, select one main hue for accents and then create lighter or darker variations by adjusting brightness, saturation or opacity. This keeps the palette consistent while offering enough variety for headings, links and panels.
Matching or complementary colors help keep the design harmonious. Colors that sit near each other on the color wheel feel calm and friendly, while colors that sit opposite each other feel energetic and bold. Both approaches work as long as contrast stays strong where text is involved. A bright accent against a muted surface draws the eye, yet bright text on a bright background leads to strain.
Color tools and browser extensions can inspect any value on your page and report how well it meets accessibility guidelines. These guidelines do not limit creativity. Instead they help ensure that your design remains readable for as many people as possible, especially in long passages of text or when viewed outdoors on bright screens.
Margins, padding, and balanced layout
Spacing shapes the quiet architecture of a page. Margins create gaps between elements while padding creates gaps inside them. When these spaces repeat in steady patterns the entire layout feels comfortable. Without them, everything crowds together as if the page is whispering too fast. A simple spacing scale helps keep measurements consistent so headings, paragraphs and images never feel out of place.
section {
margin: 2rem 0;
}
p {
margin: 1rem 0;
}
.card {
padding: 1rem;
border: 1px solid #ddd;
}
Backgrounds, borders, and shadows
These three tools define edges and layers. Backgrounds can highlight blocks of content or create subtle depth. Borders outline shapes and make structure visible. Shadows add a hint of lift, almost like sunlight slipping beneath a sheet of paper. When used gently they help readers understand how pieces relate to each other. When used heavily they can overwhelm, so restraint keeps the effect charming rather than loud.
There is also text-shadow, which applies a soft outline or glow to letters. It can improve readability when text sits on a busy background, though it works best in very small doses. A faint shadow can give headings a sense of presence, but strong or repeated shadows can make text blur or shimmer. As with all visual effects, clarity comes first and decoration comes second.
.panel {
background-color: #fff;
border: 1px solid #ccc;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
padding: 1rem;
}
h2 {
text-shadow: 1px 1px 2px rgba(0,0,0,0.15);
}
border and border-radius for images
Simple image borders use the same properties as any other box. You can set width, style and color on the img element. Rounded corners soften the edge and help photos feel less boxy. Keep the thickness modest so the picture remains the focus.
img.photo {
display: block;
max-width: 100%;
height: auto;
border: 4px solid #ccc;
border-radius: 8px;
}
display: block and set height: auto so images scale cleanly while the border keeps its shape.
border-image for frames and certificates
For decorative frames, use border-image. This property takes a single graphic (PNG, SVG or gradient), slices it into nine regions (four corners, four edges and the center) and paints those pieces around your element. Corners stay crisp while edges can repeat or stretch, which lets you create picture frames and certificate borders from one source file.
img.framed {
display: block;
max-width: 100%;
height: auto;
/* Reserve border space first */
border: 24px solid transparent;
/* Provide the artwork and slice it */
border-image-source: url("frame-ornate.png");
border-image-slice: 24;
border-image-width: 24;
border-image-repeat: round;
}
The border-image-slice value tells the browser how far to cut in from each edge. Those cuts create the nine-region grid. The corners draw once. The top, right, bottom and left edges repeat or stretch according to border-image-repeat. The center region is ignored for images, so your picture remains visible.
border must be nonzero for border-image to show. Use a transparent border color when the artwork itself provides the color.
Controlling edges and corner
Use a single number to slice all sides equally or four numbers to fine tune each side. Choose stretch when artwork should expand, repeat to tile exact copies or round to tile and adjust spacing so tiles fit evenly.
.frame-wood {
border: 20px solid transparent;
border-image-source: url("wood-grain.png");
border-image-slice: 20;
border-image-repeat: repeat;
}
.frame-ribbon {
border: 16px solid transparent;
border-image-source: url("ribbon.svg");
border-image-slice: 24 18 24 18;
border-image-repeat: stretch;
}
A reusable frame utility
You can turn a frame into a utility class and apply it to any element, not just images. This works for certificates, pull quotes and callouts. The element’s inner content remains untouched because the frame only paints the border box.
.u-frame {
border: 28px solid transparent;
border-image-source: url("certificate-border.svg");
border-image-slice: 28;
border-image-width: 28;
border-image-repeat: round;
background-color: #fff;
padding: 1.25rem;
}
<figure class="u-frame">
<img src="award.jpg" alt="Certificate recipient smiling with award">
<figcaption>Community Award, 2025</figcaption>
</figure>
Borders with gradients for subtle mats
You can create gentle picture mats without images by combining a transparent border with a CSS gradient as the border source. This keeps page weight low while giving a refined edge.
.mat-soft {
border: 12px solid transparent;
border-image-source: linear-gradient(90deg, #e9e9e9, #f7f7f7);
border-image-slice: 1;
border-image-repeat: stretch;
background-color: #fff;
}
These techniques let you finish a layout with elegant frames. Use them sparingly so images stay the hero and the design remains calm and readable.
Using gradients for depth and gentle color transitions
Gradients appear often in modern design because they let you blend colors smoothly without relying on image files. They can add quiet depth behind sections, soften the edges of panels or create subtle bands of tone that guide the eye. Since gradients are generated by the browser, they scale cleanly across all screen sizes and never blur.
CSS offers two main types: linear-gradient() and radial-gradient(). A linear gradient shifts color along a straight line. A radial gradient spreads outward from a center point, almost like ink drifting through water. Both can use any colors you choose, and both accept multiple stops where the tone changes.
.hero {
background-image: linear-gradient(
135deg,
#f7f7f7,
#e0e0e0 40percent,
#cccccc
);
padding: 2rem;
}
Angles add direction. A 90deg gradient moves from left to right, while 180deg moves from top to bottom. Using percentages for color stops gives you precise control over where each shift happens. These transitions can be bold for decorative banners or gentle for panels that support text.
.spotlight {
background-image: radial-gradient(
circle,
rgba(255, 255, 255, 0.9),
rgba(255, 255, 255, 0) 70percent
);
padding: 1.5rem;
}
Radial gradients work well for soft highlights because the brightness fades naturally as it expands. This makes them useful behind headings or callouts. Keeping the opacity low helps the effect stay calm rather than theatrical.
Because gradients are resolution independent, they are lighter to load than images and remain crisp on high density screens. They can also replace heavy decorative assets in certificates, dividers and hero sections, giving your layouts polish without increasing page weight. Adding gradients to your toolkit offers a final, flexible way to give pages depth and character.