CSS border-width Property
Last Updated :
20 Feb, 2024
CSS border-width property sets the width of the border of an element. It can be specified individually for each side (top, right, bottom, left) or all sides collectively.
Default Value: mediumÂ
CSS border-width property Syntax:Â
border-width: length|thin|medium|thick|initial|inherit
CSS border-width Property values:Â Â
- length: It is used to set the width of the border. It does not take a negative value.
- thin: It is used to set the thin border at the top of the element.
- medium: It is used to set a medium-sized top border. It is the default value.
- thick: It is used to set the thick top border.
- initial: It is used to set the border-top-width to its default value.
- inherit: This property is inherited from its parent.
CSS border-width property is a shorthand for the following CSS properties:
CSS border-width property Example:
Here we set border-width to a single value to all sides. here CSS border-width property sets border thickness.
HTML
<!DOCTYPE html>
< html >
< head >
< title >
border-width property
</ title >
< style >
div {
margin-bottom: 10px;
border-style: solid;
}
</ style >
</ head >
< body >
< h1 style = "color: green" >
GeeksforGeeks
</ h1 >
< p >border-width property: [value]</ p >
< div style = "border-width: 10px" >
This div has a border around it of 10px.
</ div >
< div style = "border-width: thin" >
This div has a thin border.
</ div >
< div style = "border-width: medium" >
This div has a medium border.
</ div >
< div style = "border-width: thick" >
This div has a thick border.
</ div >
< div style = "border-width: initial" >
border-width property: initial
This div has the default border width,
which is the medium border.
</ div >
< div id = "parent" style = "border-width: thin" >
This is the parent div.
< div style = "border-width: inherit; margin: 8px;" >
This div inherits the border width
from the parent.
</ div >
</ div >
</ body >
</ html >
|
Output:Â
CSS border-width property example output
CSS border-width property Example Explanation:
Here is the implementation explanantion of above code example.
- Here we are using boder-width property to target our given divs.
- The first <div> has a border that is 10 pixels thick all around.
- The 2nd <div> has a medium-thickness border around it.
- The fourth <div> has a thick border around it.
- The 5th <div> we setting border-width to initial reverts <div> border to default medium width.
- The 6th <div> the Parent <div> sets border width to thin, child <div> inherits, adopting same border width.
CSS border-width:val1 val2;Â property Example :
In This example we are using CSS border-width property which contains two values of border-width. like border-width: val1 val2; Â
HTML
<!DOCTYPE html>
< html >
< head >
< title >
border-width property
</ title >
< style >
div {
margin-bottom: 10px;
border-style: solid;
}
</ style >
</ head >
< body >
< h1 style = "color: green" >
GeeksforGeeks
</ h1 >
< p >border-width property: [value] [value]</ p >
< div style = "border-width: 5px 30px" >
This div has a border of 5px on the top and
bottom, and 30px on the left and right.
</ div >
< div style = "border-width: thin thick" >
This div has a thin border on the top and bottom,
and thick border on the left and right.
</ div >
</ body >
</ html >
|
Output:Â
CSS border-width: val1 val2; property Example Explanation:
Here is the implementation explanantion of above code example.:
- Here we are using border-width property with two values.
- The first <div> has a 5px border on its top and bottom, and a 30px border on its left and right sides.
- The second <div> showcases thin borders on its top and bottom, and thick borders on its left and right sides.
CSS border-width: val1 val2 val3; property Example :
The border-width property with three values sets the width for top, right/left, and bottom borders respectively, targeting each side individually. like border-width: val1 val2 val3; Â
HTML
<!DOCTYPE html>
< html >
< head >
< title >
border-width property
</ title >
< style >
div {
margin-bottom: 10px;
border-style: solid;
}
</ style >
</ head >
< body >
< h1 style = "color: green" >GeeksforGeeks</ h1 >
< p >
border-width property: [value] [value] [value]
</ p >
< div style = "border-width: 5px 30px 15px" >
This div has a 5px border on the top, 30px on
the left and right, and 15px on the bottom.
</ div >
< div style = "border-width: thin thick medium" >
This div has a thin border on the top, a thick
border on the left and right, and a medium
border on the bottom.
</ div >
</ body >
</ html >
|
Output:
CSS border-width: val1 val2 val3; property Example Explanation:
Here is the implementation explanation of the above example.
- Here we are using border-width property with 3 values sets the width for top, right/left, and bottom borders respectively,
- 1. First <div> 5px border on top, 30px on sides, 15px on bottom.
- 2. Second <div> Thin top, thick sides, medium bottom border.
CSS border-width property Example using 4 values :
In This example we are using CSS border-width property which contains four value to border-width property. like border-width: val1 val2 val3 val4;Â Â Â here we targets the top, right, bottom, and left sides of an element, respectively. Each value corresponds to one side’s width.
HTML
<!DOCTYPE html>
< html >
< head >
< title >
border-width property
</ title >
< style >
div {
margin-bottom: 10px;
border-style: solid;
}
</ style >
</ head >
< body >
< h1 style = "color: green" >
GeeksforGeeks
</ h1 >
< p >
border-width property:
[value] [value] [value] [value]
</ p >
< div style = "border-width: 5px 30px 15px 2px" >
This div has a border of 5px on the top,
30px on the right, 15px on the bottom,
and 2px on the left.
</ div >
< div style = "border-width: thin thick medium thin" >
This div has a thin border on the top, thick
border on right, medium border on the bottom,
and thin border on the left.
</ div >
</ body >
</ html >
|
Output:Â
CSS border-width:val1 val2 val3 val4; property example explanation:
- In this example we are using 4 values to target each side of given div.
- The first <div> features a 5px top border, 30px right border, 15px bottom border, and 2px left border.
- The second <div> displays a thin top border, thick right border, medium bottom border, and thin left border.
CSS border-width property Use caese:
The border-width property in CSS specifies the width of a border around an element’s content area, padding area, and border.
To specify no border in CSS, set the border-width property to “0” or “none”, or use the shorthand border: none;.
To set the width of the bottom border in CSS, use the border-bottom-width property followed by the desired width value.
CSS border-width property Supported Browsers:
The browser supported by border-width property are listed below:Â
- Google Chrome 1.0
- Edge 12.0
- Firefox 1.0
- Internet Explorer 4.0
- Apple Safari 1.0
- Opera 3.5
Share your thoughts in the comments
Please Login to comment...