It’s Festive Season! Enjoy 30% Off

Use code FESTIVE30 at checkout

Code has been added to clipboard!

The Outline CSS Property

Reading time 1 min
Published Sep 26, 2019
Updated Oct 1, 2019

Defining the outline in CSS

To draw an outline around an element, you need to use the outline CSS property:

Example
p {
    border: 2px solid gray;
    outline: 6px dotted blue;
}

CSS outline property syntax

This property is actually a shorthand for three subproperties that define an outline in CSS:

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

As with all CSS shorthands, you need to omit the names of the subproperties and only list their values:

outline: width style color;

Subproperty Default value Definition
outline‑width medium CSS outline thickness defined in keywords (thin, medium, or thick) or length units
outline‑style none CSS outline style defined in keywords (auto, none, dotted, dashed, solid, double, groove, ridge, inset, or outset)
outline‑color currentColor or invert CSS outline color defined in keywords (currentColor, or invert), color names, RGB, RGBA, HEX, HSL or HSLA values

Border and outline in CSS

An outline is similar to a border – however, there are a few differences. Unlike borders, outlines do not take up space in CSS. They also don't have to be rectangle-shaped.

One element can have both a border and an outline in CSS. You can specify the offset between them by using the outline-offset property:

Example
div {       
    border: 1px solid green;       /* Set border properties */
    outline: 1px solid hotpink;       /* Set outline properties */
    outline-offset: 15px;        /* Set the distance between the outline and border*/
}

Browser support

Browser image
Chrome
1+
Browser image
Edge
12+
Browser image
Firefox
1.5+
Browser image
IE
8+
Browser image
Opera
7+
Browser image
Safari
1.2+

Mobile browser support

Browser image
Chrome
18+
Browser image
Firefox
4+
Browser image
Opera
10.1+
Browser image
Safari
3.1+