The CSS border properties allow you to specify the style, width, and color of an element's border. Every HTML element can have a border that surrounds the padding and content.
The border-style property is the most important; it specifies what kind of border to display. Without this, no border will appear.
/* Example Syntax */
p {
border-style: solid;
border-style: dotted;
border-style: dashed;
border-style: double;
border-style: none; /* No border */
}
The border-width property sets the thickness of the border. It can be set using specific units (px, pt, em) or by using one of the three pre-defined values: thin, medium, or thick.
p {
border-style: solid;
border-width: 5px;
}
The border-color property is used to set the color of the four borders. The color can be set by name, HEX, RGB, or HSL values.
p {
border-style: solid;
border-color: #2e7d52;
}
To keep your CSS code clean, you can specify all the individual border properties in one single property. The order of the values should be: width style color.
/* Shorthand property */
p {
border: 3px solid #007bff;
}
none.
You can also specify different borders for each side (top, right, bottom, left) of an element:
p {
border-top: 2px solid red;
border-bottom: 5px dotted blue;
border-left: 10px solid green;
}
The border-radius property is used to add rounded corners to an element, making it look more modern and friendly.
div {
border: 2px solid #2e7d52;
border-radius: 12px;
}
border-radius to 50% on a square element.
overflow: hidden; to the parent — otherwise the child's square corners poke out past the rounded edge.
border-style. Setting only border-width and border-color shows nothing — the default style is none, so you must explicitly set solid, dashed, etc.
margin, not a border — adding a border just to create a gap adds an unwanted visible line.
A single-side border (border-left) is a very common real-world pattern for highlighting a card or callout — different from the full 4-side borders shown above:
.accent-card {
border-left: 4px solid #2e7d52;
padding: 12px 16px;
background-color: #f8f9fa;
}
Rendered result:
Q: Why isn't my border showing up even though I set border-color?
A: You almost certainly forgot border-style — color and width alone render nothing.
Q: Can each side of a border have a different color?
A: Yes — set border-top-color, border-right-color, etc. individually, or use the per-side shorthands like border-left: 2px solid red;.
Q: Is border-radius supported in all modern browsers?
A: Yes, universally, with no vendor prefixes needed since roughly 2015. See the MDN border-radius reference for the full syntax including elliptical corners.