CSS border-width Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The border-width property is a shorthand that sets the thickness of an element’s border. It covers border-top-width, border-right-width, border-bottom-width, and border-left-width.

Use a keyword (thin, medium, thick) or a length such as 2px. One to four values control which sides share a thickness. It applies to all elements, including ::first-letter, and is not inherited. A width does nothing useful until border-style is a visible style such as solid.

Standard-track.

Not deprecated. Keywords and length values are Baseline and widely available. The newer hairline keyword from CSS Borders Level 4 is still experimental and not safe as a sole value in production yet.

CSS Syntax

syntax.css
border-width: <line-width>{1,4} | initial | inherit;

Use one to four non-negative lengths or keywords. One value sets every side; four values go top, right, bottom, left.

Property Values

ValueDescriptionTry it
thinThin line. Typically about 1pxTry it
mediumDefault thickness. Typically about 3pxTry it
thickThick line. Typically about 5pxTry it
<length>Exact size such as 4px on all sidesTry it
Two valuesTop/bottom, then left/rightTry it
Four valuesTop, right, bottom, left (clockwise)Try it
initialResets each side to mediumTry it
inheritTakes the parent’s border-widthTry it

How to Use border-width

Set a visible style first, then choose how thick each side should be.

  1. Set border-style to something visible, such as solid.
  2. Set border-width to a keyword or length. Use one value for every side, or more values when sides differ.
  3. Optionally set border-color, or use the border shorthand for width, style, and color together.
  4. Prefer side longhands such as border-top-width when only one edge must change.
PieceRequired?Role
Visible styleYes (to show)Without a style other than none, nothing paints
Width value(s)YesKeyword or length. medium is the initial
ColorOptionalDefaults to the element’s color if omitted
1–4 valuesBy designControls which sides share the same thickness

Live Preview

The box already has a solid blue border. Change only border-width.

Style and color stay fixed. Only the width shorthand changes.

Box

border-width: 4px

CSS Examples

Each snippet focuses on border-width. Style and color are only there so the line can show. Use Try It Yourself for a live editor.

Example 1 — One Value for All Sides

Set the same thickness on every edge.

CSS
<style>
  div {
    border-width: 4px;
    border-style: solid;
    border-color: #2563eb;
  }
</style>

<div>4px on all sides</div>
Try It Yourself

How It Works

  1. Set the width. border-width: 4px applies four pixels to every side.
  2. Give it a style. border-style: solid draws the line. Without this, the default none hides the border.
  3. Pick a color. Blue paints the stroke so the thickness is easy to see.
  4. One value, four sides. A single length is the most common beginner pattern.

Example 2 — Thick Keyword

Use thick when you want a heavier line without picking a pixel value.

CSS
<style>
  div {
    border-width: thick;
    border-style: solid;
    border-color: #2563eb;
  }
</style>

<div>Thick border</div>
Try It Yourself

How It Works

  1. Use a keyword. thick is usually about 5px. thin and medium are the lighter options.
  2. Keep style visible. solid is still required so the thick line paints.
  3. Color the box. The blue stroke makes the heavier edge clear.
  4. Prefer lengths for UI polish. Keywords are quick. Exact px or rem values are better when design specs matter.

Example 3 — Different Widths Per Side

Two values set top/bottom first, then left/right.

CSS
<style>
  div {
    border-width: 2px 8px;
    border-style: solid;
    border-color: #2563eb;
  }
</style>

<div>Thin top/bottom, thick sides</div>
Try It Yourself

How It Works

  1. Write two lengths. 2px 8px is a two-value shorthand.
  2. First value = top and bottom. Those edges become 2px.
  3. Second value = left and right. Those edges become 8px.
  4. Need four different sides? Use four values in clockwise order: top, right, bottom, left.

Edge Cases & Pitfalls

If the border is missing or looks wrong, check these first.

style

Width without style stays invisible

The default border-style is none. Set solid, dashed, or another visible style, or use the border shorthand.

0

0 removes the painted edge

border-width: 0 is valid and draws no visible line, even if style and color are set. Negative lengths are invalid.

order

Remember the value order

Two values are top/bottom then left/right. Four values are top, right, bottom, left. Mixing them up is a common source of uneven boxes.

box

Thickness affects layout size

With the default content-box sizing, thicker borders make the element larger. box-sizing: border-box keeps the outer size stable.

hairline

hairline is experimental

The Level 4 hairline keyword means a just-visible line. Support is incomplete, so prefer 1px or thin for production.

Browser Support

border-width is a browser CSS property for the box model. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

border-width

Chrome 1+, Firefox 1+, Safari 1+, Edge 12+, Internet Explorer 4+. Keywords and length values are long-established.

99% Global support
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera 3.5+
Full support
Samsung Internet 1+
Full support
Internet Explorer 4+
Full support
border-width Widely supported

Bottom line: Safe to use everywhere for thin, medium, thick, and length values. Treat hairline as experimental until browser support catches up.

Key Takeaways

  • Role: shorthand for border thickness on all four sides.
  • Needs style: pair with a visible border-style, or use border.
  • 1–4 values: all sides, top/bottom + left/right, three-value, or clockwise four-value.
  • Initial value: medium per side. Not inherited.

One line: border-width is the thickness dial — turn on style (and color) so the dial has something to draw.

Frequently Asked Questions

It is a shorthand that sets the thickness of the border on all four sides. One value applies everywhere; up to four values set top, right, bottom, and left.
Width alone is not enough when border-style is none, which is the default. Set a visible style such as solid, and usually a color, or use the border shorthand.
Each side starts at medium, which is typically about 3px. The border still stays hidden until you also set a visible border-style.
One value: all sides. Two: top/bottom, then left/right. Three: top, left/right, bottom. Four: top, right, bottom, left (clockwise).
They are keyword sizes. In practice they map to about 1px, 3px, and 5px. For exact control, use a length such as 2px or 0.25rem.
It is Baseline and widely available: Chrome 1+, Firefox 1+, Safari 1+, Edge 12+, and Internet Explorer 4+. It is a browser style property, not a Node.js, Deno, or Bun feature.

Next: bottom

Offset a positioned element from the bottom edge of its containing block.

bottom tutorial →

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.

8 people found this page helpful