border-width
Quick Summary for border-width
Code Usage for border-width
/* Keyword values */ border-width: thin; border-width: medium; border-width: thick; /* <length> values */ border-width: 4px; border-width: 1.2rem; /* vertical | horizontal */ border-width: 2px 1.5em; /* top | horizontal | bottom */ border-width: 1px 2em 1.5cm; /* top | right | bottom | left */ border-width: 1px 2em 0 4rem; /* Global keywords */ border-width: inherit; border-width: initial; border-width: revert; border-width: unset;
More Details for border-width
border-width
The border-width
shorthand CSS property sets the width of an element's border.
Constituent properties
This property is a shorthand for the following CSS properties:
border-bottom-width
border-left-width
border-right-width
border-top-width
Syntax
/* Keyword values */ border-width: thin; border-width: medium; border-width: thick; /* <length> values */ border-width: 4px; border-width: 1.2rem; /* vertical | horizontal */ border-width: 2px 1.5em; /* top | horizontal | bottom */ border-width: 1px 2em 1.5cm; /* top | right | bottom | left */ border-width: 1px 2em 0 4rem; /* Global keywords */ border-width: inherit; border-width: initial; border-width: revert; border-width: unset;
The border-width
property may be specified using one, two, three, or four values.
Values
<line-width>
Defines the width of the border, either as an explicit nonnegative <length>
or a keyword. If it's a keyword, it must be one of the following values:
thin
medium
thick
Note: Because the specification doesn't define the exact thickness denoted by each keyword, the precise result when using one of them is implementation-specific. Nevertheless, they always follow the pattern thin ≤ medium ≤ thick
, and the values are constant within a single document.
Formal definition
Initial value | as each of the properties of the shorthand:border-top-width : medium border-right-width : medium border-bottom-width : medium border-left-width : medium |
---|---|
Applies to | all elements. It also applies to ::first-letter . |
Inherited | no |
Computed value | as each of the properties of the shorthand:border-bottom-width : the absolute length or 0 if border-bottom-style is none or hidden border-left-width : the absolute length or 0 if border-left-style is none or hidden border-right-width : the absolute length or 0 if border-right-style is none or hidden border-top-width : the absolute length or 0 if border-top-style is none or hidden |
Animation type | as each of the properties of the shorthand:border-bottom-width : a lengthborder-left-width : a lengthborder-right-width : a lengthborder-top-width : a length |
Formal syntax
<line-width>{1,4}where
<line-width> = <length> | thin | medium | thick
Examples
A mix of values and lengths
HTML<p id="sval"> one value: 6px wide border on all 4 sides</p> <p id="bival"> two different values: 2px wide top and bottom border, 10px wide right and left border</p> <p id="treval"> three different values: 0.3em top, 9px bottom, and zero width right and left</p> <p id="fourval"> four different values: "thin" top, "medium" right, "thick" bottom, and 1em left</p>
CSS #sval { border: ridge #ccc; border-width: 6px; } #bival { border: solid red; border-width: 2px 10px; } #treval { border: dotted orange; border-width: 0.3em 0 9px; } #fourval { border: solid lightgreen; border-width: thin medium thick 1em; } p { width: auto; margin: 0.25em; padding: 0.25em; }
ResultSpecifications
Specification |
---|
CSS Backgrounds and Borders Module Level 4 # the-border-width |
See also
The border-related shorthand properties:border
, border-style
, border-color
The border-width-related properties: border-bottom-width
, border-left-width
, border-right-width
, border-top-width
Select your preferred language English (US)DeutschEspañolFrançais日本語한국어PolskiРусский中文 (简体) Change language
Posted in
12:22 am, February 22, 2022
Add Comment
Other Items in CSS
rgb()
rgba()
:right
right
@right-bottom
:root
rotate
rotate()
rotate3d()
rotateX()
rotateY()
rotateZ()
row-gap
ruby-align
ruby-position
saturate()
scale
scale()
scale3d()
scaleX()
scaleY()
scaleZ()
:scope
scroll-behavior
scroll-margin
scroll-margin-block
scroll-margin-block-end
scroll-margin-block-start
scroll-margin-bottom
scroll-margin-inline
scroll-margin-inline-end
scroll-margin-inline-start
scroll-margin-left
scroll-margin-right
scroll-margin-top
scroll-padding
scroll-padding-block
scroll-padding-block-end
scroll-padding-block-start
scroll-padding-bottom
scroll-padding-inline
scroll-padding-inline-end
scroll-padding-inline-start
scroll-padding-left
scroll-padding-right
scroll-padding-top
scroll-snap-align
scroll-snap-stop
scroll-snap-type
@scroll-timeline