The CSS border is a shorthand property used to set the border on an element.
The CSS border properties are use to specify the style, color and size of the border of an element. The CSS border properties are given below
The Border style property is used to specify the border type which you want to display on the web page.
There are some border style values which are used with border-style property to define a border.
Value | Description |
---|---|
none | It doesn't define any border. |
dotted | It is used to define a dotted border. |
dashed | It is used to define a dashed border. |
solid | It is used to define a solid border. |
double | It defines two borders wIth the same border-width value. |
groove | It defines a 3d grooved border. effect is generated according to border-color value. |
ridge | It defines a 3d ridged border. effect is generated according to border-color value. |
inset | It defines a 3d inset border. effect is generated according to border-color value. |
outset | It defines a 3d outset border. effect is generated according to border-color value. |
See this example:
Output:
No border.
A dotted border.
A dashed border.
A solid border.
A double border.
A groove border.
A ridge border.
An inset border.
An outset border.
The border-width property is used to set the border's width. It is set in pixels. You can also use the one of the three pre-defined values, thin, medium or thick to set the width of the border.
Note: The border-width property is not used alone. It is always used with other border properties like "border-style" property to set the border first otherwise it will not work.
See this example:
Output:
Write your text here.
Write your text here.
Write your text here.
There are three methods to set the color of the border.
There is also a border color named "transparent". If the border color is not set it is inherited from the color property of the element.
Note: The border-color property is not used alone. It is always used with other border properties like "border-style" property to set the border first otherwise it will not work.
See this example:
Output
This is a solid red border
This is a solid green border
The border-radius
property is used to add rounded borders to an element:
See this example:
Output:
Normal border
Round border
Rounder border
Roundest border
Note: The border-radius
property is not supported in IE8 and earlier versions.