CSS Outline

Styling is not just about making the elements look good, rather be clearly visible while looking good.

One such CSS feature that helps the developer in the “visibility” regard is the outline property.

In simplest terms, outline is essentially a line drawn around the elements (not inside the Borders) to make the element clearly visible on the web-page.

Run

Outlines can also be used to differentiate and element from others on the page.

There are 4 outline properties

  • outline-width
  • outline-style
  • outline-color
  • outline-offset

above combinly outline shorthand property can be created.
Please note, that outline is a separate element in itself.

Unlike the Borders, it is not a part of the box-model for the element it is around and thus, does not affect the actual height and width of that element.

The above-mentioned CSS properties, define different aspects of the outline element as obvious. Let’s take a look at them one by one.

outline-width

The width of the outline can be specified with the following permissible values:
thin (~1px)
medium(~3px)
thick(~5px)
Any specific size

Run

Run

Run

Run

outline-style

This property provides the kind of outline that will be rendered on the web-page.

The allowed values for this are:

dotted |dashed |solid |double |groove| ridge |inset |outset |none|hidden

Run

Run

Run

Run

Here, the values: groove, ridge, inset, and outset are dependent on the outline color for their effects.

Run

Run

Run

Run

Run

Run

outline-color

The allowed values for the colors are:
color name
RGB Code
Hex Code
Invert

Run

Run

Run

Run

The invert, basically, performs a color inversion ensuring the visibility of the outline regardless of the background color.

Try the outline-color as yellow and check if you’re able to differentiate between the above mentioned outline-style values.

outline-offset

This property specifies the space between the outline and the border of the enclosed element. This is a transparent space.

Run

outline (shorthand property)

For the shorthand property you can specify the width, style and color of the outline.

The order of the values doesn’t matter and you can specify one, two or three of these values as per the requirement.

Run