The CSS outline properties allow you to define an outline area around an element's box.
An outline is a line that is drawn just outside the border edge of the elements. Outlines are generally used to indicate focus or active states of the elements such as buttons, links, form fields, etc.
The following section describes how to set the style, color, and width of the outline.
An outline looks very similar to the border, but it differs from border in the following ways:
The outline-style property sets the style of an element's outline such as: solid, dotted, etc.
The outline-style property can have one of the following values: none, solid, dashed, dotted, double, inset, outset, groove, and ridge. Now, let's take a look at the following illustration, it gives you a sense of the differences between the outline style types.
The value none displays no outline. The values inset, outset, groove, and ridge creates a 3D like effect which essentially depends on the outline-color value. This is typically achieved by creating a "shadow" from two colors that are slightly lighter and darker than the outline color.
The outline-width property specifies the width of the outline to be added on an element.
Let's try out the following example to understand how it actually works:
The outline-color property sets the color of the outline.
This property accepts the same values as those used for the color property.
The following style rules adds a solid outline of blue color around the paragraphs.
The outline CSS property is a shorthand property for setting one or more of the individual outline properties outline-style, outline-width and outline-color in a single rule.
Let's take a look at the following example to understand how it works:
If the value for an individual outline property is omitted or not specified while setting the outline shorthand property, the default value for that property will be used instead, if any.
For instance, if the value for the outline-color property is missing or not specified when setting the outlines, the element's color property will be used as the value for the outline color.
In the following example, the outline will be a solid green line of 5px width:
But, in the case of outline-style, omitting the value will cause no outline to show at all, because the default value for this property is none. In the example below, there will be no outline:
The outline property is widely used to remove the outline around active links.
The outline property is widely used to remove the outline around active links.
Let's try out the following example and see how it basically works: