border is shorthand for setting border-width, border-style, and border-color all at once, and border-style is the only one of the three that's actually required for any border to appear at all, since it defaults to none otherwise, regardless of what width or color is specified. Individual sides can be targeted separately with border-top, border-right, border-bottom, and border-left, each accepting the same width/style/color shorthand, and border-radius, a related but separate property, rounds an element's corners rather than styling the border line itself.
1Understanding Borders
border is shorthand for setting border-width, border-style, and border-color all at once, and border-style is the only one of the three that's actually required for any border to appear at all, since it defaults to none otherwise, regardless of what width or color is specified. Individual sides can be targeted separately with border-top, border-right, border-bottom, and border-left, each accepting the same width/style/color shorthand, and border-radius, a related but separate property, rounds an element's corners rather than styling the border line itself.
A border won't render at all without specifying border-style, since it defaults to none — setting only border-width and border-color without a style is one of the most common reasons a border unexpectedly fails to show up.
.box {
border: 2px solid black;
}2Practical Example
Here is a real-world application of Borders showing how it is used in production CSS code.
.box {
border-width: 2px;
border-color: red;
}3Best Practices
Follow these guidelines when working with Borders:
1. Always include a border-style value, like solid or dashed, since border-style defaults to none and no border renders without it, regardless of width or color
2. Use border-top/right/bottom/left individually when only specific sides need a border, rather than the full border shorthand followed by overrides
3. Use the separate border-radius property, not the border shorthand, when you need rounded corners rather than a styled border line
Tip: A border won't render at all without specifying border-style, since it defaults to none — setting only border-width and border-color without a style is one of the most common reasons a border unexpectedly fails to show up.
.box {
border: 2px solid black;
}