border is a shorthand that sets border width, style and color in one line.border-radius is used to round the corners of the element.border-style, the border will not be visible.1px, 2px, 5px).solid, dashed, dotted, etc.border to set all at once, or properties like border-width, border-style, border-color individually.10px, 50% for circles).Basic shorthand syntax for setting all border properties at once:
/* Shorthand border syntax: width style color */
.card {
border: 2px solid #333;
}
Here are a few common border styles you will use frequently:
/* Different border styles and rounded corners */
.container {
border: 2px solid #333;
}
.dashed-border {
border: 3px dashed #2563eb;
}
.rounded-border {
border: 5px solid #16a34a;
border-radius: 10px;
}
| Property | Description | Example Value |
|---|---|---|
border |
Shorthand for setting width, style and color. | 2px solid #333 |
border-width |
Width of the border. | 1px, 2px, 5px |
border-style |
Style of the border line. | solid, dashed, dotted |
border-color |
Color of the border. | #333, red, rgba(0, 0, 0, 0.2) |
border-radius |
Radius of the element's corners. | 10px, 50% |
This box has a 5px solid red border around it.
/* Simple bordered box example */
.box {
border: 5px solid red;
padding: 10px;
max-width: 260px;
margin: 12px auto 0;
}
border-radius to create rounded corners and softer UI components.border property for cleaner, more readable CSS.border-style (like solid) or your border will not appear.rgba() for subtle, modern-looking borders.solid, dashed and dotted borders.border-width values and see how the appearance changes.border-radius: 50%; on a square element.border-top, border-right, border-bottom or border-left.