Tag border-top

🔝 CSS border-top: Styling the Top Border with Precision

Borders are fundamental in web design — they define boundaries, create emphasis, and add style. The border-topproperty in CSS is a shorthand that lets you control the top border of any HTML element in one go: its width, style, and color.


🧾 What is border-top?

border-top is a shorthand CSS property that allows you to set the widthstyle, and color of the top border of an element in a single declaration.


🧬 Syntax

selector {
border-top: <border-width> <border-style> <border-color>;
}

All parts are optional, but if you leave out border-style, no border will appear even if width and color are set.


🎯 Examples

1. Solid blue top border

header {
border-top: 4px solid blue;
}

Creates a thick solid blue line at the top edge of the header.


2. Dashed red top border

section {
border-top: 2px dashed red;
}

Adds a thin dashed red line at the top of the section.


3. Double green top border

.article {
border-top: 5px double green;
}

Gives a thick double-lined green border on top — great for emphasis.


🔍 How It Works

  • border-top-style must be set (not none) for the border to show.
  • The property overrides any previous individual border-top-widthborder-top-style, or border-top-colorsettings.
  • Can be combined with other border properties like borderborder-bottomborder-left, etc.

🛠️ Practical Uses

  • Visually separate content sections with a top border.
  • Add emphasis to headers or titles.
  • Create decorative dividers.
  • Combine with animations to create dynamic borders on hover.

✅ Browser Support

border-top works flawlessly across all modern browsers including:

  • Chrome
  • Firefox
  • Safari
  • Edge
  • Internet Explorer 8+

🔚 Conclusion

The CSS border-top property is a versatile shorthand for defining the top border of an element with control over width, style, and color. Whether you want a subtle separator or a bold accent, border-top lets you easily customize your layouts.