CSS border Property

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

Definition and Usage

The border property is a shorthand that sets border-width, border-style, and border-color on all four sides at once.

A border only appears when the style is not none. Width defaults to medium and color to currentColor when omitted. For one side only, use border-top and the other side longhands instead.

Baseline · Widely available.

Not deprecated and not experimental. The border shorthand has been supported across browsers since the early days of CSS.

CSS Syntax

syntax.css
border: <line-width> || <line-style> || <color> | initial | inherit;

Write one to three values, in any order. The usual order is width, style, then color: border: 2px solid black;.

Property Values

ValueDescriptionTry it
<line-width>Thickness: a length, or thin, medium, thick. Default mediumTry it
solidA continuous line. Most common styleTry it
dashedA series of short dashesTry it
dottedA series of dotsTry it
doubleTwo parallel lines. Needs enough width to show bothTry it
noneNo border. Initial style. Width and color alone will not showTry it
<color>Border color. Default is currentColorTry it
initialResets to the initial border values (style none)Try it
inheritInherits this property from the parent elementTry it

How to Use border

Pick a style first so the line is visible, then set width and color as needed.

  1. Choose the element that should have a border on every side.
  2. Set a style such as solid, dashed, or dotted. Without a style, nothing draws.
  3. Add a width and color when you want them. Omit them to use medium and currentColor.
  4. Remember: border also resets border-image to none.
PieceRequired?Role
StyleYes (to show a line)Without it, the border stays none and invisible
WidthOptionalDefaults to medium if omitted
ColorOptionalDefaults to currentColor if omitted
Same on all sidesBy designUse side longhands when sides must differ

Live Preview

Change the border shorthand on the box and watch all four sides update together.

Style is required. Width and color are optional parts of the same shorthand.

Box

border: 2px solid #0f172a

CSS Examples

Each snippet focuses on the border shorthand. Use Try It Yourself for a live editor.

Example 1 — Solid Border

Set width, style, and color in one declaration.

CSS
<style>
  div {
    border: 2px solid #0f172a;
    padding: 12px;
  }
</style>

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

How It Works

  1. Pick the box. The rule targets the div that should show a border.
  2. Set the style. solid draws a continuous line. Without a style, nothing appears.
  3. Set the width. 2px is the thickness on every side.
  4. Set the color. #0f172a paints that line. All four sides match because border is a four-side shorthand.

Example 2 — Dashed Border

Use a dashed style with a clear color for emphasis.

CSS
<style>
  div {
    border: 3px dashed #2563eb;
    padding: 12px;
  }
</style>

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

How It Works

  1. Keep the same shorthand shape. Width, style, and color still share one property.
  2. Swap the style. dashed replaces the solid line with short gaps.
  3. Thicken the stroke. 3px makes the dashes easier to see.
  4. Color the dashes. Blue applies to every side the same way solid did.

Example 3 — Double Border

Draw two parallel lines. Give the border enough width so both show.

CSS
<style>
  div {
    border: 6px double #0f766e;
    padding: 12px;
  }
</style>

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

How It Works

  1. Choose double. The browser draws two lines with a gap between them.
  2. Give it room. 6px is wide enough for both lines and the space between.
  3. Set the color. Teal fills both lines.
  4. Same on all sides. The shorthand still applies the effect to top, right, bottom, and left together.

Edge Cases & Pitfalls

If the border disappears or looks wrong, check these first.

style

No style means no border

border: 2px #000 still looks empty because style defaults to none. Always include solid or another style keyword.

image

border resets border-image

The shorthand sets border-image back to none. Declare border-image after border if you need an image border.

size

Borders add to the box by default

With the default content-box sizing, a border grows the element’s outer size. Use box-sizing: border-box to keep width and height inclusive of the border.

sides

One shorthand cannot style sides differently

border paints all four sides the same. For a bottom-only line, use border-bottom or set the longhands separately.

outline

Outline is not a border

outline draws outside the border edge and does not take layout space. Do not swap them when you need box-model size.

Browser Support

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

✓ Baseline · Widely available

border

Supported in all modern browsers and Internet Explorer. The shorthand has been part of CSS since the earliest versions.

100% Universal support
Google Chrome All versions
Full support
Mozilla Firefox All versions
Full support
Apple Safari All versions
Full support
Microsoft Edge All versions
Full support
Opera All versions
Full support
Samsung Internet All versions
Full support
Internet Explorer All versions
Full support
border Widely supported

Bottom line: Safe everywhere for width, style, and color. Prefer the shorthand when all four sides match. It is not a runtime API.

Key Takeaways

  • Role: one shorthand for width, style, and color on all four sides.
  • Style first: without a visible style, width and color do nothing.
  • Resets image: border sets border-image back to none.
  • Not inherited. Defaults: width medium, style none, color currentColor.

One line: border: 2px solid black; draws the same line on every side — after you include a style.

Frequently Asked Questions

It is a shorthand that sets border-width, border-style, and border-color on all four sides in one declaration.
A border needs a visible style. The initial style is none, so width or color alone will not draw a line. Use solid, dashed, dotted, or another style.
You can write width, style, and color in any order. The common pattern is width then style then color, for example border: 2px solid black.
Yes. Using the border shorthand sets border-image back to its initial value (none). Set border-image after border if you need both.
Border is part of the box model and takes up space. Outline is drawn outside the border edge and does not affect layout size.
The border shorthand is Baseline Widely available and works in all modern browsers and Internet Explorer. It is a browser CSS property, not a Node.js feature.

Next: border-block

Set the logical block-start and block-end borders in one go.

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