CSS border-top-color Property
The border-top-color property sets the color of an element's top border.
It accepts CSS color values, including named colors, hexadecimal notation, RGB, HSL, and currentcolor. The property changes only the color of the physical top border, leaving its width, style, and the other border colors unchanged.
For the color to be visible, the top border must have a nonzero width and a visible border style, such as solid, dashed, or dotted.
border-top-color Syntax
The border-top-color property accepts one valid CSS color value.
selector {
border-top-color: #1769aa;
}
The general syntax is:
selector {
border-top-color: <color>;
}
Named Color
.panel {
border-top-color: blue;
}
Hexadecimal Color
.panel {
border-top-color: #1769aa;
}
RGB Color
.panel {
border-top-color: rgb(23 105 170);
}
HSL Color
.panel {
border-top-color: hsl(207 76% 38%);
}
Transparent Color
.panel {
border-top-color: transparent;
}
Current Text Color
.panel {
border-top-color: currentcolor;
}
CSS-Wide Keywords
.inherited {
border-top-color: inherit;
}
.reset {
border-top-color: initial;
}
.unset {
border-top-color: unset;
}
.reverted {
border-top-color: revert;
}
.layer-reverted {
border-top-color: revert-layer;
}
Only one color value or one CSS-wide keyword is allowed in a declaration.
Property Values
The property accepts the CSS <color> data type and CSS-wide keywords.
| Value | Description |
|---|---|
| Named color | A predefined color name such as red, blue, or rebeccapurple. |
| Hexadecimal color | A color such as #1769aa or #1769aa80. |
rgb() |
Defines a color using red, green, and blue channels, optionally with alpha transparency. |
hsl() |
Defines a color using hue, saturation, and lightness, optionally with alpha transparency. |
hwb() |
Defines a color using hue, whiteness, and blackness. |
lab(), lch(), oklab(), oklch() |
Defines colors using perceptual color spaces. |
color() |
Defines a color in a specified color space. |
color-mix() |
Creates a color by mixing other colors. |
currentcolor |
Uses the element's computed color value. |
transparent |
Produces a fully transparent border color. |
inherit |
Inherits the computed top border color from the parent. |
initial |
Resets the color to currentcolor. |
unset |
Resets the color to currentcolor because the property is not inherited. |
revert |
Reverts the color according to cascade origin rules. |
revert-layer |
Reverts the color according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | currentcolor |
| Inherited | No |
| Applies to | Elements that support the border properties |
| Computed value | Computed color |
| Animation type | By computed value type (color) |
| Accepted values | One CSS color value |
| Property type | Longhand |
| Physical edge | Top |
Although the property itself is not inherited, its default currentcolor value follows the element's text color, which is normally inherited.
How It Works
The browser uses border-top-color to determine the color of the top border without changing its width or style.
Step 1: Create an Element
<div class="panel">
This panel has a colored top border.
</div>
Step 2: Add Basic Styling
.panel {
padding: 20px;
background-color: #f3f8fc;
}
Step 3: Set the Border Width and Style
.panel {
border-top-width: 5px;
border-top-style: solid;
}
The top border uses the default color, currentcolor.
Step 4: Set the Border Color
.panel {
border-top-color: #1769aa;
}
The top border becomes blue.
Step 5: Change the Color
.panel {
border-top-color: #c04b37;
}
The top border becomes red without changing its width or style.
Step 6: Use the Shorthand
.panel {
border-top: 5px solid #1769aa;
}
The shorthand sets the width, style, and color together.
Use border-top-color when you need to change only the color of an existing top border.
CSS Color Formats
CSS supports several ways to express colors. The same top border color can often be written using different formats.
Named Colors
.panel {
border-top: 5px solid;
border-top-color: steelblue;
}
Hexadecimal Colors
.panel {
border-top: 5px solid;
border-top-color: #1769aa;
}
RGB Colors
.panel {
border-top: 5px solid;
border-top-color: rgb(23 105 170);
}
HSL Colors
.panel {
border-top: 5px solid;
border-top-color: hsl(207 76% 38%);
}
HWB Colors
.panel {
border-top: 5px solid;
border-top-color: hwb(207 9% 33%);
}
OKLCH Colors
.panel {
border-top: 5px solid;
border-top-color: oklch(55% 0.13 245);
}
Using color()
.panel {
border-top: 5px solid;
border-top-color: color(display-p3 0.1 0.4 0.7);
}
Using color-mix()
.panel {
border-top: 5px solid;
border-top-color: color-mix(in srgb, #1769aa 70%, white);
}
Modern color functions provide additional flexibility, but their browser compatibility may differ from traditional hexadecimal, RGB, and HSL formats.
Choose a color format that fits your project and browser support requirements.
Using currentcolor
The currentcolor keyword uses the element's computed color value as the border color.
Matching Text and Border Colors
.panel {
color: #1769aa;
border-top: 5px solid currentcolor;
}
The text and top border use the same color.
Default Border Color
.panel {
color: #1769aa;
border-top-width: 5px;
border-top-style: solid;
}
Because no border color is specified, the top border uses currentcolor.
Inherited Text Color
.container {
color: #1769aa;
}
.container .panel {
border-top: 5px solid currentcolor;
}
The panel inherits its text color from the container, and its top border uses that color.
Changing Text Color on Hover
.panel {
color: #1769aa;
border-top: 5px solid currentcolor;
}
.panel:hover {
color: #c04b37;
}
The border changes with the text color because it uses currentcolor.
Resetting to currentcolor
.panel {
color: #1769aa;
border-top: 5px solid #c04b37;
border-top-color: initial;
}
The initial keyword resets the top border color to currentcolor.
Using currentcolor is useful when a border should automatically match the text color of a component.
Transparent and Alpha Colors
Border colors can be fully transparent or partially transparent. Transparency changes how the border is painted without removing its width from the box model.
Fully Transparent Border
.panel {
border-top: 5px solid transparent;
}
The border is invisible but still occupies 5 pixels of space.
RGB With Alpha
.panel {
border-top: 5px solid rgb(23 105 170 / 50%);
}
The border uses a blue color at 50% opacity.
HSL With Alpha
.panel {
border-top: 5px solid hsl(207 76% 38% / 50%);
}
Eight-Digit Hexadecimal
.panel {
border-top: 5px solid #1769aa80;
}
The final two hexadecimal digits specify the alpha channel.
Transparent Hover Border
.panel {
border-top: 5px solid transparent;
}
.panel:hover {
border-top-color: #1769aa;
}
The border becomes visible on hover without changing its width.
Alpha Color Over a Background
.panel {
background-color: #f3f8fc;
border-top: 8px solid rgb(23 105 170 / 40%);
background-clip: padding-box;
}
Clipping the background to the padding box prevents the element's background from being painted beneath the semi-transparent border.
Use alpha colors when you want a border to blend visually with the background or surrounding content.
Border Width and Style
A top border color is visible only when the border has a visible style and a nonzero computed width.
Color Without a Style
.panel {
border-top-color: #1769aa;
}
No border is visible if the top border style remains at its initial value of none.
Adding a Border Style
.panel {
border-top-style: solid;
border-top-color: #1769aa;
}
The border becomes visible using the initial width of medium.
Setting an Explicit Width
.panel {
border-top-width: 5px;
border-top-style: solid;
border-top-color: #1769aa;
}
Using the Shorthand
.panel {
border-top: 5px solid #1769aa;
}
Zero Border Width
.panel {
border-top: 0 solid #1769aa;
}
The border is not visible because its width is zero.
Border Style none
.panel {
border-top-width: 5px;
border-top-style: none;
border-top-color: #1769aa;
}
The computed border width becomes zero because the style is none.
Changing Only the Color
.panel {
border-top: 5px dashed #1769aa;
}
.panel.highlight {
border-top-color: #c04b37;
}
The highlighted panel retains its dashed style and 5-pixel width.
Use border-top-color when the width and style are already defined and should remain unchanged.
Shorthand Interactions
Several border shorthands can set or reset the top border color.
border-top Shorthand
.panel {
border-top: 5px solid #1769aa;
}
Sets the top border width, style, and color together.
border Shorthand
.panel {
border: 3px solid #cccccc;
}
Sets the width, style, and color of all four borders.
border-color Shorthand
.panel {
border: 3px solid;
border-color: #1769aa #c04b37 #27805c #8054a5;
}
The first color applies to the top border, followed by right, bottom, and left.
Overriding the Top Color
.panel {
border: 3px solid #cccccc;
border-top-color: #1769aa;
}
Only the top border becomes blue.
Later border Shorthand
.panel {
border-top-color: #1769aa;
border: 3px solid #cccccc;
}
The later shorthand resets the top border color to gray.
Later border-top Shorthand
.panel {
border-top-color: #1769aa;
border-top: 5px dashed;
}
The later shorthand resets the top border color to currentcolor because no color is specified.
Preserving Width and Style
.panel {
border-top: 5px solid #1769aa;
border-top-color: #c04b37;
}
The longhand changes only the color.
At equal cascade priority, a later shorthand declaration can override a previously declared top border color.
Physical vs. Logical Borders
The border-top-color property always affects the physical top edge of an element.
Physical Top Border Color
.panel {
border-top: 5px solid;
border-top-color: #1769aa;
}
Logical Block-Start Color
.panel {
border-block-start: 5px solid;
border-block-start-color: #1769aa;
}
The logical property follows the block-start edge of the writing mode.
Horizontal Writing Mode
.panel {
writing-mode: horizontal-tb;
border-block-start: 5px solid;
border-block-start-color: #1769aa;
}
The block-start edge is the physical top edge.
Vertical Right-to-Left Writing Mode
.panel {
writing-mode: vertical-rl;
border-block-start: 5px solid;
border-block-start-color: #1769aa;
}
The block-start edge is the physical right edge.
Vertical Left-to-Right Writing Mode
.panel {
writing-mode: vertical-lr;
border-block-start: 5px solid;
border-block-start-color: #1769aa;
}
The block-start edge is the physical left edge.
Physical and Logical Conflict
.panel {
writing-mode: horizontal-tb;
border-top: 5px solid;
border-top-color: #1769aa;
border-block-start-color: #c04b37;
}
Both color properties target the top edge in this writing mode. The later declaration wins when cascade priority is otherwise equal.
Use border-top-color for a fixed physical edge and border-block-start-color for a color that follows the writing mode.
Backgrounds and Border Radius
The top border color can be combined with background colors, background clipping, and rounded corners.
Colored Panel
.panel {
padding: 20px;
background-color: #f3f8fc;
border-top: 5px solid #1769aa;
}
Rounded Top Corners
.panel {
border-top: 5px solid #1769aa;
border-top-left-radius: 16px;
border-top-right-radius: 16px;
}
The top border follows the rounded corners.
Rounded Card
.card {
border: 2px solid #cccccc;
border-top-color: #1769aa;
border-radius: 12px;
}
Semi-Transparent Border
.panel {
border-top: 8px solid rgb(23 105 170 / 50%);
background-color: #f3f8fc;
background-clip: padding-box;
}
The background is clipped to the padding box, allowing the semi-transparent border to blend with the surface behind the element.
Gradient Background
.panel {
border-top: 5px solid #1769aa;
background: linear-gradient(#ffffff, #e7f3fc);
}
The top border remains a separate painted edge above the gradient background.
The border-top-color property accepts a color, not a gradient image. For a gradient border effect, use an appropriate background or border-image technique.
Cascade and Overrides
The CSS cascade determines which top border color is applied when multiple declarations target the same element.
Later Declaration
.panel {
border-top-color: #1769aa;
border-top-color: #c04b37;
}
The later red color wins when cascade priority is otherwise equal.
Higher Specificity
.panel {
border-top-color: #1769aa;
}
.panel.featured {
border-top-color: #c04b37;
}
Shorthand Override
.panel {
border-top-color: #1769aa;
border-top: 5px solid #c04b37;
}
The later shorthand sets the color to red.
Longhand Override
.panel {
border-top: 5px solid #1769aa;
border-top-color: #27805c;
}
The top border becomes green without changing its width or style.
CSS Layers
@layer base, components;
@layer base {
.panel {
border-top-color: #1769aa;
}
}
@layer components {
.panel {
border-top-color: #c04b37;
}
}
For normal declarations, the later layer takes precedence.
Resetting the Color
.panel {
border-top: 5px solid #1769aa;
}
.panel.reset {
border-top-color: initial;
}
The reset class returns the top border color to currentcolor.
When troubleshooting a top border color, inspect declarations for border-top-color, border-top, border-color, and border.
CSS Custom Properties
Custom properties can store reusable border colors and make component themes easier to maintain.
Shared Accent Color
:root {
--accent-color: #1769aa;
}
.panel {
border-top: 5px solid;
border-top-color: var(--accent-color);
}
Fallback Color
.panel {
border-top: 5px solid;
border-top-color: var(--top-border-color, #1769aa);
}
Component Variants
.card {
--card-accent: #1769aa;
border-top: 5px solid var(--card-accent);
}
.card.warning {
--card-accent: #b7791f;
}
.card.success {
--card-accent: #27805c;
}
Color Mixing
.panel {
--accent-color: #1769aa;
border-top: 5px solid;
border-top-color: color-mix(in srgb, var(--accent-color) 70%, white);
}
Light and Dark Themes
.theme-light {
--panel-border-color: #1769aa;
}
.theme-dark {
--panel-border-color: #80c7f2;
}
.panel {
border-top: 5px solid var(--panel-border-color);
}
Responsive Color Variable
.panel {
--top-accent: #1769aa;
border-top: 5px solid var(--top-accent);
}
@media (max-width: 600px) {
.panel {
--top-accent: #27805c;
}
}
Custom properties help keep accent colors consistent while allowing individual components to override them.
Interactive States
Changing the top border color can communicate hover, focus, selection, and other interface states without changing the border's dimensions.
Hover State
.card {
border-top: 5px solid #cccccc;
}
.card:hover {
border-top-color: #1769aa;
}
Focus State
.control {
border-top: 3px solid #888888;
}
.control:focus-visible {
border-top-color: #1769aa;
outline: 2px solid #1769aa;
outline-offset: 2px;
}
Selected Card
.card {
border-top: 5px solid #cccccc;
}
.card.is-selected {
border-top-color: #1769aa;
}
Current Navigation Item
.nav-link {
border-top: 3px solid transparent;
}
.nav-link[aria-current="page"] {
border-top-color: #1769aa;
}
Expanded Details Panel
details {
border-top: 4px solid #cccccc;
}
details[open] {
border-top-color: #1769aa;
}
Invalid Form Field
input {
border: 2px solid #888888;
}
input:invalid {
border-top-color: #c04b37;
}
Color changes can reinforce interactive feedback, but important states should not be communicated by color alone.
Transitions and Animation
The border-top-color property can transition smoothly between compatible CSS colors.
Hover Color Transition
.panel {
border-top: 5px solid #1769aa;
transition: border-top-color 0.3s ease;
}
.panel:hover {
border-top-color: #c04b37;
}
Transparent to Opaque
.panel {
border-top: 5px solid transparent;
transition: border-top-color 0.3s ease;
}
.panel:hover {
border-top-color: #1769aa;
}
The border fades into view without changing its width.
Focus Color Transition
.control {
border-top: 3px solid #888888;
transition: border-top-color 0.2s ease;
}
.control:focus-visible {
border-top-color: #1769aa;
outline: 2px solid #1769aa;
}
Keyframe Animation
@keyframes top-border-pulse {
0%, 100% {
border-top-color: #1769aa;
}
50% {
border-top-color: #c04b37;
}
}
.animated-panel {
border-top: 5px solid #1769aa;
animation: top-border-pulse 2s ease-in-out infinite;
}
Animating With currentcolor
.panel {
color: #1769aa;
border-top: 5px solid currentcolor;
transition: color 0.3s ease;
}
.panel:hover {
color: #c04b37;
}
The top border follows the changing text color.
Reduced Motion Preference
.panel {
border-top: 5px solid #1769aa;
transition: border-top-color 0.3s ease;
}
.panel:hover {
border-top-color: #c04b37;
}
@media (prefers-reduced-motion: reduce) {
.panel {
transition: none;
}
}
Animating the color instead of the border width is often useful when you want visual feedback without changing layout dimensions.
Responsive Design
Top border colors can adapt to viewport size, container dimensions, and color scheme preferences.
Media Query
.panel {
border-top: 5px solid #1769aa;
}
@media (max-width: 600px) {
.panel {
border-top-color: #27805c;
}
}
Container Query
.panel-container {
container-type: inline-size;
}
.panel {
border-top: 5px solid #1769aa;
}
@container (min-width: 500px) {
.panel {
border-top-color: #8054a5;
}
}
Dark Color Scheme
.panel {
border-top: 5px solid #1769aa;
}
@media (prefers-color-scheme: dark) {
.panel {
border-top-color: #80c7f2;
}
}
High Contrast Preferences
.panel {
border-top: 5px solid #1769aa;
}
@media (prefers-contrast: more) {
.panel {
border-top-color: currentcolor;
}
}
Forced Colors Mode
.panel {
border-top: 5px solid #1769aa;
}
@media (forced-colors: active) {
.panel {
border-top-color: CanvasText;
}
}
The system color keyword CanvasText can help the border follow the user's forced color palette.
Logical Border Alternative
.panel {
border-block-start: 5px solid;
border-block-start-color: #1769aa;
}
The logical alternative follows the block-start edge rather than always targeting the physical top.
Responsive border colors can help maintain contrast and visual consistency across different layouts and user preferences.
Practical Uses
The border-top-color property is useful for accent panels, status indicators, navigation, cards, and section dividers.
Accent Card
.card {
padding: 20px;
border: 2px solid #cccccc;
border-top-width: 6px;
border-top-color: #1769aa;
}
Success Message
.success-message {
padding: 16px;
border-top: 5px solid #27805c;
background-color: #eef8f2;
}
Warning Message
.warning-message {
padding: 16px;
border-top: 5px solid #b7791f;
background-color: #fff8e8;
}
Error Message
.error-message {
padding: 16px;
border-top: 5px solid #c04b37;
background-color: #fff0ed;
}
Navigation Indicator
.nav-link {
border-top: 3px solid transparent;
}
.nav-link[aria-current="page"] {
border-top-color: #1769aa;
}
Section Divider
.section-divider {
padding-top: 20px;
border-top: 2px solid #cccccc;
}
.section-divider.featured {
border-top-color: #1769aa;
}
Theme Accent
.panel {
--accent-color: #1769aa;
border-top: 5px solid var(--accent-color);
}
.panel.secondary {
--accent-color: #8054a5;
}
Hover Highlight
.feature-card {
border-top: 5px solid #cccccc;
transition: border-top-color 0.3s ease;
}
.feature-card:hover {
border-top-color: #1769aa;
}
Changing only the top border color is useful when you want consistent border dimensions across several component variations.
border-top-color Example
The following example demonstrates several color formats, transparency, and the currentcolor keyword.
<div class="border-top-color-demo">
<div class="demo-box hex">Hexadecimal</div>
<div class="demo-box rgb">RGB</div>
<div class="demo-box hsl">HSL</div>
<div class="demo-box named">Named Color</div>
<div class="demo-box alpha">50% Alpha</div>
<div class="demo-box transparent">Transparent</div>
<div class="demo-box current">currentcolor</div>
<div class="demo-box mixed">Mixed Borders</div>
</div>
.border-top-color-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
gap: 20px;
}
.border-top-color-demo .demo-box {
box-sizing: border-box;
min-height: 100px;
padding: 20px;
border-top: 8px solid;
background-color: #f3f8fc;
color: #173b5e;
font-weight: bold;
text-align: center;
}
.border-top-color-demo .hex {
border-top-color: #1769aa;
}
.border-top-color-demo .rgb {
border-top-color: rgb(192 75 55);
}
.border-top-color-demo .hsl {
border-top-color: hsl(145 52% 33%);
}
.border-top-color-demo .named {
border-top-color: rebeccapurple;
}
.border-top-color-demo .alpha {
border-top-color: rgb(23 105 170 / 50%);
}
.border-top-color-demo .transparent {
border-top-color: transparent;
}
.border-top-color-demo .current {
color: #1769aa;
border-top-color: currentcolor;
}
.border-top-color-demo .mixed {
border: 3px solid #cccccc;
border-top-width: 8px;
border-top-color: #1769aa;
}
The examples show how different CSS color formats can be applied to the same border edge. The transparent example reserves border space without drawing a visible line.
The currentcolor example matches the border to the text color. The Mixed Borders example uses a blue top border with gray borders on the remaining sides.
Important Considerations
Keep the following points in mind when using border-top-color:
- Purpose: Sets the color of the physical top border.
- Property type: Longhand property.
- Initial value:
currentcolor. - Inheritance: The property is not inherited.
- Accepted values: One valid CSS color value.
- Physical edge: Always targets the top edge regardless of writing mode.
- Visible border: Requires a visible style and nonzero computed width.
- Color formats: Supports named colors, hexadecimal, RGB, HSL, and other CSS color functions.
- currentcolor: Uses the element's computed text color.
- transparent: Makes the border invisible without removing its width.
- Alpha colors: Allow partially transparent borders.
- Shorthand interactions:
border,border-top, andborder-colorcan reset the value. - Logical alternative: Use
border-block-start-colorfor a direction-aware border. - Rounded corners: The colored border follows applicable border radius curves.
- Gradients: The property accepts colors, not gradient images.
- Custom properties: Can store reusable border colors.
- Animation: Compatible color values can interpolate smoothly.
- Accessibility: Important states should not be communicated by color alone.
- Browser support: The property is widely supported.
Use border-top-color when you need to change the top border's color without changing its thickness or line style.
Browser Support
The border-top-color property is widely available and supported in Chrome, Edge, Firefox, Safari, and other major browsers.
Basic color values, including named colors, hexadecimal notation, RGB, HSL, and currentcolor, are supported across modern browsers. Newer color functions may have different compatibility requirements.
.panel {
border-top: 5px solid;
border-top-color: #1769aa;
}
This example uses established CSS border features and does not require a vendor prefix.
For current compatibility details, visit Can I Use? and search for border-top-color.
Specifications
The border-top-color property is defined in the CSS Backgrounds and Borders Module Level 3 specification.
CSS Backgrounds and Borders Module Level 3
The specification defines border color properties and their relationships to border shorthands. The accepted color values are defined by the CSS Color specifications.
