Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

border — border shorthand

The border property sets the width, style, and color of all four borders. Omitted components return to their initial values, and border-image is reset as well.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

border: <line-width> || <line-style> || <color>;

border is a shorthand that sets the same border-width, border-style, and border-color on all four sides of a box. It is not inherited. Unlike margin, it does not accept four sets of values for successive sides.

The || notation means components can appear in any order; at least one is required. Width is a nonnegative length or thin, medium, or thick; percentages are not allowed. Example styles include solid, dashed, and dotted.

Omitted components receive their initial values: medium, none, and currentColor. Consequently, border: 2px red alone draws no line: the style remains none, and the used width is zero. currentColor means the color supplied by the element’s color property.

Beware of resets: border also restores the initial values of border-image, although it cannot specify an image. If you need a border image, declare border-image after border. For different sides, use side-specific properties or more specific declarations after the shorthand, such as border-left-width in the example.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Border example</title>
<style>
  .box {
    border: 2px solid #006699;
    border-left-width: 6px;
    padding: 8px;
  }
</style>
<div class="box">Border example</div>
</html>

Result

Border example — top/right/bottom: 2px solid #006699; left: 6px solid #006699.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources