CSS Borders Explained
The CSS border property allows you to specify the style, width, and color of an element's border. It is one of the fundamental layers of the CSS Box Model, sitting directly between the padding and the margin.
The Three Pillars
To render a visible border, you generally need to define three properties:
- border-width: The thickness of the border (e.g.,
1px,5px,thin). - border-style: The line type. This is mandatory. Common values are
solid,dashed,dotted, anddouble. - border-color: The color of the border. If omitted, it defaults to the element's current text color.
The Shorthand
Instead of writing three separate lines, you can use the border shorthand. The standard order is width, style, then color:border: 2px solid red;
Border Radius
The border-radius property adds rounded corners to an element. You can use pixel values for a constant radius or percentages for a responsive curve. Setting border-radius: 50% on a square element will create a perfect circle.
