border-width
shorthand property sets the width for the overall border of an element or for each side individually.
Item | Value |
---|---|
Initial value | |
Inherited | No. |
Version | CSS1 |
JavaScript syntax | object.style.borderWidth="thin thick" |
Applies to | All elements. |
border-width: width [ width width width]
where width
is
non-negative length | medium | thick | thin | inherit
border-width
can have one to four values.
border-width:thin medium thick 10px;
is equal to
border-width:thin medium thick;
is equal to
border-width:thin medium;
is equal to
border-width:thin;
is equal to all four borders are thin.
The property values are listed in the following table.
Value | Description |
---|---|
thin | thin border |
medium | medium border. Default |
thick | thick border |
length | Set the thickness of the border |
inherit | Inherit the border width from the parent element |
border-width |
Yes | Yes | Yes | Yes | Yes |
An example showing how to use border-width CSS property.
<!DOCTYPE HTML>
<html>
<head>
<style>
div {<!-- w w w.ja va 2 s .c o m-->
padding: 3px;
border-color: black;
border-style: solid;
background: mistyrose;
margin: 5px;
border-width: thin;
}
</style>
</head>
<body>
<div>thin</div>
</body>
</html>
The code above is rendered as follows:
The following css uses the pixel to define the border width.
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
p { <!-- w w w .ja va 2 s . c o m-->
border-width: 5px;
border-style: solid;
border-color: black;
}
</style>
</head>
<body>
<p>
HyperText Markup Language (HTML)
java 2s .com
</p>
</body>
</html>
The code above is rendered as follows:
The following css uses the percentage to define the border width
<!DOCTYPE HTML>
<html>
<head>
<style>
p { <!--from w w w .j a va 2 s . c o m-->
border-width: 50%;
border-style: solid;
border-color: black;
}
</style>
</head>
<body>
<p>
HyperText Markup Language (HTML)
</p>
</body>
</html>
The code above is rendered as follows:
The following code uses cm
to define the border width
<!DOCTYPE HTML>
<html>
<head>
<style>
p { <!-- w ww. jav a 2s .c om-->
border-width: 1cm;
border-style: solid;
border-color: black;
}
</style>
</head>
<body>
<p>
HyperText Markup Language (HTML)
</p>
</body>
</html>
The code above is rendered as follows:
The following code shows how to set Border width in one, two, three or four values.
<!DOCTYPE HTML>
<html>
<head>
<style rel='stylesheet' type='text/css'>
div {<!-- w w w. jav a2 s. c om-->
padding: 3px;
border-color: khaki;
border-style: solid;
background: lightyellow;
margin: 5px;
float: left;
width: 80px;
height: 80px;
}
div#one {
border-width: 8px;
}
div#two {
border-width: 2px 8px;
}
div#three {
border-width: 2px 8px 16px;
}
div#four {
border-width: 2px 8px 16px 32px;
}
</style>
</head>
<body>
<div id='one'>border-width: 8px;</div>
<div id='two'>border-width: 2px 4px;</div>
<div id='three'>border-width: 2px 4px 8px;</div>
<div id='four'>border-width: 2px 4px 8px 10px;</div>
</body>
</html>
The code above is rendered as follows:
The following code shows how to set Border Width to thin medium or thick.
<html>
<head>
<style rel='stylesheet' type='text/css'>
div {<!--from w w w. java 2 s. c o m-->
padding: 3px;
border-color: black;
border-style: solid;
background: mistyrose;
margin: 5px;
}
div#thin {
border-width: thin;
}
div#medium {
border-width: medium;
}
div#thick {
border-width: thick;
}
</style>
</head>
<body>
<div id='thin'>thin</div>
<div id='medium'>medium</div>
<div id='thick'>thick</div>
</body>
</html>
The code above is rendered as follows: