CSS border-top Property

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The border-top property is a shorthand that sets border-top-width, border-top-style, and border-top-color on the physical top edge only.

A border appears only when the style is not none. Width defaults to medium and color to currentColor when omitted. For every side at once, use border. For a logical start edge that follows writing mode, use border-block-start.

Baseline · Widely available.

Not deprecated and not experimental. The border-top shorthand has been supported across browsers since the early days of CSS.

CSS Syntax

syntax.css
border-top: <line-width> || <line-style> || <color> | initial | inherit;

Write one to three values, in any order. The usual order is width, style, then color: border-top: 3px solid black;.

Property Values

ValueDescriptionTry it
<line-width>Thickness: a length, or thin, medium, thick. Default mediumTry it
solidA continuous top line. Most common styleTry it
dashedA series of short dashes on the top edgeTry it
dottedA series of dots on the top edgeTry it
doubleTwo parallel top lines. Needs enough width to show bothTry it
<color>Top border color. Default is currentColorTry it
noneNo top border. Initial style. Width and color alone will not showTry it
initialResets to the initial top border (style none)Try it
inheritInherits this property from the parent elementTry it

How to Use border-top

Pick a style first so the top line is visible, then set width and color as needed.

  1. Choose the element that needs a line on its physical top edge.
  2. Set a style such as solid, dashed, or dotted. Without a style, nothing draws.
  3. Add a width and color when you want them. Omit them to use medium and currentColor.
  4. Leave the other sides alone — border-top does not change right, bottom, or left.
PieceRequired?Role
StyleYes (to show a line)Without it, the top border stays none and invisible
WidthOptionalDefaults to medium if omitted
ColorOptionalDefaults to currentColor if omitted
Top edge onlyBy designOther sides keep whatever they already have

Live Preview

Change the border-top shorthand and watch only the top edge update.

Style is required. Width and color are optional parts of the same shorthand.

Top edge

border-top: 3px solid #0f172a

CSS Examples

Each snippet focuses on the border-top shorthand. Use Try It Yourself for a live editor.

Example 1 — Solid Top Border

Set width, style, and color on the top edge in one declaration.

CSS
<style>
  div {
    border-top: 3px solid #0f172a;
    padding: 12px;
  }
</style>

<div>Solid top border</div>
Try It Yourself

How It Works

  1. Target the top edge. border-top never paints right, bottom, or left by itself.
  2. Set the style. solid draws a continuous line. Without a style, nothing appears.
  3. Set the width. 3px is the thickness of that top line.
  4. Set the color. #0f172a paints the stroke. All three values share one shorthand.

Example 2 — Dashed Top Border

Use a dashed style with a clear color for a soft divider.

CSS
<style>
  div {
    border-top: 3px dashed #2563eb;
    padding: 12px;
  }
</style>

<div>Dashed top border</div>
Try It Yourself

How It Works

  1. Keep the same shorthand shape. Width, style, and color still share one property.
  2. Swap the style. dashed replaces the solid line with short gaps.
  3. Color the dashes. Blue applies only to the top edge.
  4. Other sides stay untouched. Right, bottom, and left keep their previous borders (or none).

Example 3 — Double Top Border

Draw two parallel lines on the top. Give the border enough width so both show.

CSS
<style>
  div {
    border-top: 6px double #0f766e;
    padding: 12px;
  }
</style>

<div>Double top border</div>
Try It Yourself

How It Works

  1. Choose double. The browser draws two lines with a gap between them.
  2. Give it room. 6px is wide enough for both lines and the space between.
  3. Set the color. Teal fills both top lines.
  4. Still top-only. The shorthand applies the effect to the physical top edge alone.

Edge Cases & Pitfalls

If the top border disappears or looks wrong, check these first.

style

No style means no top border

border-top: 3px #000 still looks empty because style defaults to none. Always include solid or another style keyword.

reset

The shorthand resets omitted parts

Writing border-top: thick green after border-top-style: dotted resets style to none. Include the style in the shorthand, or set longhands after it.

logical

Physical top is not always “start”

border-top stays on the screen’s top edge. In vertical writing modes, use border-block-start when the line should follow the block-start side instead.

size

Borders add to the box by default

With the default content-box sizing, a top border grows the element’s outer height. Use box-sizing: border-box to keep height inclusive of the border.

sides

Need every side the same?

Use border instead. Reach for border-top when only the top edge should change.

Browser Support

border-top is a browser CSS property for the box model. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

border-top

Supported in all modern browsers and Internet Explorer. The side shorthand has been part of CSS since the earliest versions.

100% Universal support
Google Chrome All versions
Full support
Mozilla Firefox All versions
Full support
Apple Safari All versions
Full support
Microsoft Edge All versions
Full support
Opera All versions
Full support
Samsung Internet All versions
Full support
Internet Explorer All versions
Full support
border-top Widely supported

Bottom line: Safe everywhere for top-edge width, style, and color. Prefer the shorthand when the top side is the only edge you need. It is not a runtime API.

Key Takeaways

  • Role: one shorthand for width, style, and color on the physical top edge.
  • Style required: initial style is none. Width or color alone will not draw.
  • Physical edge: always the screen top — not writing-mode aware like border-block-start.
  • Shorthand reset: omitted parts fall back to defaults, including style none.

One line: use border-top when only the top edge needs a border — and always include a style keyword.

Frequently Asked Questions

It is a shorthand that sets border-top-width, border-top-style, and border-top-color on the physical top edge in one declaration.
A visible style is required. The initial style is none, so width or color alone will not draw a line. Use solid, dashed, dotted, or another style.
You can write width, style, and color in any order. The common pattern is width then style then color, for example border-top: 3px solid black.
border-top always targets the physical top edge. border-block-start follows writing-mode, so in vertical text it may map to a side instead of the top.
Yes. Like other border shorthands, omitted parts reset to their defaults. If you omit style, it becomes none and the border disappears.
It is Baseline Widely available and works in all modern browsers and Internet Explorer. It is a browser CSS property, not a Node.js feature.

Next: border-top-color

Set only the color of the physical top border.

border-top-color tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful