Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Topics

CSS border-top Property

Posted in CSS Tutorial
Updated on Oct 02, 2024
By Mari Selvan
👁️ 25 - Views
⏳ 4 mins
💬 1 Comment
CSS border-top Property

Photo Credit to CodeToFun

🙋 Introduction

The border-top property in CSS is used to define the style, width, and color of the top border of an element.

This property is particularly useful when you want to create a border on only the top side of an element, allowing for more control over the appearance of your content.

💡 Syntax

The border-top property can be used with one, two, or three values depending on what you want to specify. The values correspond to the border's width, style, and color.

Syntax
Copied
Copy To Clipboard
element {
  border-top: width style color;
}
  • width: Specifies the thickness of the border (e.g., 1px, 0.5em, thin, medium, thick).
  • style: Specifies the line style of the border (e.g., solid, dashed, dotted, double, none).
  • color: Specifies the color of the border (e.g., red, #000, rgb(0, 0, 0)).

🎛️ Default Value

The default value for the border-top property is medium none color, where:

  • medium is the default width,
  • none means no border is shown, and
  • color defaults to the current text color of the element.

🏠 Property Values

ValueDescription
widthThe thickness of the border (e.g., 1px, 0.5em, thin, medium, thick).
styleThe style of the border line (e.g., solid, dashed, dotted, double, none).
colorThe color of the border, which can be defined using named colors, hexadecimal values, RGB, or HSL.

📄 Example

In this example, we'll add a solid blue border to the top of a <div> element.

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 Example</title>
  <style>
    .top-border {
      border-top: 5px solid blue;
    }
  </style>
</head>
<body>
  <h1>Div with Top Border</h1>
  <div class="top-border">
    This div has a blue top border that is 5 pixels thick.
  </div>
</body>
</html>

🖥️ Browser Compatibility

The border-top property is well-supported across all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. This ensures that your styling will be consistent across different platforms and devices.

🎉 Conclusion

The border-top property is a simple yet powerful CSS property that allows you to add a border to the top of an element. With options to customize the width, style, and color, this property gives you precise control over the visual presentation of your elements. Experiment with different combinations to enhance the design of your web pages.

👨‍💻 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