CSS Borders

The border property draws a line around an element. A border needs three things: a width, a style and a colour.

p {
  border: 2px solid #0073aa;
}
Output in the browser

A paragraph with a 2px solid blue border.


Border style

ValueLook
solidA continuous line
dashedDashes
dottedDots
doubleTwo lines
groove, ridge, inset, outset3D effects
noneNo border
Output in the browser

solid

dashed

dotted

double

A border will not show without a style. border: 2px red; does nothing, because the style is missing.


Width and colour

.box {
  border-width: 3px;
  border-style: solid;
  border-color: tomato;
}

Borders on one side

.box {
  border-bottom: 3px solid navy;
  border-left: 5px solid orange;
}

/* or by value order: top right bottom left */
.box2 {
  border-width: 1px 2px 3px 4px;
}
Output in the browser

Only the bottom and left side have a border.


Rounded borders

Use border-radius. See Rounded Corners.


Summary

  • A border needs width, style and colour: border: 2px solid red;.
  • Use border-top, border-right, border-bottom and border-left for one side.
  • Next: Rounded Corners.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.