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.
Fundamentals
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.
Foundation
📝 Syntax
The syntax for border-width accepts keyword values or length units:
syntax.css
selector{border-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.
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.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
medium
Applies to
All four border sides (shorthand for top, right, bottom, left)
Inherited
No
Animatable
Yes, as a length
Common use
Cards, boxes, form fields, frames, and emphasis lines
Defaults
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.
Reference
💎 Property Values
The border-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
Shorthand
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
Compare
border-width vs Side Longhands vs border
Property
Targets
Best for
border-width
Width 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 only
Accenting a single edge without affecting the others
border
Width, style, and color together
Quick one-line borders when all three parts are the same
Preview
👀 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;.
Hands-On
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><divclass="box">
This box has a 5px wide border.
</div>
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.
Compatibility
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 property100% supported
Bottom line: Use border-width freely in any project. It works consistently across all browsers.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about border-width
Use these points when sizing borders around any element.
5
Core concepts
─01
All Sides
One to four values.
Purpose
⚙️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.