Smal SEO Tool

CSS Outline

An outline is a line drawn around elements, OUTSIDE the borders, to make the element "stand out".

CSS has the following outline properties:

  • outline-style
  • outline-color
  • outline-width
  • outline-offset
  • outline (shorthand property)

Note: The outline property differs from the border property as the outline is drawn outside the element's border and does not take up space (it is drawn on top of other content).

Example

css
p {
  border: 1px solid black;
  outline-style: solid;
  outline-color: red;
  outline-width: thick;
}

Outline Shorthand

The outline property is a shorthand for setting the outline width, style, and color.

Example

css
p {
  outline: 5px dotted blue;
}

Outline Offset

The outline-offset property adds space between an outline and the edge/border of an element.

Example

css
p {
  margin: 30px;
  border: 1px solid black;
  outline: 2px solid red;
  outline-offset: 15px; /* Creates a 15px gap between the border and the outline */
}

Test Yourself with an Exercise

What is the main difference between an outline and a border?