border-width, CSS property

This page is also about physical property(ies):
- border-bottom-width
Sets the thickness of the border line located below the element.
- border-left-width
Sets the thickness of the border on the left side of the element.
- border-right-width
Sets the thickness of the border on the right side of the element.
- border-top-width
Sets the thickness of the border line above the element.
And the logical properties:
- border-block-end-width
Sets the border thickness on the end side of the blocks.
- border-block-start-width
Sets the border thickness on the end side of the blocks.
- border-block-width
Sets the border thickness on the start and the end side of the blocks.
- border-inline-end-width
Sets the thickness of the border strokes, for the end side of the lines.
- border-inline-start-width
Sets the thickness of the border strokes, for the beginning side of the lines.
- border-inline-width
Sets the thickness of the border strokes, for the beginning and end sides of the lines.
border-width

Summary of characteristics of the border-width property

Quick description
Sets the thickness of the border line around the element.
Status
Standard
Predefined values
medium | thick | thin
Percentages
Not applicable.
Initial value
medium
Inherited by default
No.
Computed value: during an animation, the border-width property gradually changes from one value to another.
Per grammar: serialization in the order of syntax.
W3C Module
CSS Backgrounds and Borders Module
 🡇  
 🡅  
Document status: CR (Candidate Recommendation)

Document status: WD (Working Draft)

Document status: REC (Recommendation)

Document status: DEPR (Old specification, declared obsolete or superseded)

Syntax diagram of border-width.

border-width - Syntax DiagramSyntax diagram of the border-width CSS property. See stylescss.free.fr for details. thin thin medium medium thick thick length length {1,4} {1,4}border-width:;border-width:;
Syntax diagram of the border-width property.
The links in the diagram provide more details about the values.
Download the diagram in SVG.

In the diagram, the bold terms are the predefined words of CSS, the other terms are described below:

  • length is a positive or zero numeric value, followed by one of CSS dimension units.
  • From one to four values can be listed, separated by a space.

Description of the border-width property.

border-widthsets the thickness of an element's borders. It's a shorthand property in the sense that it sets the thickness of all four borders in one go. But there are also specific properties for each of the borders:

border-top-width
Sets the thickness of the border line above the element.
border-right-width
Sets the thickness of the border on the right side of the element.
border-bottom-width
Sets the thickness of the border line located below the element.
border-left-width
Sets the thickness of the border on the left side of the element.

To make the borders visible, also remember to set the border-style property. This leads to a little quirk: the initial value of border-width is indeed medium (about 3 pixels), but if border-style isn't set, the element has no border and its border thickness is counted as 0. This is shown in the example below: border-width isn't set on either the left or right example, but the border only appears on the second example because border-style is only set on that second element.

The border style is not set:
no border, so thickness = 0.
LThe border style is set.
The initial thickness is medium

Also note that some line styles (double, embossed effects) need a minimum thickness of 2 or 3 pixels to display properly.

Language support.

Logical properties take into account the meaning and writing direction, with the following equivalences for Latin languages:

border-top-width
⇒ Sets the thickness of the border line above the element.
border-right-width
⇒ Sets the thickness of the border on the right side of the element.
border-bottom-width
⇒ Sets the thickness of the border line located below the element.
border-left-width
⇒ Sets the thickness of the border on the left side of the element.

For non-Latin languages, refer to the interactive diagram below:

border-top-width
border-left-width
The direction and writing mode of this text adapt to the chosen language.
border-right-width
border-bottom-width

You need to add the following shorthand properties, each of which accepts two values: border-block-width and border-inline-width. They let you set the values for start and end in a single line.

Values for border-width.

  • border-width: 5px 1px 2px 2px;

    This is the general syntax of border-width: from one to four values separated by spaces. The assignment rules are as follows, depending on the number of values provided:

    border-width with a single value
    Une seule valeur
    border-width with two values
    Two values
    border-width with three values
    Three values
    border-width with four values
    Four values
    border-width:5px 1px;
  • border-width: medium;

    Default value. Medium thickness (generally around 3 pixels).

    border-width:medium;
  • border-width: thin;

    Thin thickness (usually around 1 pixel).

    border-width:thin;
  • border-width: thick;

    Thick width (generally around 5 pixels).

    border-width:thick;
  • border-width: initial; (medium) border-width: inherit; border-width: revert; border-width: revert-layer; border-width: revert-rule; border-width: unset;

    Common values ​​are presented on these pages: initial, inherit, revert, revert-layer, revert-rule, unset.

Examples with the border-width property.

Special effect achieved with a border thickness that is different on the top

Animation of the border-width property.

The animation of the border-width property poses no problem and is very smooth.

Note that the border grows inward, meaning the dimensions of the element don’t change. The system behaves this way because the box-sizing property has been set to border-box.

Access the border-width property via a program

Change the border thickness in JavaScript.

Two variants of JavaScript code can work: with the property name written in kebab-case, typical of CSS (a dash to separate words), or in camel-case notation, more common in JavaScript (a capital letter to separate words).

Javascript
let el = document.getElementById('id'); el.style['border-width'] = '1mm'; // or let el = document.getElementById('id'); el.style.borderWidth = '1mm';

Read the border thickness in JavaScript.

The following code example retrieves the value of border-width if it has been set directly on the element itself, via its HTML style attribute, and not in the style sheet through a CSS selector.

Javascript
let el = document.getElementById('id'); let value = el.style['border-width']; // or let el = document.getElementById('id'); let value = el.style.borderWidth;

Read the computed value of border-width in Javascript.

The computed value is the one that comes from evaluating the relative units (especially the percentage) and resolving the inheritance cascade. If this logic doesn't give any value, the computed value will be the initial value of the property (medium in the case of border-width).

The thickness is always returned in pixels, even if it was set using another unit, or with one of the keywords thin, thick, or medium.

Javascript
let el = document.getElementById('id'); let value = window.getComputedStyle(el).getPropertyValue('border-width');

With JQuery, read or change the value of border-width.

JQuery

// Read the value:
$('#id').prop('border-width');
// Write the value:
$('#id').prop('border-width', '1mm');
$('#id').prop('{border-width': '1mm'});

Read the computed value of the property border-width with JQuery.

Just like in JavaScript, the value is returned in pixels.

JQuery
let value = $('#id').css('border-width');

Other code examples.

Other examples of Javascript and JQuery code are given on the page Javascript and CSS.

Test it yourself.

The second button lets you see how the value of border-width is stored (serialized). All units are converted into pixels, with a quirk: if thickness is requested in a number of pixels, the result on the computed value won’t exactly match what was requested. It’s the same across all browsers. We haven’t found any information about this.

Simulator.

border-width :

Browsers compatibility with border-width.

As we can see in the compatibility table below, the property border-width doesn't cause any issues with current browsers, both for physical properties and logical properties.

Column 1
Support for physical properties to define border thickness: border-top-width, border-left-width, etc. Physical properties do not take into account the characteristics of the language (direction an writing mode).
Column 2
Support for logical properties to define border thickness: border-block-start-style, border-inline-end-style, etc. These properties adapt to the writing mode of the language.
1
border-width
(physical properties)
2
border-width
(logical properties)
Estimated overall support.
96%
96%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

KaiOS Browser

Opéra Mobile

Opéra

Firefox pour Androïd

Samsung Internet

Chrome

Edge

Firefox

Androïd Brower

Chrome pour Androïd

Baidu Browser

QQ Browser

Safari

Safari sur IOS

UC Browser pour Androïd

Opéra mini

Historic of the border-width property.

The shorthand property border-width and the corresponding detailed properties haven't changed across the different versions of CSS.

  • Cascading Style Sheets specification - Version 1

    This first level of the CSS specification describes the mechanism of cascading style sheets. Authors and readers can add styles to documents. Mainly intended for formatting HTML documents, CSS allows defining colors, fonts, text formatting, spacing (margins), etc. The CSS language is easy to understand, readable, and easy to write; it uses common terms from desktop publishing.

    Regarding border-width Initial definition of the border-width shorthand property and detailed properties for each edge.
    WD
    November 17, 1995
    Working Draft.
    PR
    November 12, 1996
    Proposed for recommendation.
    REC
    December 17, 1996
    Recommendation .
    DEPR
    September 13, 2018
    Old specification, declared obsolete.
  • Cascading Style Sheets Level 2 - Revision 1 Specification

    This level 2 of the specification describes the mechanism of cascading styles in CSS. This language is used to format HTML or XML documents. It supports media-specific style sheets so that authors can adapt the presentation of their documents for visual browsers, auditory devices, printers, braille devices, portable devices, etc.

    Regarding border-width No change to the border-width... properties except that they accept the inherit value.
    WD
    November 04, 1997
    Working Draft.
    PR
    March 24, 1998
    Proposed for recommendation.
    REC
    May 11, 1998
    Recommendation .
  • CSS Logical Properties and Values Level 1

    This specification module defines properties that indirectly define certain other properties depending on the writing mode: left to right, right to left, or top to bottom. They are useful in simple and generic style sheets, such as browser style sheets, but can also save a few lines of styles for documents containing both left-to-right and right-to-left text.

    Regarding border-width Introducing logical properties (supporting language-dependent writing mode) for setting border thicknesses.
    WD
    May 18, 2017
    Working Draft.
    CR
    PR
    REC
  • CSS Backgrounds and Borders Module Level 3

    Level 3 of the specification also explains how to position the background relative to the background area, and how to crop it.
    Regarding borders, the concept of image borders is introduced, as well as the ideas of rounded corners and box shadows.

    Regarding border-width No change to border-width... properties.
    WD
    August 02, 2002
    Working Draft.
    CR
    December 17, 2009
    Candidate Recommendation.
    PR
    REC

See also, about the borders.

The properties related to backgrounds and borders are described in the W3C specification "CSS Backgrounds and Borders Module".

Properties:

background
Summary of background properties.
background-attachment
Background image scrolling mode.
background-clip
Defines the extent of the background, especially in relation to the border and padding.
background-color
Sets the background color.
background-image
Defines the background image or gradient (multiple images or gradients can coexist).
background-origin
Defines a reference to position the background image.
background-position
Defines how the background image is positioned.
background-position-block
Sets the background positioning in the block direction.
background-position-inline
Sets the background positioning along the lines.
background-position-x
Sets how the background image is positioned horizontally.
background-position-y
Defines how the background image is positioned in the vertical direction.
background-repeat
Defines how the background image is repeated.
background-size
Sizing the background image.
border
A shorthand property that defines the set of border parameters: width, style and color.
border-bottom
Sets the parameters of the bottom border of the element (thickness, line style, color).
border-bottom-color
Sets the border line color for the bottom of the element.
border-bottom-left-radius
Sets the radius of the rounded corner at the bottom left.
border-bottom-right-radius
Sets the radius of the rounded corner in the lower right.
border-bottom-style
Sets the line style for the border below the element.
Border-bottom-width
Sets the thickness of the border line located below the element.
border-color
Sets the border color for all four sides of the element.
border-end-end-radius
Sets the radius of the corner rounding at the end of line and end of block.
border-end-start-radius
Sets the radius of the corner rounding at the end of line and beginning of the block.
border-image
Langue française
Shorthand of border properties made with images.
border-image-outset
Langue française
Sets the overflow of the border image.
border-image-repeat
Langue française
Defines how the border image is repeated or expanded to cover the desired area.
border-image-slice
Langue française
Defines how the border image is clipped.
border-image-source
Sets the path and file name for the image used to build the border.
border-image-width
Langue française
Sets the thickness of the border when the border is made with an image.
border-left
Sets the three parameters of the left border of the element (thickness, line style, color).
border-left-color
Sets the color of the left border line of the element.
border-left-style
Sets the border style for the left side of the element.
Border-left-width
Sets the thickness of the border on the left side of the element.
border-radius
Radius of rounded corners.
border-right
Sets the three parameters of the right border of the element (thickness, line style, color).
border-right-color
Sets the color of the border line on the right side of the element.
border-right-style
Sets the line style for the right border of the element.
Border-right-width
Sets the thickness of the border on the right side of the element.
border-start-end-radius
Sets the radius of the corner rounding at the beginning of the line and the end of the block.
border-start-start-radius
Sets the radius of the corner rounding at the beginning of the line and the beginning of the block.
border-style
Sets the line type for some or all four borders around the element (solid, double, dotted...).
border-top
Sets the parameters of the top border of the element (thickness, line style, color).
border-top-color
Sets the color of the border line above the element.
border-top-left-radius
Sets the radius of the rounded corner at the top left.
border-top-right-radius
Sets the radius of the rounded corner in the upper-right.
border-top-style
Sets the line style for the left border of the element.
Border-top-width
Sets the thickness of the border line above the element.
Border-width
Sets the thickness of the border line around the element.
box-shadow
Applies a shading effect to the frames by indicating all the parameters: color, shadow shift, blur, etc.