Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS border-top-color Property

Posted in CSS Tutorial
Updated on Aug 09, 2024
By Mari Selvan
πŸ‘οΈ 9 - Views
⏳ 4 mins
πŸ’¬ 1 Comment
CSS border-top-color Property

Photo Credit to CodeToFun

πŸ™‹ Introduction

The border-top-color property in CSS is used to set the color of the top border of an element.

This property is particularly useful when you want to style the top border of an element differently from the other borders, allowing for more nuanced design control. The color can be specified using any valid CSS color value.

πŸ’‘ Syntax

The syntax for the border-top-color property is straightforward. You can apply this property to any element that supports borders.

Syntax
Copied
Copy To Clipboard
element {
  border-top-color: color;
}

Here, color can be a named color, a hexadecimal value, an RGB value, an HSL value, or any other valid CSS color value.

πŸŽ›οΈ Default Value

The default value of the border-top-color property is the color of the element's color property, which means it inherits the text color if not specified otherwise.

🏠 Property Values

ValueDescription
named-colorA color keyword, such as blue, red, green, etc.
hexadecimal valueA hex code representing a color, such as #ff5733.
RGB valueAn RGB color value, such as rgb(255, 87, 51).
HSL valueAn HSL color value, such as hsl(9, 100%, 60%).
transparentMakes the top border color fully transparent.
currentcolorThe current value of the color property.

πŸ“„ Example

In this example, we’ll change the top border color of a div element to red.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS border-top-color Example</title>
  <style>
    div {
      border: 2px solid;
      border-top-color: red;
    }
  </style>
</head>
<body>
  <h1>Div with Custom Top Border Color</h1>
  <div>This div has a red top border.</div>
</body>
</html>

πŸ–₯️ Browser Compatibility

The border-top-color property is widely supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It works consistently in most environments, so you can use it confidently in your web projects.

πŸŽ‰ Conclusion

The border-top-color property is a simple yet powerful tool for customizing the appearance of an element’s top border. By setting a specific color for the top border, you can enhance the design of your web page and create visually appealing effects. Experiment with different color values to see how this property can add a unique touch to your web design.

πŸ‘¨β€πŸ’» Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
πŸ‘‹ Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy