Border Shorthand and Individual Sides
What you'll learn: How to set borders efficiently using shorthand notation and how to style specific sides of an element independently.
In the previous lesson, you learned about border-width, border-style, and border-color. Instead of writing these three properties separately, CSS offers a convenient shorthand that combines all three in one line.
The Border Shorthand
The border property lets you set width, style, and color in a single declaration:
.box {
border: 2px solid #333;
/* width style color */
}
This applies the same border to all four sides. Think of it as a "quick wrap" command—you're wrapping your element with identical borders on all edges at once.
The order is flexible (the browser can figure it out), but the convention is: width, style, color.
Individual Side Properties
What if you only want a border on the bottom? Or different styles on each side? CSS gives you side-specific properties:
.card {
border-top: 3px dashed blue;
border-right: 1px solid gray;
border-bottom: 2px solid black;
border-left: none;
}
Each side property (border-top, border-right, border-bottom, border-left) works exactly like the main shorthand, but affects only that edge.
You can also mix approaches—set a general border, then override one side:
.highlight {
border: 1px solid #ccc;
border-left: 4px solid orange; /* emphasize left edge */
}
Key Takeaway: Use border for uniform borders on all sides, or use border-top, border-right, border-bottom, and border-left to style each side individually—giving you complete control over your element's outline.