The border-top-width property sets how thick the top border is on an element. It is useful when you want precise control over divider weight on the top edge.
01
Top Width
Physical top edge.
02
thin / medium / thick
Keyword sizes.
03
px / em / rem
Exact length units.
04
medium Default
Browser default size.
05
Needs Style
Pair with style/color.
06
Longhand
Part of border-top.
Fundamentals
Definition and Usage
The border-top-width CSS property allows you to specify the thickness of the top border of an element. This property is part of the border longhand family and is used to control the width of the border along the top edge.
By adjusting this property, you can enhance visual separation between elements and create more defined layouts with subtle 1px dividers or prominent accent lines.
💡
Beginner Tip
border-top-width only sets thickness. Add border-top-style: solid; and border-top-color: black; so the border is visible, or use border-top: 5px solid black; as shorthand.
Foundation
📝 Syntax
The syntax for border-top-width is straightforward. It accepts keyword values or length units.
syntax.css
selector{border-top-width:<length> | thin | medium | thick;}
The value can be a keyword such as thin or a length such as 5px, 0.25em, or 1rem.
Syntax Rules
The initial value is medium, typically around 3 to 4 pixels.
Keywords: thin, medium, and thick.
Length values use units like px, em, or rem.
Pair with border-top-style and border-top-color for full control.
Use border-top shorthand when setting width, style, and color together.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
medium
Applies to
Top border width only
Inherited
No
Animatable
Yes, as a length
Common use
Section dividers, header lines, card accent bars
Defaults
Default Value
The default value of border-top-width is medium, which typically corresponds to a width of around 3 to 4 pixels depending on the browser’s default settings.
Reference
💎 Property Values
The border-top-width property accepts keyword values and length units.
Value
Description
thin
A thin border width (typically 1px)
medium
A medium border width (default, typically 3–4px)
thick
A thick border width (typically 5–6px)
<length>
A specific width using a length unit like px, em, or rem
initial
Sets the property to its default value
inherit
Inherits the property value from its parent element
previewthin
previewmedium
previewthick
preview1px
preview4px
preview8px
Scope
Physical Top Edge
border-top-width always sets the thickness of the visual top border, even when writing mode changes. For writing-mode-aware layouts, consider border-block-start-width instead.
Horizontal writing
5px top border width
Vertical writing (vertical-rl)
Still on physical top
Compare
border-top-width vs border-block-start-width
Property
Targets
Best for
border-top-width
Physical top border thickness
Cards, headers, and horizontal section dividers
border-block-start-width
Logical block-start border thickness
Multilingual and writing-mode-aware layouts
border-top
Width, style, and color together
When you want one shorthand for the full top border
Preview
👀 Live Preview
A box with a 5px top border width:
This element has a 5px top border width.
Uses border-top-width: 5px; with solid style and black color.
Hands-On
Examples Gallery
Try border-top-width with keyword sizes, pixel lengths, width comparisons, and top-edge overrides.
📚 Basic Top Border Widths
Set the top border width with style and color longhands so the line is visible.
Example 1 — Border Top Width Example (Reference)
Set different top border widths using the thin and thick keywords, matching the reference tutorial.
border-top-width-reference.html
<style>p.thin-border{border-top-width:thin;border-top-style:solid;border-top-color:black;padding-top:0.75rem;margin-bottom:0.75rem;}p.thick-border{border-top-width:thick;border-top-style:solid;border-top-color:black;padding-top:0.75rem;}</style><pclass="thin-border">This paragraph has a thin top border.</p><pclass="thick-border">This paragraph has a thick top border.</p>
thin and thick are keyword widths. Pair them with a visible style and color so the top border appears clearly.
Example 2 — 5px Top Border Width
Set border-top-width to 5px on a paragraph element.
border-top-width-5px.html
<style>p{border-top-width:5px;border-top-style:solid;border-top-color:black;padding-top:0.75rem;}</style><p>
This paragraph has a top border width of 5 pixels.
</p>
The border shorthand sets all sides to 1px. border-top-width: 4px; then overrides only the top thickness for a stronger accent line.
🧠 How border-top-width Works
1
You choose a thickness
Set a keyword like thin or a length like 5px.
Width rule
2
You add style and color
Pair the width with border-top-style and border-top-color.
Border setup
3
The browser draws the top edge
Only the physical top border uses that thickness. Right, bottom, and left sides stay unchanged.
Top edge
=
─
Sized top accent
Your element gets a clear separator with the thickness you chose on the top edge.
Compatibility
Universal Browser Support
The border-top-width property is supported in all major browsers, including Chrome, Firefox, Safari, Edge, Opera, and Internet Explorer. It is one of the most reliable CSS border properties.
✓ Baseline · All browsers
Reliable top border widths on every platform
Chrome, Firefox, Safari, Edge, and Opera all support border-top-width consistently.
100%Universal support
Google Chrome69+ · Desktop & Mobile
Full support
Mozilla Firefox66+ · Desktop & Mobile
Full support
Apple Safari12.1+ · macOS & iOS
Full support
Microsoft Edge79+ · Chromium
Full support
Opera56+ · Modern versions
Full support
border-top-width property100% supported
Bottom line: Use border-top-width freely in any project. It works consistently across all browsers.
Wrap Up
Conclusion
The border-top-width property is a useful tool for controlling the thickness of the top border of elements. Whether you want a subtle 1px divider or a prominent accent line, adjusting the border width helps you achieve the desired visual effect.
Experiment with keyword values like thin and thick, or use exact lengths such as 2px and 4px to find the best fit for your design needs.
Use 1px or 2px for subtle UI dividers on the top edge
Pair width with style and color longhands for predictable results
Use rem when you want thickness to scale with root font size
Use the border-top shorthand when setting all three parts
Override only border-top-width when other sides use the border shorthand
❌ Don’t
Set width alone and forget a visible border style
Use border-top-width when you need a writing-mode-aware logical edge
Use very thick borders everywhere in minimal UI designs
Mix physical and logical width properties without a clear reason
Rely on medium when you need exact pixel control
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about border-top-width
Use these points when sizing the physical top edge.
5
Core concepts
─01
Top Width
Physical top edge.
Purpose
⚙️02
medium Default
Browser default size.
Default
📏03
thin / thick
Quick keywords.
Values
📝04
px / em / rem
Exact lengths.
Units
🔄05
One Edge Only
Other sides unchanged.
Scope
❓ Frequently Asked Questions
The border-top-width property sets the thickness of the top border of an element. It only affects the physical top edge.
The initial value is medium, which is typically around 3 to 4 pixels depending on the browser.
Width alone does not always show a border. You also need a visible border-top-style such as solid and usually a color, or use the border-top shorthand.
border-top-width always sets the physical top edge thickness. border-block-start-width follows the writing mode and stays on the logical block-start side.
Length values like 1px, 2px, and 4px are most common in modern UI. Keywords thin, medium, and thick are useful for quick sizing.