Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Web Development - CSS Borders


CSS Borders

Borders outline elements and help separate sections visually. You can control a border's style, width, color, corners, and more.


Border Style

Use the border-style property to set the line style.

Example

Common border styles:

.box1 { border-style: solid; }
.box2 { border-style: dashed; }
.box3 { border-style: dotted; }
.box4 { border-style: double; }
.box5 { border-style: groove; }
.box6 { border-style: ridge; }
.box7 { border-style: inset; }
.box8 { border-style: outset; }
Try it Yourself »

Tip: A border will not show without a style. Width or color alone is not enough.


Border Width and Color

Use border-width and border-color to control thickness and color.

Example

Width and color:

.card {
  border-style: solid;
  border-width: 2px;
  border-color: #333;
}
Try it Yourself »

You can use keywords like thin, medium, thick, or specific units like px.


Border Shorthand

Combine width, style, and color in one declaration with just using border.

Example

Shorthand border:

.card { border: 2px solid #333; }
Try it Yourself »

Individual Sides

You can style each side using border-top, border-right, border-bottom, and border-left.

Example

Different borders per side:

.box {
  border-top: 4px solid #4caf50;
  border-right: 4px dashed #f44336;
  border-bottom: 4px dotted #2196f3;
  border-left: 4px double #ff9800;
}
Try it Yourself »

Rounded Corners

Use border-radius to round the corners of a border.

Example

Rounded corners:

.card {
  border: 2px solid #333;
  border-radius: 8px;
  padding: 12px;
}

.pill {
  border: 2px solid #333;
  border-radius: 9999px;
  padding: 8px 16px;
}
Try it Yourself »

You can set one to four values: border-radius: 10px 20px 10px 20px; affects each corner clockwise.


Circle and Avatar Images

Make perfectly round images by setting width and height equally and using border-radius: 50%;.

Example

Circle image avatar:

img.avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 3px solid #fff;
}
Try it Yourself »

Outline vs Border

outline draws outside the border and does not take space. It is often used for focus states.

Example

Outline on focus:

button {
  border: 2px solid #333;
}

button:focus {
  outline: 3px solid #4caf50; /* outside the border */
  outline-offset: 2px; /* gap between border and outline */
}
Try it Yourself »

Accessibility tip: Do not remove focus outlines without providing a clear replacement.


Border Image

You can draw borders using an image with border-image.

Example

Border from an image:

.frame {
  border: 12px solid transparent;
  border-image: url('border.png') 30 round;
}
Try it Yourself »

Best Practices

  • Use shorthand border for simple cases.
  • Use individual sides to create visual accents.
  • Prefer border-radius for rounded UI elements and avatars.
  • Keep borders subtle to maintain readability of content.

Next, you'll learn about CSS Spacing (Margins and Padding) - the spacing around and inside elements.

Next » CSS Spacing


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.