Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

border-top — top border

The CSS `border-top` shorthand sets the width, style, and color of the physical top border. Omitted components receive their initial values rather than retaining values from earlier declarations.

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

Syntax

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

border-top combines border-top-width, border-top-style, and border-top-color. It targets the physical top edge regardless of writing direction; it does not always mean the block-start edge. It is not inherited.

The || notation means one or more components may appear in any order, each at most once. Width can be a nonnegative length or one of the keywords thin, medium, or thick. The CSS Borders Level 4 draft also includes the hairline keyword in <line-width>, but that does not guarantee browser support. Percentages are not allowed. A complete declaration is border-top: 4px solid #000000.

Omitted components revert to their initial values: medium, none, and currentColor. Consequently, border-top: 4px replaces a previously assigned line style with none. In the CSS Borders Level 4 draft, the computed width is snapped to device pixels, so it can differ from 4px. The used width is zero because the style is none. To change only the width while preserving the other settings, use border-top-width.

Unlike border, this shorthand neither resets border-image nor sets the other three edges. The example omits image borders and displays an ordinary black line above a gray area.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>border-top</title>
<style>
  .box {
    width: 200px;
    height: 60px;
    background: #eeeeee;
    border-top: 4px solid #000000;
  }
</style>
<div class="box"></div>
</html>

Result

A 200px-wide, 60px-high light-gray content area with a 4px solid black top border; the border box is 200px wide and 64px high.

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