Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Borders, Outlines and Shadows

The border-top property

Reference for the CSS border-top shorthand: set the width, style and color of only the top border, with examples, defaults and logical alternatives.

The border-top property is a shorthand that sets the width, style and color of an element's top border only. It is the single-side version of border. Its longhands are border-top-width, border-top-style and border-top-color.

Top borders are handy as dividers between stacked items and as colored accent bars across the top of cards.

CSS
.card {
  border-top: 4px solid #7c3aed;
}

Try it

Accent bars and dividers

The list uses li + li so the divider appears between items, not above the first one.

Syntax

CSS
border-top: <line-width> || <line-style> || <color>
  • Initial value: medium none currentcolor
  • Applies to: all elements
  • Inherited: no
  • Animatable: yes (width and color; style is discrete)
  • Computed value: see the longhands

Values

Value Description
<line-width> A length or thin, medium, thick. See border-width.
<line-style> solid, dashed, dotted, double, groove, ridge, inset, outset, none, hidden. See border-style.
<color> Any color value; omitted means currentcolor.

Usage notes

  • A style is required for anything to appear, just like the border shorthand.
  • Order of rules matters. Put border first, then border-top to override one side. If border comes later it overwrites the top border again.
  • Dividers. Use the sibling combinator (li + li) or :not(:first-child) so the first item does not get an extra line.
  • Zero-width removal. border-top: 0 or border-top: none removes the top border; resetting with none is the usual way to undo an inherited rule.
  • Logical alternative. In vertical writing modes the "top" is not the block start. border-block-start follows the writing mode and is the better choice for internationalized layouts.
  • Rounded corners. A thick top border on a box with border-radius curves into the side borders with a smooth taper, which gives a nice accent-tab look.
  • Layout. A top border adds to the element's height under content-box.

Browser support

Supported in every browser.