CSS border-top-width Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Box Model & Borders

What You’ll Learn

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.

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.

📝 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;
}

Basic Example

border-top-width.css
p {
  border-top-width: 5px;
  border-top-style: solid;
  border-top-color: black;
}

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.

⚡ Quick Reference

QuestionAnswer
Initial valuemedium
Applies toTop border width only
InheritedNo
AnimatableYes, as a length
Common useSection dividers, header lines, card accent bars

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.

💎 Property Values

The border-top-width property accepts keyword values and length units.

ValueDescription
thinA thin border width (typically 1px)
mediumA medium border width (default, typically 3–4px)
thickA thick border width (typically 5–6px)
<length>A specific width using a length unit like px, em, or rem
initialSets the property to its default value
inheritInherits the property value from its parent element
previewthin
previewmedium
previewthick
preview1px
preview4px
preview8px

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

border-top-width vs border-block-start-width

PropertyTargetsBest for
border-top-widthPhysical top border thicknessCards, headers, and horizontal section dividers
border-block-start-widthLogical block-start border thicknessMultilingual and writing-mode-aware layouts
border-topWidth, style, and color togetherWhen you want one shorthand for the full top border

👀 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.

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>

<p class="thin-border">This paragraph has a thin top border.</p>
<p class="thick-border">This paragraph has a thick top border.</p>
Try It Yourself

How It Works

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>
Try It Yourself

How It Works

5px sets an exact thickness on the top edge. Style and color longhands make the border visible.

📏 Width Comparisons and Overrides

Compare exact pixel widths and override only the top edge on a full border.

Example 3 — Compare 1px, 4px, and 8px Widths

See how different pixel values change the weight of a top divider.

border-top-width-pixels.css
.w-1 {
  border-top: 1px solid #64748b;
}
.w-4 {
  border-top-width: 4px;
  border-top-style: solid;
  border-top-color: #2563eb;
}
.w-8 {
  border-top: 8px solid #dc2626;
}
Try It Yourself

How It Works

Small differences in width create very different visual weight. Use 1px or 2px for subtle UI lines and larger values for emphasis.

Example 4 — Thick Top Accent on a Card

Give all sides a light border, then make only the top edge thicker for a card accent bar.

border-top-width-override.css
.tab-card {
  border: 1px solid #cbd5e1;
  border-top-width: 4px;
  border-top-color: #2563eb;
  padding: 1rem;
  border-radius: 0.5rem;
}
Try It Yourself

How It Works

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.

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 property 100% supported

Bottom line: Use border-top-width freely in any project. It works consistently across all browsers.

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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about border-top-width

Use these points when sizing the physical top edge.

5
Core concepts
⚙️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.

Practice in the Live Editor

Open the HTML editor, try border-top-width, and preview top border thickness instantly.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful