Border - CSS Property

This page is also about physical property(ies):
- border-bottom
Sets the parameters of the bottom border of the element (thickness, line style, color).
- border-left
Sets the three parameters of the left border of the element (thickness, line style, color).
- border-right
Sets the three parameters of the right border of the element (thickness, line style, color).
- border-top
Sets the parameters of the top border of the element (thickness, line style, color).
And the logical properties:
- border-block-end
Sets all the parameters of the border for the end side of the block.
- border-block-start
Sets all the parameters of the border on the start side of the block.
- border-inline-end
Sets all the parameters of the border strokes, for the end side of the lines.
- border-inline-start
Sets all the parameters of the border strokes, for the beginning side of the lines.
border
border-top
border-right
border-bottom
border-left

Summary of characteristics of the border property

Quick description
A shorthand property that defines the set of border parameters: width, style and color.
Status
Standard
Percentages
Not applicable.
Initial value
See individual properties.
Inherited by default
No.
See individual properties.
Per grammar: serialization in the order of syntax. {enter-free]
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.

border - Syntax DiagramSyntax diagram of the border CSS property, which is a shorthand property defining all the border parameters. thin thin medium medium thick thick length length none none hidden hidden solid solid double double dotted dotted dashed dashed groove groove ridge ridge inset inset outset outset color colorborder:;border:;
Syntax diagram of the border 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 numeric value followed by one of CSS dimension units.
  • color is a color expressed in any of the syntaxes recognized by CSS (see Colors).

Description of the border property.

A border is defined by three properties: thickness, line style, and line color. These settings can be applied globally to all four sides, or they can be customized individually for each side (top, right, bottom, and left). This explains the large number of border-related properties, but they are just combinations of the three basic parameters and the four sides.

The border property sets the three parameters (thickness, style, and color) for all four sides of the element. But the many shorthand properties are often useful. border also resets the border-image property.

Summary properties grouping the values of the three parameters for one of the sides:

border-top
Sets the parameters of the top border of the element (thickness, line style, color).
border-right
Sets the three parameters of the right border of the element (thickness, line style, color).
border-bottom
Sets the parameters of the bottom border of the element (thickness, line style, color).
border-left
Sets the three parameters of the left border of the element (thickness, line style, color).

Summary properties grouping the values of a parameter for all four sides:

border-width
Sets the thickness of the border line around the element.
border-style
Sets the line type for some or all four borders around the element (solid, double, dotted...).
border-color
Sets the border color for all four sides of the element.

Finally, the long hand properties, to set one of the parameters for one of the sides:

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

For more information on the possible values with border, refer to the properties border-width, border-style, and border-color.

Warning! The border defined by border can be hidden if an image border is defined afterward or with a higher priority (see border-image ).

Don't confuse borders and outlines. Refer to the description of the CSS property outline for a detailed presentation of the differences between borders and outlines.

Features of the short hand properties.

The fact that shorthand properties define all the values they involve, even if some aren't specified, can lead to surprising but explainable results. This behavior is common to all shorthand properties, not just those related to borders, but it's especially noticeable with borders because we mainly use shorthand properties for them.

border-color:red; border:2px solid;
The color set by border-color is reset by the property border that follows: even though the color isn't specified, it goes back to its initial value.
border:2px solid red; border-top:6px double;
This second example is even more surprising: the red color is reset by border-top, while the developer probably thought they were only changing the thickness and style of the line.

Language support.

The properties border-top, border-right, border-bottom, border-left, as well as their variations for each of the border parameters, can be replaced by their logical equivalent if you want the borders to adapt to the language of the text. The logical properties are as follows, along with their correspondence to the physical properties in the case of Latin languages:

Logical propertiesPhysical properties
equivalents for Latin
border-block-start-width
border-inline-end-width
border-block-end-width
border-inline-start-width
border-top-width
border-right-width
border-bottom-width
border-left-width
border-block-start-style
border-inline-end-style
border-block-end-style
border-inline-start-style
border-top-style
border-right-style
border-bottom-style
border-left-style
border-block-start-color
border-inline-end-color
border-block-end-color
border-inline-start-color
border-top-color
border-right-color
border-bottom-color
border-left-color
border-block-start
border-inline-end
border-block-end
border-inline-start>
border-top
border-right
border-bottom
border-left
border-block-width
border-inline-width
border-block-style
border-inline-style
border-block-color
border-inline-color

But most of the time, we'll just stick to the summarized properties that group the parameters for one of the edges. They are shown in the diagram below.

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

Values for border.

  • border: none;

    Default value. No border is drawn around the element. If an image border is set, it is also canceled.

  • border: solid;

    Minimal syntax: a border is drawn, with the default thickness (medium) and the default color (currentColor).

    To find out the different types of line styles, refer to the border-style property.

  • border: 2px solid green;

    Full syntax, describing the border's thickness, its type, and its color.

  • border: initial; border: inherit; border: revert; border: revert-layer; border: revert-rule; border: unset;

    These values ​​are described in more detail on their respective page: initial, inherit, revert, revert-layer, revert-rule, unset.

Examples with the border property.

Classic border: you just need to set its thickness and style (the color will be the same as the text)
A border with a 3D effect (ridge). For the 3D effect to show properly, make sure to have a sufficient thickness (usually 5 pixels), and a medium brightness color (gray in this case).
Dotted border on the vertical sides and dashed on the top and bottom sides.
Border with 3D effect (groove) and rounded corners (see border-radius). 3D borders are not easy to render with rounded corners: you can notice imperfections in the rounding at the top right and bottom left.
251814
8180
40027

Border on the left and right only, with rounded corners. Applied to a table, this border makes it easy to present a matrix just like it's usually shown in math.

Access the border property via a program

With Javascript, change the value of border.

In JavaScript, here's how to set a border. JavaScript accepts two syntaxes: the first with an array-like notation, the second with an object-like notation.

Javascript
let el = document.getElementById('id'); el.style['border'] = '1px solid blue'; // or let el = document.getElementById('id'); el.style.border = '1px solid blue';

With Javascript, read the value of border.

The property must have been applied directly to the element itself via its style attribute, not through a CSS selector.

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

With Javascript, read the computed value of border.

Refer to the individual properties to see how each of the values accepted by border is stored.

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

With JQuery, read or change the value of border.

JQuery offers the same possibilities as Javascript to read or write the value of border, with a more compact syntax.

JQuery

// Read the value:
$('#id').prop('border');
// Write the value:
$('#id').prop('border', '1px solid blue');
$('#id').prop('{border': '1px solid blue'});

With JQuery, read the computed value of border.

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

Other code example.

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

Test it yourself.

The buttons below apply the entered value to the border property and then show either the value as it was applied or the computed value. This second option lets you see how the value of border is stored (serialized). You’ll also notice that if you try to set an incorrect value (like a non-existent color, for example), all the values are ignored and the computed value is reset to the property's initial value.

Browsers compatibility with border.

No compatibility issues: borders have been properly handled by browsers for a long time.

Column 1
Correct handling by browsers of the shorthand property border, which defines all parameters of a border.
1
border
property
Estimated overall support.
96%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

KaiOS Browser

Opéra Mobile

Chrome

Edge

Opéra

Safari

Safari sur IOS

Androïd Brower

Chrome pour Androïd

Firefox pour Androïd

Samsung Internet

Firefox

Baidu Browser

QQ Browser

UC Browser pour Androïd

Opéra mini

Historic of the border property.

  • 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 Initial definition of border-related properties and the border shorthand property.
    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 No change to the properties defining the borders, 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 Introduction of logical properties to define borders. These properties depend on the writing mode of the language used.
    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 No change directly to border-related properties, but longhand properties now have a logical equivalent (supporting language-dependent writing mode).
    WD
    August 02, 2002
    Working Draft.
    CR
    December 17, 2009
    Candidate Recommendation.
    PR
    REC

See also, about the borders.

The descriptions of properties related to backgrounds and borders are gathered 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.