CSS propertyBox model

border

Shorthand that sets the width, style, and color of a border.

Initial value
medium none currentcolor
Inherited
No
Animatable
yes, width and color
Applies to
all elements
JavaScript
element.style.border = "2px solid #a78bfa"
On this page

Example

#
CSS
.input {
  border: 1px solid #525252;
  border-radius: 8px;
}

.input:focus {
  border-color: #a78bfa;
}
Preview

Definition and usage

#

The border property combines three properties: border-width, border-style, and border-color. You can list the values in any order, for example border: 2px solid #a78bfa.

The style matters most. Without it, no border appears, because the default style is none. If you skip the color, the border takes on the text color (currentcolor).

The shorthand sets all four edges at once. For a single edge, use border-top, border-right, border-bottom, and border-left, handy for things like underlines and separators.

Syntax

#
Syntax
border: <width> || <style> || <color>;

Values

#

Values in practice

#

1px solid #525252

A thin, solid, gray line. The most common choice for cards and fields.
.demo { border: 1px solid #525252; }

3px dashed #f59e0b

A thicker dashed line.
.demo { border: 3px dashed #f59e0b; }

6px double #a78bfa

A double line. It needs at least 3px of width to be visible.
.demo { border: 6px double #a78bfa; }

none

No border.
.demo { border: none; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • A border changes an element’s size. If it only appears on hover and causes a layout shift, set a fixed, transparent border up front.
  • For a border that doesn’t affect layout, use outline or box-shadow instead.

Related entries

#

Spotted a mistake or missing an example? Write to us.