border-top

The border-top shorthand CSS property sets all the properties of an element's top border.

Try it

As with all shorthand properties, border-top always sets the values of all of the properties that it can set, even if they are not specified. It sets those that are not specified to their default values. Consider the following code:

css
border-top-style: dotted;
border-top: thick green;

It is actually the same as this one:

css
border-top-style: dotted;
border-top: none thick green;

The value of border-top-style given before border-top is ignored. Since the default value of border-top-style is none, not specifying the border-style part results in no border.

Constituent properties

This property is a shorthand for the following CSS properties:

Syntax

css
border-top: 1px;
border-top: 2px dotted;
border-top: medium dashed green;

/* Global values */
border-top: inherit;
border-top: initial;
border-top: revert;
border-top: revert-layer;
border-top: unset;

The three values of the shorthand property can be specified in any order, and one or two of them may be omitted.

Values

Formal definition

Initial valueas each of the properties of the shorthand:
Applies toall elements. It also applies to ::first-letter.
Inheritedno
Computed valueas each of the properties of the shorthand:
Animation typeas each of the properties of the shorthand:

Formal syntax

border-top = 
<line-width> ||
<line-style> ||
<color>

<line-width> =
<length [0,∞]> |
thin |
medium |
thick

<line-style> =
none |
hidden |
dotted |
dashed |
solid |
double |
groove |
ridge |
inset |
outset

Examples

Applying a top border

HTML

html
<div>This box has a border on the top side.</div>

CSS

css
div {
  border-top: 4px dashed blue;
  background-color: gold;
  height: 100px;
  width: 100px;
  font-weight: bold;
  text-align: center;
}

Results

Specifications

Specification
CSS Backgrounds and Borders Module Level 3
# border-shorthands

Browser compatibility

BCD tables only load in the browser

See also