CSS border Property
The border property in CSS is a shorthand property used to define the width, style, and color of an element’s border in a single declaration.
1. Syntax
Accepted Values:
| Property | Possible Values | Description |
|---|---|---|
border-width | thin, medium, thick, px, em, etc. | Defines the thickness of the border. |
border-style | solid, dotted, dashed, double, groove, ridge, none, hidden | Specifies the appearance of the border. |
border-color | Named colors, #hex, rgb(), rgba(), hsl(), etc. | Sets the color of the border. |
2. Example – Applying a Border to an Element
✅ The div will have a 3px solid red border.
3. Example – Different Border Styles
✅ Each div has a different border style.
4. Example – Border on Specific Sides
Instead of applying a border to all sides, you can set it only on specific sides:
✅ This applies different border styles on each side.
5. Example – Using border-width, border-style, and border-color Separately
You can also define these properties individually:
✅ This is equivalent to border: 4px dashed purple;
6. Example – Border with Rounded Corners (border-radius)
✅ This creates rounded corners for a softer appearance.
7. Example – Removing Borders
To remove a border, you can set:
✅ This removes any existing border.
8. Best Practices
✔ Use border shorthand for cleaner code.
✔ Always include border-style, otherwise, the border won’t appear.
✔ Use rgba() or hsla() for transparency effects.
✔ Combine with border-radius for modern designs.

