outline-style
Definition
The outline-style property in CSS is used to set the style of the outline around an element. Outlines are non-rectangular shapes that surround an element and are typically used to indicate focus, active states, or other types of user interactions.
Examples
Set the outline style to dotted:
.example {
outline-style: dotted;
}
Set the outline style to solid:
.example {
outline-style: solid;
}
Set the outline style to double:
.example {
outline-style: double;
}
Values
Value | Description |
---|---|
none | Specifies that no outline should be drawn. This is the default value. |
dotted | Specifies a dotted outline style. |
dashed | Specifies a dashed outline style. |
solid | Specifies a solid outline style. |
double | Specifies a double outline style. |
groove | Specifies a 3D groove outline style, which creates a raised border that appears to be carved into the page. |
ridge | Specifies a 3D ridge outline style, which creates a border that appears to be extruded from the page. |
inset | Specifies a 3D inset outline style, which creates a border that appears to be pressed into the page. |
outset | Specifies a 3D outset outline style, which creates a border that appears to be coming out of the page. |
initial | Resets the property to its default value. |
inherit | Inherits the property from its parent element. |
hidden | Specifies that the outline should be hidden, but still take up space. This can be useful for creating visual effects where an outline is only shown on hover or focus. This value is not supported in Internet Explorer. |
dotted-2px | Specifies a dotted outline style with a 2-pixel gap between dots. This value is not supported in Internet Explorer. |
dashed-2px | Specifies a dashed outline style with a 2-pixel gap between dashes. This value is not supported in Internet Explorer. |
solid-2px | Specifies a solid outline style with a 2-pixel width. This value is not supported in Internet Explorer. |
double-2px | Specifies a double outline style with a 2-pixel width. This value is not supported in Internet Explorer. |
groove-2px | Specifies a 3D groove outline style with a 2-pixel width. This value is not supported in Internet Explorer. |
ridge-2px | Specifies a 3D ridge outline style with a 2-pixel width. This value is not supported in Internet Explorer. |
inset-2px | Specifies a 3D inset outline style with a 2-pixel width. This value is not supported in Internet Explorer. |
outset-2px | Specifies a 3D outset outline style with a 2-pixel width. This value is not supported in Internet Explorer. |
groove-ridge | Specifies a 3D groove-ridge outline style with alternating ridges and grooves. This value is not supported in Internet Explorer. |
ridge-groove | Specifies a 3D ridge-groove outline style with alternating grooves and ridges. This value is not supported in Internet Explorer. |
Best Practices
- Only use outlines for interactive elements, such as links and form inputs. Outlines can be distracting and confusing for non-interactive elements, such as images and paragraphs.
- Use a subtle outline style that doesn't overwhelm the content. A solid or dashed style is usually sufficient.
- Avoid using outline styles that mimic 3D effects, such as groove, ridge, inset, and outset, as they can be confusing for users who rely on assistive technologies.
- Ensure that the outline has sufficient contrast with the background color to be visible for users with low vision.
- Use the hidden value to create visual effects where an outline is only shown on hover or focus, rather than relying on none and changing the border property, which can cause layout shifts.
Browser Compatibility
Chrome | Firefox | Safari | Internet Explorer | Microsoft Edge | Opera |
---|---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes | Yes |