Prev Next

Borders

Border-style

The border-style property defines the style of the border. Various styles with its value and the function are given below:
None – no border is drawn
Dotted – the border is a dotted line drawn on top, bottom, left or right of the
background of the element
Dashed – the border is a dashed line
Solid – the border is a solid line
Double – the border is a double line
Groove – a 3D groove is drawn in colors based on the “color” value
Ridge – a 3D ridge is drawn in colors based on the “color” value
Inset – a 3D inset is drawn in colors based on the “color” value

Sample Code

H1 {border-style:solid;}

Border-width

The border-width property defines the thickness of the four borders around padding area. The width can be set as a specific size (in px, pt, cm, em,
etc) or by using one of the three pre-defined values: thick, medium, or thin.
The border-width property can have from one to four values (for the top
border, right border, bottom border, and the left border).

Sample Code

H1 {border-width:thick;}
P {border-width:2px 10px 4px 20px;}

Border-color

The border-color property is used to set the color of the four borders. The color can be set by:
name – specify a color name, like “red”
RGB – specify a RGB value, like “rgb(255,0,0)”
Hex – specify a hex value, like “#ff3399”

The border-color property can have from one to four values (for the top border, right border, bottom border, and the left border).
If border-color is not set, it inherits the color of the element.

Sample Code

H1 {border-color:#668fc0;}

Border on individual sides

From the examples above you have seen that it is possible to specify a different border for each side. In CSS, there are also properties for specifying each of the borders (top, right, bottom, and left).

Sample Code

H1 {
   border-top-style:dotted;
   border-bottom-style:solid;
   border-bottom-width:10px;
   border-bottom-color:10px;
   }

Border

As you can see from the examples above, there are many properties to consider when dealing with borders. To shorten the code, it is also possible to specify all the individual border properties in one property. The border property is a shorthand property for the following individual border
properties:

Border-width
Border-style (required)
Border-color

Sample Code

H1 {border:5px solid red;}

All Border Properties

Border
Border-top
Border-top-width
Border-top-style
Border-top-color
Border-right
Border-right-width
Border-right-style
Border-right-color
Border-bottom
Border-bottom-width
Border-bottom-style
Border-bottom-color
Border-left
Border-left-width
Border-left-style
Border-left-color

Try it yourself

<html>
<head>
<style>
h1{
   border-width: 5px;
   border-style:solid;
   border-color:red;
   border-bottom-color:green;
   border-top-style:dotted;
   background-color:pink;
   }
</style>
</head>
<body>
 <h1>A sample of border </h1>
</body>
</html>

Leave a Comment