Search⌘ K

Setting Up Borders

Explore how to configure borders around HTML elements using CSS. Understand the use of shorthand and individual properties for border color, width, and style. Learn to customize each edge and apply rounded corners with border-radius to enhance design flexibility.

We'll cover the following...

A border is simply a line that runs around an element, and it can be rounded at the corners.

You can use the border shorthand notation to set all edges of the box, or use border-top, border-right, border-bottom, or border-left to specify the properties of a particular edge. When setting up the edges of the border, you can specify three individual properties: color, width, and style.

To make the setup a bit more complicated, you can specify these attributes with other notations.

For example, you can specify the border width of all edges with border-width:

NAME_
CSS
h1 { border-width: 4px; }

Similarly, you can use the border-color, and border-style properties:

NAME_
CSS
h2 {
border-style: dotted;
border-color: fuchsia;
}

If you want, you can specify any of these attributes for a specific edge. For example, you can set the color of the left border to red:

NAME_
CSS
h3 { border-left-color: red; }

When ...