outline property

Tutorials

Definition and Usage

The CSS outline property is a shorthand property for setting one or more of the individual outline properties outline-styleoutline-width and outline-color in a single rule. In most cases the use of this shortcut is preferable and more convenient.

Outlines differ from borders in the following ways:

  • Outlines do not take up space, they are drawn above the content.
  • Outlines may be non-rectangular. They are rectangular in Gecko/Firefox. But e.g. Opera draws a non-rectangular shape around a construct
  • Initialthe concatenation of the initial values of its longhand properties:
    • outline-color: is itself a shorthand, its initial value is the concatenation of its own longhand properties
    • outline-width: is itself a shorthand, its initial value is the concatenation of its own longhand properties
    • outline-style: is itself a shorthand, its initial value is the concatenation of its own longhand properties
  • Applies toall elements
  • Inheritedno
  • Mediavisual, interactive
  • Computed Valueas each of the properties of the shorthand:
    • outline-color: For the keyword invert, the computed value is invert. For the color value, if the value is translucent, the computed value will be the rgba() corresponding one. If it isn’t, it will be the rgb() corresponding one. The transparent keyword maps to rgb(0,0,0).
    • outline-width: an absolute length; if the keyword none is specified, the computed value is 0
    • outline-style: as specified
  • Animatableas each of the properties of the shorthand:
    • outline-color: yes, as a color
    • outline-width: yes, as a length
    • outline-style: no
  • Canonical orderorder of appearance in the formal grammar of the values

Syntax

Formal syntax: <'outline-color'> || <'outline-width'> || <'outline-style'>

Values

One, two or three values, given in arbitrary order:

<‘outline-width’>
See outline-width.
<‘outline-style’>
See outline-style.
<‘outline-color’>
Since Gecko 1.9 (Firefox 3), the value of the element’s color property (foreground color) is used. See outline-color.

Examples

1 <span style="outline: solid;">outline: solid;</span>
2 <span style="outline: dashed red;">outline: dashed red;</span>
3 <span style="outline: dotted 1px;">outline: dotted 1px;</span>
4 <span style="outline: ridge thick violet;">outline: ridge thick violet;</span>
5 <span style="outline: ridge 5px yellow;">outline: custom 5px;</span>
1 /* two identical declarations */
2 :link:hover { outline1px solid #000; }
3 :link:hover { outlinesolid black 1px; }

Result:

outline: solid;
outline: dashed red;
outline: dotted 1px;
outline: ridge thick violet;
outline: custom 5px;


Compatibility

Desktop browsers

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 1.5 (1.8) 8.0 7.0 1.2 (125)

Mobile browsers

Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 1.0 1.0 (1.8) 8.0 6.0 3.1
Rate article