Free beginner tutorial

CSS Borders, Rounded Corners and Outlines

Borders define the edge of an element, rounded corners soften its shape, and outlines can highlight focus without changing layout. Learn the properties and when each one is useful.

Quick answer: Use the border shorthand to set a line's width, style and color. Use border-radius for rounded corners. Use outline for a visible focus indicator around an interactive control; unlike a border, it does not take up layout space.

Set a border with the shorthand

A visible border needs a width, a line style and a color. The order of the values can vary. If you omit the style, its initial value is none, so no border is drawn.

.notice {
  border: 2px solid #315a78;
  padding: 1rem;
}

Common line styles include solid, dashed, dotted and double. Keep decorative borders subtle so they support the content rather than compete with it.

Style one side or use logical sides

Use a side property when only one edge needs emphasis. Logical properties describe the start or end of a line or block, so they adapt to different writing directions more naturally than physical left and right properties.

.callout {
  border-inline-start: 4px solid #a74800;
  padding-inline-start: 1rem;
}

For a simple top divider, border-block-start can be more adaptable than border-top when the page may use a different writing mode.

Round corners with border-radius

The border-radius property rounds the corners of an element's border box. One value rounds every corner; multiple values let you set corners individually.

.card {
  border: 1px solid #dce3eb;
  border-radius: 12px;
  padding: 1.25rem;
}

.pill {
  border-radius: 999px;
}

A very large radius is useful for a pill shape when the element's height can change. Keep the text and shape comfortable at different font sizes and zoom levels.

Understand border and box sizing

A border adds to the rendered size of an element under the default content-box sizing model. With border-box, the declared width includes the content, padding and border, which often makes component dimensions easier to manage.

* {
  box-sizing: border-box;
}

Learn more about content, padding and sizing in the CSS box model lesson.

Use an outline for keyboard focus

An outline is drawn outside the border and does not change an element's layout size. It is often used to make keyboard focus visible. Do not remove a browser's focus indicator unless you replace it with a clearly visible style.

a:focus-visible,
button:focus-visible {
  outline: 3px solid #a74800;
  outline-offset: 3px;
}

Test the focus color against the surfaces around the control. A visible indicator helps people who navigate with a keyboard understand where the next action will happen.

Common border mistakes

  • Forgetting a line style, which leaves the border invisible.
  • Using many heavy borders that make a page feel crowded.
  • Removing focus outlines without adding another visible keyboard-focus treatment.
  • Choosing a border color that is difficult to distinguish from the page background.

Frequently asked questions

What is the difference between a border and an outline?

A border is part of an element's box and can affect its measured size. An outline is drawn outside the border and does not take up layout space. Outlines are useful for focus indicators.

Why is my CSS border not showing?

Check that the selector matches the element and that the border has a visible style such as solid. A width and color alone do not display a border when the style is still none.

How do I make a circle with CSS?

Give an element equal width and height, then set border-radius: 50%. If the dimensions differ, the shape will be an oval.

For exact syntax and browser details, read MDN's references for the CSS border property, border-radius and outline.

Practice: Add a border to a card, round its corners, then tab to a button and confirm its focus outline remains visible. Try your changes in the HTML and CSS editor.