CSS border-top-color Property

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

What You’ll Learn

The border-top-color property sets the color of the border on the physical top side only.

01

Top Side

Physical color.

02

Longhand

Color only.

03

Color Formats

Hex, rgb, hsl.

04

currentcolor

Matches text.

05

Override

Recolor top only.

06

Classic CSS

Universal support.

Definition and Usage

The border-top-color CSS property sets the color of the border on the physical top side of an element. It is a longhand of border-top and works alongside border-top-width and border-top-style.

Unlike logical properties such as border-block-start-color, border-top-color 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

border-top-color only sets color. Pair it with a visible border width and style, or use border: 2px solid; plus this longhand to recolor only the top side.

📝 Syntax

border-top-color accepts any valid CSS color value:

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

Basic Example

border-top-color.css
div {
  border: 2px solid;
  border-top-color: red;
}

Syntax Rules

  • Accepts named colors, hex, rgb, hsl, currentcolor, and transparent.
  • Only affects the top border side; other sides keep their own colors.
  • You need a visible border width and style for the color to appear.
  • Always affects the physical top side, regardless of direction or writing-mode.
  • Default is currentcolor, matching the element’s text color.

⚡ Quick Reference

QuestionAnswer
Initial valuecurrentcolor
Applies toTop border color only
InheritedNo
AnimatableYes, as a color
Common useSection dividers, card accents, recoloring one side

Default Value

The default value of border-top-color is currentcolor. The top border uses the element’s text color unless you set a different color explicitly.

💎 Property Values

ValueExampleMeaning
Named colorborder-top-color: green;Uses a CSS color keyword on the top side
Hexborder-top-color: #2563eb;Hexadecimal color on the physical top side
HSLborder-top-color: hsl(142, 71%, 45%);HSL functional notation
currentcolorborder-top-color: currentcolor;Matches the element’s text color
transparentborder-top-color: transparent;Makes the top border invisible
green
#2563eb
hsl

Common Value Types

greennamed color
#2563ebhex value
currentcolormatches text

Top Border Color and Writing Modes

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

Horizontal (writing-mode: horizontal-tb)

Red top border on the top edge

Vertical (writing-mode: vertical-rl)

Top border color still on the physical top

border-top-color vs related properties

PropertyTargetsBest for
border-top-colorColor on the physical top side onlyTop accent bars, section dividers, recoloring one side
border-topWidth, style, and color on the top sideSetting the full top border in one rule
border-block-start-colorColor on the block-start side (writing-mode-aware)Header accents that follow vertical writing modes
border-top-styleStyle on the physical top side onlyChanging solid, dashed, or dotted on the top edge

👀 Live Preview

A box with a blue top border on a gray frame:

Blue border on the physical top edge.

Uses border: 3px solid #cbd5e1; and border-top-color: #2563eb;.

Examples Gallery

Try border-top-color with named colors, hex values, currentcolor, and vertical writing.

📚 Basic Top Border Colors

Color only the physical top border side.

Example 1 — Red Top Border Color

Change the top border color to red on a box with a visible border, matching the reference tutorial.

border-top-color-red.html
<style>
  div {
    border: 2px solid;
    border-top-color: red;
    padding: 10px;
  }
</style>

<div>
  This div has a red top border.
</div>
Try It Yourself

How It Works

The shorthand sets a border on all sides. border-top-color: red overrides only the top side color while other sides use the default border color.

Example 2 — Hex Color on the Top Side

Use a hex color for the top border while keeping other sides neutral gray.

border-top-color-hex.css
.card {
  border: 3px solid #cbd5e1;
  border-top-color: #2563eb;
  padding: 1rem;
  background: #eff6ff;
}
Try It Yourself

How It Works

All sides start with gray from the shorthand, then border-top-color recolors only the physical top edge to blue.

🎨 currentcolor and Vertical Writing

Match text color or see how top border color behaves in vertical writing.

Example 3 — currentcolor Keyword

Make the top border match the element’s text color.

border-top-color-current.css
.quote {
  color: #7c3aed;
  border: 3px solid #cbd5e1;
  border-top-color: currentcolor;
  padding: 0.75rem 1rem;
}
Try It Yourself

How It Works

currentcolor is the default value. Here it makes the top border purple to match the text while other sides stay gray.

Example 4 — border-top-color in Vertical Writing

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

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

<div class="vertical-box">
  Top border color 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-color instead.

🧠 How border-top-color Works

1

Border must be visible

A width and style on the top side create a border to color.

Setup
2

Color longhand applies

border-top-color sets the physical top edge color only.

Color
3

Other sides stay unchanged

Right, bottom, and left borders keep their own colors unless you override them.

Scope
=

Colored top border

Only the physical top edge shows your chosen color.

Modern Browser Support

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

Baseline · Modern browsers

Physical top border colors in every browser

Chrome, Edge, Firefox, Safari, and Opera have supported border-top-color 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-color property 99% supported

Bottom line: Use border-top-color for reliable top-side accent colors in any modern browser.

Conclusion

The border-top-color property controls the color of the physical top border. Use it for section dividers, card accent bars, and highlights where the border should stay on the top edge.

Pair it with border-top-width and border-top-style, or use the border-top shorthand when you want width, style, and color together.

💡 Best Practices

✅ Do

  • Set border width and style alongside color for visible top borders
  • Use currentcolor when the top border should match text
  • Use border-top-color for section headers, card accent bars, and horizontal dividers
  • Override one side after a border shorthand to recolor only the top
  • Use border-block-start-color when the accent must follow vertical writing modes

❌ Don’t

  • Set color alone without a visible border width and style
  • Expect border-top-color to move to the side in vertical writing modes
  • Mix conflicting physical and logical color rules on the same element
  • Use border-top-color when the design needs a block-start accent in vertical writing
  • Forget that the shorthand sets all sides before your longhand override

Key Takeaways

Knowledge Unlocked

Five things to remember about border-top-color

Use these points when coloring physical top borders.

5
Core concepts
02

currentcolor

Default.

Default
🔀03

red

Named color.

Values
🌐04

Fixed top

Not logical.

Physical
🛠05

Needs width

Color longhand.

Usage

❓ Frequently Asked Questions

The border-top-color property sets the color of the border on the physical top edge of an element only.
The initial value is currentcolor, which uses the element's text color for the top border.
border-top-color always targets the physical top edge, regardless of text direction or writing mode.
border-top-color only sets color. You also need a visible border width and style, or use a shorthand like border: 2px solid plus this longhand.
border-top-color is fixed to the physical top edge. border-block-start-color follows the writing mode, so in vertical writing it may appear on the side instead of the top.

Practice in the Live Editor

Open the HTML editor, try border-top-color, and preview top border colors 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