CSS border-width Property

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

What You’ll Learn

The border-width property sets how thick the borders are on an element. You can use one value for all sides or up to four values for top, right, bottom, and left.

01

All Sides

Top, right, bottom, left.

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

Shorthand

One to four values.

Definition and Usage

The border-width CSS property controls the thickness of the border around an element. It applies to all four sides and is essential for defining how prominent a box, card, or frame appears on the page.

By choosing keyword values like thin and thick, or exact lengths such as 2px and 5px, you can fine-tune visual weight for cards, form fields, callouts, and layout dividers.

💡
Beginner Tip

border-width only sets thickness. Add border-style: solid; and border-color: black; so the border is visible, or use border: 5px solid #ff5733; as shorthand.

📝 Syntax

The syntax for border-width accepts keyword values or length units:

syntax.css
selector {
  border-width: <length> | thin | medium | thick;
}

Basic Example

border-width.css
.box {
  border-width: 5px;
  border-style: solid;
  border-color: #ff5733;
}

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.
  • One value applies to all four sides; up to four values target top, right, bottom, and left.
  • Keywords: thin, medium, and thick.
  • Length values use units like px, em, or rem.
  • Pair with border-style and border-color, or use the border shorthand.

⚡ Quick Reference

QuestionAnswer
Initial valuemedium
Applies toAll four border sides (shorthand for top, right, bottom, left)
InheritedNo
AnimatableYes, as a length
Common useCards, boxes, form fields, frames, and emphasis lines

Default Value

The default value of border-width is medium, which typically corresponds to a width of around 3 to 4 pixels depending on the browser’s default settings.

You can pass one to four values to set the same thickness on every side or assign a different width to each edge.

💎 Property Values

The border-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

One to Four Values

border-width follows the same shorthand pattern as margin and padding. One value styles every side; up to four values target top, right, bottom, and left in that order.

  • One value — applies to all four sides.
  • Two values — first value for top and bottom, second for right and left.
  • Three values — top, right/left, bottom.
  • Four values — top, right, bottom, left.

One value (3px)

Same width on every side

Four values (1px 4px 8px 2px)

Different width per side

border-width vs Side Longhands vs border

PropertyTargetsBest for
border-widthWidth on all four sides (1–4 values)Setting the same or mixed thickness around a box
border-top-width (and other side longhands)Width on one physical side onlyAccenting a single edge without affecting the others
borderWidth, style, and color togetherQuick one-line borders when all three parts are the same

👀 Live Preview

A box with a 5px orange border on all sides:

This box has a 5px wide border.

Uses border-width: 5px; with border-style: solid; and border-color: #ff5733;.

Examples Gallery

Try border-width with pixel lengths, keyword sizes, four-value shorthand, and width comparisons.

📚 Basic Border Widths

Set border-width with style and color longhands so the border is visible, matching the reference tutorial.

Example 1 — Box with Custom Border Width (Reference)

Set border-width to 5px on a box with a solid orange border.

border-width-reference.html
<style>
  .box {
    border-style: solid;
    border-width: 5px;
    border-color: #ff5733;
    padding: 10px;
  }
</style>

<h1>Box with Custom Border Width</h1>
<div class="box">
  This box has a 5px wide border.
</div>
Try It Yourself

How It Works

5px sets the same thickness on all four sides. Style and color longhands make the border visible.

Example 2 — thin, medium, and thick Keywords

Compare the three keyword widths on solid black borders.

border-width-keywords.css
.thin {
  border-width: thin;
  border-style: solid;
  border-color: black;
  padding: 0.75rem;
}
.medium {
  border-width: medium;
  border-style: solid;
  border-color: black;
  padding: 0.75rem;
}
.thick {
  border-width: thick;
  border-style: solid;
  border-color: black;
  padding: 0.75rem;
}
Try It Yourself

How It Works

Keywords give quick sizing without exact pixels. Browsers map them to roughly 1px, 3–4px, and 5–6px respectively.

📏 Shorthand and Pixel Widths

Use multiple values for per-side thickness, or compare exact pixel widths.

Example 3 — Four-Value Shorthand

Assign a different width to each side with four values: top, right, bottom, left.

border-width-shorthand.css
.shorthand-box {
  border-width: 1px 4px 8px 2px;
  border-style: solid;
  border-color: #2563eb;
  padding: 1rem;
  max-width: 16rem;
}
Try It Yourself

How It Works

The four values map to top, right, bottom, and left in that order — the same shorthand pattern used by margin and padding.

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

See how different pixel values change the visual weight of a full border.

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

How It Works

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

🧠 How border-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-style and border-color.

Border setup
3

The browser draws each border side

One value sets the same thickness on all four sides. Multiple values let you mix widths per edge.

All sides
=

Sized border frame

Your element gets a visible border with the thickness you chose on each side.

Universal Browser Support

The border-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 border widths on every platform

Chrome, Firefox, Safari, Edge, and Opera all support border-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-width property 100% supported

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

Conclusion

The border-width property is a fundamental tool for controlling the visual thickness of element borders on a web page. Whether you need a thin line to subtly separate content or a thick border to make an element stand out, this property gives you the flexibility to achieve the desired effect.

Experiment with keyword values like thin and thick, or use exact lengths such as 2px and 5px, to find the best fit for your design.

💡 Best Practices

✅ Do

  • Use 1px or 2px for subtle UI frames on cards and form fields
  • Pair width with border-style and border-color for predictable results
  • Use four-value shorthand when each side needs a different thickness
  • Use the border shorthand when setting width, style, and color together
  • Use rem when you want thickness to scale with root font size

❌ Don’t

  • Set width alone and forget a visible border style
  • Rely on medium when you need exact pixel control
  • Use very thick borders everywhere in minimal UI designs
  • Mix border-width shorthand with conflicting side longhands without a plan
  • Forget that width alone does not make a border visible

Key Takeaways

Knowledge Unlocked

Five things to remember about border-width

Use these points when sizing borders around any element.

5
Core concepts
⚙️02

medium Default

Browser default size.

Default
📏03

thin / thick

Quick keywords.

Values
📝04

px / em / rem

Exact lengths.

Units
🔄05

Shorthand

Per-side control.

Pattern

❓ Frequently Asked Questions

The border-width property sets the thickness of the border on all four sides of an element. You can use one value for every side or up to four values for top, right, bottom, and left.
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-style such as solid and usually a color, or use the border shorthand.
One value applies to all sides. Two values set top/bottom and right/left. Three values set top, right/left, and bottom. Four values set top, right, bottom, and left in that order.
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-width, and preview 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