CSS Properties

Border

The CSS property border can be used to add border to an element. We can specify a common border for the entire element on all sides, but we also have the option of specifying borders invividually for each side of the default rectangular HTML elements.

Common attributes

AttributeDescriptionRequired
stylethe style of the border (none, solid, dotted, dashed, double, groove, ridge, inset, outset)yes (defaults to none)
widththe width of the border [length unit]no (defaults to medium)
colorthe color of the border [color]no (defaults to the current color of the element)

Code example: shorthand

.all-style {
border: solid;
}
.all-style-color {
border: dotted red;
}
.all-width-style {
border: 1em solid;
}
.all-width-style-color {
border: 1em double #d32f2f;
}

which produces

.all-style
.all-style-color
.all-width-style
.all-width-style-color

Code example: extended

.rainbow {
/* top right bottom left */
border-width: 0.2em 0.4em 0.6em 0.8em;
border-color: red orange yellow green;
border-style: solid dashed double dotted;
}

which produces

.rainbow

By using the extended properties we can specify borders for each side in more detail.

Code example: border radius

We can round out our sharp corners with a CSS property called border-radius.

.rounded {
border: 0.5em solid black;
/* all equivalent */
/* all sides */
border-radius: 1em;
/* top/bottom right/left */
border-radius: 1em 1em;
/* top right bottom left */
border-radius: 1em 1em 1em 1em;
}

which produces

.rounded

Read more on MDN

border

Test yourself

Description

Add the class

black-border

to the .quote <div> element. Remember that we can add multiple classes to the same element by separating them with spaces.

All relevant rules and declarations have been defined for you.

Tests

  1. 1 Your <div> element should have the class black-border appended to it.
  2. 2 Your <div> element should still have the class quote.
Editor
Preview