CSS Outline


An outline is a line that goes around the outside of an element's border.

This item has a black line around it and a green border that's 10 pixels in width.

CSS Outline

An outline is like a border, but it goes on the outside of an element to make it look more noticeable.

CSS offers various properties that control how the outline of an element is displayed.

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

Note: An outline is not the same as borders. Unlike borders, outlines are drawn outside the element's border and can cover other content. Furthermore, the outline doesn't count as part of the element's size. It doesn't change the element's width or height.


CSS Outline Style

The outline-style property tells us how the outline should look. It can be set to one of these options:

  • dotted - Defines a dotted outline
  • dashed - Defines a dashed outline
  • solid - Defines a solid outline
  • double - Defines a double outline
  • groove - Defines a 3D grooved outline
  • ridge - Defines a 3D ridged outline
  • inset - Defines a 3D inset outline
  • outset - Defines a 3D outset outline
  • none - Defines no outline
  • hidden - Defines a hidden outline

In this example, we demonstrate various styles for outlines using the outline-style attribute.


CSS Outline Width

The "outline-width" property tells us how wide an outline should be. It can be set to one of these values:

  • thin (typically 1px)
  • medium (typically 3px)
  • thick (typically 5px)
  • A specific size (in px, pt, cm, em, etc)

A thin outline.

A medium outline.

A thick outline.

A 4px thick outline.


CSS Outline Color

The outline-color property is used to choose the color for the outline.

You can choose the color using:

  • name - specify a color name, like "red"
  • HEX - specify a hex value, like "#ff0000"
  • RGB - specify a RGB value, like "rgb(255,0,0)"
  • HSL - specify a HSL value, like "hsl(0, 100%, 50%)"
  • "invert" - changes colors so outlines are always seen, no matter the background color.

The example below displays various outlines in different colors. Additionally, observe that these elements contain a slender black border within the outline:

A solid red outline.

A dotted blue outline.

An outset grey outline.


CSS Outline - Shorthand property

The outline property is a quick way to set various outline properties all at once.

  • outline-width
  • outline-style (required)
  • outline-color

The outline property can be set using one, two, or three values from the provided options. The sequence in which you specify these values doesn't affect the outcome.

In this example, you can see various outlines set using the outline property, using shorthand notation.

A dashed outline.

A dotted red outline.

A 5px solid yellow outline.

A thick ridge pink outline.