1. css
  2. /properties
  3. /border-top-color

border-top-color

Definition

border-top-color is a CSS property that sets the color of the top border of an element. It can be set using a valid color value, such as a named color, a hex code, or an RGB value.

Examples

Setting the top border color to a named color:

element {
    border-top-color: blue;
}

Setting the top border color to a hex code:

element {
    border-top-color: #ff0000;
}

Setting the top border color to an RGB value:

element {
    border-top-color: rgb(255, 0, 0);
}

Setting the top border color to transparent:

element {
    border-top-color: transparent;
}

Setting the top border color to currentColor:

element {
    color: blue;
    border-top-color: currentColor;
}

Using border-top shorthand property to set the color, width, and style of the top border at once:

element {
    border-top: 2px solid blue;
}

Values

ValueDescription
<color>A valid color value, such as a named color, a hex code, or an RGB value.
transparentSpecifies that the top border color should be transparent.
currentColorSpecifies that the top border color should be the same as the text color of the element.

Best Practices

  • Use semantic color names: When possible, use semantic color names (e.g. red, blue, green) instead of hex codes or RGB values to make your code more readable.
  • Use the border-top shorthand property: Instead of using the border-top-color property in conjunction with border-top-width and border-top-style, you can use the border-top shorthand property to set all three properties at once. This makes your code more concise and easier to read.
  • Be consistent with your border colors: If you're using multiple borders on an element, try to be consistent with the colors you use. This will make your design more cohesive and easier to understand.
  • Avoid using too many borders: Overuse of borders can make a design look cluttered and overwhelming. Use borders sparingly and only when necessary to enhance the design.
  • Be mindful of accessibility: Keep in mind that some users may have difficulty distinguishing certain colors, especially if they have color vision deficiencies. Try to use a combination of colors and patterns to create borders that are easy to see and understand.
  • Test your border colors: Make sure to test your border colors on different devices and browsers to ensure that they look the way you expect them to. Some colors may appear differently on different screens.
  • Use CSS variables: If you need to use the same border-top-color on multiple elements, you can use CSS variables to make it easier to update the color in one place.

Browser Compatibility

ChromeFirefoxSafariInternet ExplorerMicrosoft EdgeOpera
YesYesYesYesYesYes