CSS border-top Property

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 4 Examples
Box Model & Borders

What You’ll Learn

The border-top property sets the width, style, and color of the physical top border in one shorthand rule.

01

Top Side

Physical edge.

02

Shorthand

Width, style, color.

03

solid

Common style.

04

Card Accents

Header bars and tabs.

05

Longhands

width, style, color.

06

Classic CSS

Universal support.

Definition and Usage

The border-top CSS property is a physical shorthand that sets the border on the top side of an element. It combines border-top-width, border-top-style, and border-top-color in one declaration.

Unlike logical properties such as border-block-start, border-top always targets the physical top edge — even in vertical writing modes. That makes it straightforward for section headers, card accent bars, and horizontal dividers.

💡
Beginner Tip

For layouts that must adapt to vertical writing modes, consider border-block-start instead of border-top so the accent bar follows the block-start edge.

📝 Syntax

border-top accepts border width, style, and color like other border shorthands:

syntax.css
selector {
  border-top: width style color;
}

Basic Example

border-top.css
.top-border {
  border-top: 5px solid blue;
}

Syntax Rules

  • Sets width, style, and color for the top border side only.
  • Omitted components use initial values: medium, none, currentcolor.
  • Any valid border width, style, and color values are accepted.
  • Always affects the physical top side, regardless of direction or writing-mode.
  • Use longhands when you need to set only width, style, or color on the top side.

⚡ Quick Reference

QuestionAnswer
Initial valuemedium none currentcolor
Applies toTop border side only
InheritedNo
AnimatablePartially (color and width)
Common useSection dividers, card accents, tab indicators

Default Value

The default value of border-top is medium none currentcolor. No visible border appears until you set a non-none style and a width greater than zero.

💎 Property Values

ComponentExampleMeaning
border-width4px, thin, 0.25remThickness of the top border
border-stylesolid, dashed, dottedHow the top border is drawn
border-colorred, #2563eb, currentcolorColor of the top border

Common Value Types

4px solidsolid top border
3px dasheddashed style
6px solidthick accent

Top Border and Writing Modes

border-top always draws on the physical top edge. Vertical writing modes do not move the border — compare with border-block-start when block-start should follow the writing mode.

Horizontal (writing-mode: horizontal-tb)

Top border on the top edge

Vertical (writing-mode: vertical-rl)

Top border still on the physical top

border-top vs related properties

PropertyTargetsBest for
border-topPhysical top side onlyTop accent bars and section dividers
border-block-startLogical block-start sideWriting-mode-aware header accents
border-bottomPhysical bottom side onlyFooter dividers and underlines
borderAll four sidesFull box outlines

👀 Live Preview

A box with a blue border on the top edge:

Blue border on the top edge.

Uses border-top: 4px solid #2563eb;.

Examples Gallery

Try border-top with solid blue borders, card accents, vertical writing comparison, and dashed styles.

📚 Basic Top Borders

Add a border on the physical top edge of an element.

Example 1 — 5px Solid Blue Top Border

Add a solid blue top border on a div, matching the reference tutorial.

border-top-basic.html
<style>
  .top-border {
    border-top: 5px solid blue;
    padding: 10px;
  }
</style>

<h1>Div with Top Border</h1>
<div class="top-border">
  This div has a blue top border that is 5 pixels thick.
</div>
Try It Yourself

How It Works

The shorthand sets width, style, and color on the top side only. Other sides keep their default borders unless you set them separately.

Example 2 — Card Top Accent

Use a top border as a colored accent bar on cards, panels, or callouts.

border-top-card.css
.card {
  max-width: 16rem;
  padding: 0.75rem 1rem;
  border-top: 4px solid #2563eb;
  background: #eff6ff;
  color: #334155;
}
Try It Yourself

How It Works

A top border creates a horizontal accent at the physical top edge. Pair it with padding so content sits below the line comfortably.

🎨 Writing Modes and Style Variations

See how border-top behaves in vertical writing and with different styles.

Example 3 — border-top in Vertical Writing

In vertical writing, border-top stays on the physical top — unlike border-block-start.

border-top-vertical.html
<style>
  .vertical-box {
    writing-mode: vertical-rl;
    display: inline-block;
    padding: 0.75rem 1rem;
    border-top: 4px solid #059669;
    background: #ecfdf5;
  }
</style>

<div class="vertical-box">
  Top border stays on the physical top
</div>
Try It Yourself

How It Works

Vertical writing changes text flow but not the physical top edge. For a block-start accent that follows the writing mode, use border-block-start instead.

Example 4 — Dashed Top Border

Use a dashed style for a lighter horizontal divider at the top.

border-top-dashed.css
.note {
  padding: 0.75rem 1rem;
  border-top: 3px dashed #7c3aed;
  background: #faf5ff;
}
Try It Yourself

How It Works

Any valid border style works on the top side. A dashed top border adds visual emphasis without a full box outline.

🧠 How border-top Works

1

You set width, style, and color

The shorthand combines all three border components for the top side in one rule.

Shorthand
2

Browser draws the top edge

border-top applies only to the physical top side of the element box.

Apply
3

Other sides stay unchanged

Right, bottom, and left borders keep their own values unless you set them separately.

Scope
=

Top border applied

Your element shows a styled border on the physical top edge.

Modern Browser Support

The border-top property is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera.

Baseline · Modern browsers

Physical top borders in every browser

Chrome, Edge, Firefox, Safari, and Opera have supported border-top since the earliest CSS versions.

99% Modern browser support
Google Chrome87+ · Desktop & Mobile
Full support
Mozilla Firefox66+ · Desktop & Mobile
Full support
Apple Safari14.1+ · macOS & iOS
Full support
Microsoft Edge87+ · All versions
Full support
Opera73+ · Modern versions
Full support
border-top property 99% supported

Bottom line: border-top is one of the most reliable CSS border properties across all browsers.

Conclusion

The border-top property controls the border on the physical top edge. Use it for section dividers, card accent bars, and tab indicators in horizontal layouts.

Combine width, style, and color in one shorthand, or use border-top-width, border-top-style, and border-top-color when you need finer control.

💡 Best Practices

✅ Do

  • Use top borders for section dividers and card accent bars
  • Pair with padding so content does not touch the border
  • Use border-block-start instead when vertical writing mode support is required
  • Combine width, style, and color in one shorthand when all three are needed
  • Use longhands when only one component needs to change

❌ Don’t

  • Expect border-top to move to the side in vertical writing modes
  • Mix conflicting physical and logical border rules on the same element
  • Use border-top for block-start accents when writing-mode-aware borders are needed
  • Forget a visible style — width alone may not show a border
  • Hard-code top borders when a logical property would be clearer

Key Takeaways

Knowledge Unlocked

Five things to remember about border-top

Use these points when styling physical top borders.

5
Core concepts
02

Default none

No border.

Default
🔀03

5px solid blue

Reference pattern.

Values
🌐04

Fixed top

Not logical.

Physical
🛠05

Card accents

Real use case.

Usage

❓ Frequently Asked Questions

The border-top property is a shorthand that sets the width, style, and color of the physical top border of an element in one declaration.
The initial value is medium none currentcolor, which means no visible border unless you set width, style, or color explicitly.
border-top always targets the physical top edge of an element, regardless of text direction or writing mode.
border-top is fixed to the physical top edge. border-block-start follows the writing mode, so in vertical writing it may appear on the side instead of the top.
Use it for section dividers, card accent bars, tab indicators, and header underlines where the border should stay on the physical top edge.

Practice in the Live Editor

Open the HTML editor, try border-top, and preview top border styles instantly.

HTML Editor →

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.

5 people found this page helpful