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.
.card { border-top: 4px solid #7c3aed; }
Try it
The list uses li + li so the divider appears between items, not above the first one.
Syntax
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
bordershorthand. - Order of rules matters. Put
borderfirst, thenborder-topto override one side. Ifbordercomes 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: 0orborder-top: noneremoves the top border; resetting withnoneis the usual way to undo an inherited rule. - Logical alternative. In vertical writing modes the "top" is not the block start.
border-block-startfollows the writing mode and is the better choice for internationalized layouts. - Rounded corners. A thick top border on a box with
border-radiuscurves 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.
Related
borderโ all four sidesborder-right,border-bottom,border-leftborder-blockโ logical block-axis bordersborder-radiusโ rounded corners- Lessons: Borders, The Box Model