CSS border-top-color Property

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

Definition and Usage

The border-top-color property sets the color of an element’s physical top border. It does not set width or style. You can also set this color with border-top or border-color.

The initial value is currentColor, so the top border matches the element’s text color until you override it. A visible border-top-style and non-zero border-top-width are still required for the color to show.

Baseline · Widely available.

Not deprecated. Standard <color> values are safe everywhere. Newer striped / <image-1D> border colors from CSS Borders Level 4 are not covered here and are not Baseline yet.

CSS Syntax

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

Accepts any CSS color: named colors, hex, rgb(), hsl(), currentColor, or transparent.

Property Values

ValueDescriptionTry it
<color>Any color: named, hex, rgb(), hsl(), and moreTry it
currentColorUses the element’s computed text color. This is the initial valueTry it
transparentFully transparent top border. Width still takes space if style is visibleTry it
initialResets to the initial value, currentColorTry it
inheritTakes the value from the parent elementTry it

How to Use border-top-color

Make sure a top border exists, then paint only its color.

  1. Give the element a top border with a visible style and width (or use border-top).
  2. Set border-top-color to any CSS color.
  3. Leave other sides alone — this property never colors right, bottom, or left.
  4. Prefer the longhand when width and style are already set and you only need to change the color.
PieceRequired?Role
Visible styleYesWithout solid (or similar), no border draws
WidthYes (non-zero)Zero width hides the colored line
ColorThis propertyDefaults to currentColor if unset
Top edge onlyBy designOther sides keep their own colors

Live Preview

Width and style stay fixed. Change only border-top-color and watch the top edge repaint.

The top border is already 3px solid. Only the color keyword changes.

Top edge

border-top-color: #0f172a

CSS Examples

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

Example 1 — Hex Top Color

Paint the top border with a hex color after width and style are set.

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

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

How It Works

  1. Create the top line. Width and style make a visible border on the top edge.
  2. Set only the color. border-top-color: #2563eb paints that line blue.
  3. Leave other sides alone. Right, bottom, and left keep whatever colors they already have.
  4. Same result with a shorthand. border-top: 3px solid #2563eb would set all three parts at once.

Example 2 — Match the Text Color

Use currentColor so the top border follows the element’s text color.

CSS
<style>
  div {
    color: #7c3aed;
    border-top-width: 3px;
    border-top-style: solid;
    border-top-color: currentColor;
    padding: 12px;
  }
</style>

<div>Matches text color</div>
Try It Yourself

How It Works

  1. Set the text color. color: #7c3aed is the source for currentColor.
  2. Keep a visible top border. Width and style still draw the line.
  3. Link the border to the text. currentColor copies that purple into the top border.
  4. Change one value later. Updating color updates the border too, without editing border-top-color again.

Example 3 — Transparent Top Color

Keep the top border’s space, but make the stroke invisible.

CSS
<style>
  div {
    border-top-width: 3px;
    border-top-style: solid;
    border-top-color: transparent;
    padding: 12px;
    background: #f1f5f9;
  }
</style>

<div>Invisible top stroke</div>
Try It Yourself

How It Works

  1. Keep width and style. The top border still exists in the box model.
  2. Set color to transparent. The stroke does not paint, so you do not see a line.
  3. Space remains. Unlike border-top-style: none, a transparent colored border can still reserve its width.
  4. Useful for alignment. Pair with other sides that stay opaque when you need matching padding without a visible top line.

Edge Cases & Pitfalls

If the top color seems missing, one of these is usually why.

style

Color alone never draws a border

You need a visible border-top-style and a non-zero width. Without them, border-top-color has nothing to paint.

shorthand

border-top can overwrite your color

A later border-top shorthand resets omitted parts, including color (back toward currentColor). Set the longhand after the shorthand if both are needed.

logical

Physical top is not always block-start

In vertical writing modes, use border-block-start-color when the colored edge should follow the logical start side instead of the screen top.

default

Unset means currentColor

If you never set a top color, the border uses the element’s text color. That can look like a bug when you change text color and the border follows.

sides

Need every side the same color?

Use border-color. Reach for border-top-color when only the top edge should differ.

Browser Support

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

✓ Baseline · Widely available

border-top-color

Supported in all modern browsers and Internet Explorer. Standard color values have 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-color Widely supported

Bottom line: Safe everywhere for standard <color> values. Prefer the longhand when you only need to change the top color. It is not a runtime API.

Key Takeaways

  • Role: set the color of the physical top border only.
  • Needs a line first: visible style + width, then color.
  • Initial value: currentColor. Not inherited by default.
  • Shorthands: border-top and border-color can set the same color.

One line: use border-top-color when the top edge already has a border and you only need to change its paint.

Frequently Asked Questions

It sets the color of the border on the physical top edge only. It does not set width or style.
The initial value is currentColor, which uses the element's computed text color for the top border.
Color alone is not enough. You also need a visible border-top-style (such as solid) and a non-zero border-top-width, or use the border-top shorthand.
border-top-color always paints the physical top edge. border-block-start-color follows writing-mode, so in vertical text it may map to a side instead of the top.
Yes. border-top and border-color can set the top color. Use border-top-color when you want to change only the color after width and style are already set.
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-left-radius

Round the physical top-left corner of the box.

border-top-left-radius 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