Borders¶
A border is a line around a box. It has a width, a style, and a colour.
Shorthand¶
This is equivalent to:
A border needs a style. border-width: 1px without solid, dashed, or another style will not show a line.
Individual sides¶
You can use physical sides (top, right, bottom, left) or logical sides:
The logical version follows the writing direction.
Rounded corners¶
Individual corners are also available:
The logical form is border-start-start-radius.
Border or outline?¶
- Border takes up space and affects layout.
- Outline is drawn outside the box, does not affect layout, and is useful for focus states.
Do not remove an outline unless you replace it with an equally visible focus style.
Try it¶
- Add a border to a card and change its width, style, and colour.
- Add a thick border on one side only.
- Try
border-radiuswith a small value and with50%. - Add a focus outline to a button and tab to it with the keyboard.
- Set
outline-offsetto0and then4px. Which is easier to see?
If a border does not appear, check whether the style is missing or the colour matches the background.
Next: Shadows