Borders have width, style, and color and can be set with one shorthand. Each side can also be styled independently, such as a notice with only border-left. An outline does not occupy box-model space and is often used for focus indication.
Read a rule first
A CSS declaration uses property: value;. The semicolon ends one declaration, and braces group declarations for the same selector. The browser reads rules from top to bottom. When several rules match one element, the cascade considers their source, selector specificity, and order.
<button class="primary">Continue</button>
<button class="quiet">Later</button>button { padding: 10px 16px; background: white; color: #0f172a; }
.primary { border: 2px solid #0369a1; }
.quiet { border: 2px dashed #64748b; }Change one value at a time and watch the text, color, size, or position. This connects each declaration to a visible result. Browser developer tools show the result of the same matching process.
A useful checking order
- Confirm that the selector matches the intended HTML element.
- Check the property name, colon, value, and semicolon.
- Test narrow space, longer text, and keyboard use.
Live style lab: Borders
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
A common source of confusion
CSS changes presentation and layout; it does not change the meaning of the HTML. Keep meaningful HTML elements and style them, rather than choosing the wrong element only for its default appearance. Readability comes before decoration.
KNOWLEDGE QUIZ
Practice: build a borders example
Write a small CSS rule set for the supplied HTML and verify each result in a browser preview.
- Keep the HTML content and semantic structure.
- Use selectors related to this lesson and write at least three declarations.
- Check text contrast and make sure no content is covered or clipped.
HTML structure
<button class="primary">Continue</button>
<button class="quiet">Later</button>