Border Width, Style, and Color
What you'll learn: How to define the thickness, appearance, and color of borders around elements using three fundamental CSS properties.
The Core Idea
Borders are visible lines that frame an element, sitting between the padding and margin in the box model. You control three characteristics of borders independently: how thick they are (border-width), what they look like (border-style), and what color they are (border-color).
Think of a picture frame: you choose the width of the frame material, the style (solid wood, ornate pattern, etc.), and the color or finish. CSS borders work the same way.
The Three Properties
border-width sets the thickness, accepting length units like px or keywords like thin, medium, thick:
div {
border-width: 5px; /* All four sides */
}
border-style determines the line pattern. Common values include solid, dashed, dotted, double, groove, ridge, inset, and outset. Note: you must set a style for borders to appear — there's no default style:
div {
border-style: solid; /* Required! */
}
border-color sets the border hue using any color format you've learned (keywords, hex, RGB, HSL):
div {
border-color: blue;
}
Applying to All Sides
These properties affect all four sides by default. A complete border looks like this:
div {
border-width: 3px;
border-style: dashed;
border-color: red;
}
Key Takeaway: Define borders using border-width for thickness, border-style for appearance (required!), and border-color for hue — each property controls that characteristic on all four sides of an element.