The border-top property sets the width, style, and color of the physical top border in one shorthand rule.
01
Top Side
Physical edge.
02
Shorthand
Width, style, color.
03
solid
Common style.
04
Card Accents
Header bars and tabs.
05
Longhands
width, style, color.
06
Classic CSS
Universal support.
Fundamentals
Definition and Usage
The border-top CSS property is a physical shorthand that sets the border on the top side of an element. It combines border-top-width, border-top-style, and border-top-color in one declaration.
Unlike logical properties such as border-block-start, border-top always targets the physical top edge — even in vertical writing modes. That makes it straightforward for section headers, card accent bars, and horizontal dividers.
💡
Beginner Tip
For layouts that must adapt to vertical writing modes, consider border-block-start instead of border-top so the accent bar follows the block-start edge.
Foundation
📝 Syntax
border-top accepts border width, style, and color like other border shorthands:
syntax.css
selector{border-top:width style color;}
Basic Example
border-top.css
.top-border{border-top:5px solid blue;}
Syntax Rules
Sets width, style, and color for the top border side only.
Omitted components use initial values: medium, none, currentcolor.
Any valid border width, style, and color values are accepted.
Always affects the physical top side, regardless of direction or writing-mode.
Use longhands when you need to set only width, style, or color on the top side.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
medium none currentcolor
Applies to
Top border side only
Inherited
No
Animatable
Partially (color and width)
Common use
Section dividers, card accents, tab indicators
Defaults
Default Value
The default value of border-top is medium none currentcolor. No visible border appears until you set a non-none style and a width greater than zero.
Reference
💎 Property Values
Component
Example
Meaning
border-width
4px, thin, 0.25rem
Thickness of the top border
border-style
solid, dashed, dotted
How the top border is drawn
border-color
red, #2563eb, currentcolor
Color of the top border
Common Value Types
4px solidsolid top border
3px dasheddashed style
6px solidthick accent
Scope
Top Border and Writing Modes
border-top always draws on the physical top edge. Vertical writing modes do not move the border — compare with border-block-start when block-start should follow the writing mode.
Horizontal (writing-mode: horizontal-tb)
Top border on the top edge
topleftrightbottom
Vertical (writing-mode: vertical-rl)
Top border still on the physical top
topleftrightbottom
Compare
border-top vs related properties
Property
Targets
Best for
border-top
Physical top side only
Top accent bars and section dividers
border-block-start
Logical block-start side
Writing-mode-aware header accents
border-bottom
Physical bottom side only
Footer dividers and underlines
border
All four sides
Full box outlines
Preview
👀 Live Preview
A box with a blue border on the top edge:
Blue border on the top edge.
Uses border-top: 4px solid #2563eb;.
Hands-On
Examples Gallery
Try border-top with solid blue borders, card accents, vertical writing comparison, and dashed styles.
📚 Basic Top Borders
Add a border on the physical top edge of an element.
Example 1 — 5px Solid Blue Top Border
Add a solid blue top border on a div, matching the reference tutorial.
border-top-basic.html
<style>.top-border{border-top:5px solid blue;padding:10px;}</style><h1>Div with Top Border</h1><divclass="top-border">
This div has a blue top border that is 5 pixels thick.
</div>
A top border creates a horizontal accent at the physical top edge. Pair it with padding so content sits below the line comfortably.
🎨 Writing Modes and Style Variations
See how border-top behaves in vertical writing and with different styles.
Example 3 — border-top in Vertical Writing
In vertical writing, border-top stays on the physical top — unlike border-block-start.
border-top-vertical.html
<style>.vertical-box{writing-mode:vertical-rl;display:inline-block;padding:0.75rem 1rem;border-top:4px solid #059669;background:#ecfdf5;}</style><divclass="vertical-box">
Top border stays on the physical top
</div>
Vertical writing changes text flow but not the physical top edge. For a block-start accent that follows the writing mode, use border-block-start instead.
Example 4 — Dashed Top Border
Use a dashed style for a lighter horizontal divider at the top.
Any valid border style works on the top side. A dashed top border adds visual emphasis without a full box outline.
🧠 How border-top Works
1
You set width, style, and color
The shorthand combines all three border components for the top side in one rule.
Shorthand
2
Browser draws the top edge
border-top applies only to the physical top side of the element box.
Apply
3
Other sides stay unchanged
Right, bottom, and left borders keep their own values unless you set them separately.
Scope
=
↑
Top border applied
Your element shows a styled border on the physical top edge.
Compatibility
Modern Browser Support
The border-top property is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera.
✓ Baseline · Modern browsers
Physical top borders in every browser
Chrome, Edge, Firefox, Safari, and Opera have supported border-top since the earliest CSS versions.
99%Modern browser support
Google Chrome87+ · Desktop & Mobile
Full support
Mozilla Firefox66+ · Desktop & Mobile
Full support
Apple Safari14.1+ · macOS & iOS
Full support
Microsoft Edge87+ · All versions
Full support
Opera73+ · Modern versions
Full support
border-top property99% supported
Bottom line:border-top is one of the most reliable CSS border properties across all browsers.
Wrap Up
Conclusion
The border-top property controls the border on the physical top edge. Use it for section dividers, card accent bars, and tab indicators in horizontal layouts.
Combine width, style, and color in one shorthand, or use border-top-width, border-top-style, and border-top-color when you need finer control.
Use top borders for section dividers and card accent bars
Pair with padding so content does not touch the border
Use border-block-start instead when vertical writing mode support is required
Combine width, style, and color in one shorthand when all three are needed
Use longhands when only one component needs to change
❌ Don’t
Expect border-top to move to the side in vertical writing modes
Mix conflicting physical and logical border rules on the same element
Use border-top for block-start accents when writing-mode-aware borders are needed
Forget a visible style — width alone may not show a border
Hard-code top borders when a logical property would be clearer
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about border-top
Use these points when styling physical top borders.
5
Core concepts
↑01
Top shorthand
Physical edge.
Purpose
⚡02
Default none
No border.
Default
🔀03
5px solid blue
Reference pattern.
Values
🌐04
Fixed top
Not logical.
Physical
🛠05
Card accents
Real use case.
Usage
❓ Frequently Asked Questions
The border-top property is a shorthand that sets the width, style, and color of the physical top border of an element in one declaration.
The initial value is medium none currentcolor, which means no visible border unless you set width, style, or color explicitly.
border-top always targets the physical top edge of an element, regardless of text direction or writing mode.
border-top is fixed to the physical top edge. border-block-start follows the writing mode, so in vertical writing it may appear on the side instead of the top.
Use it for section dividers, card accent bars, tab indicators, and header underlines where the border should stay on the physical top edge.