{"id":350656,"date":"2021-09-01T10:54:41","date_gmt":"2021-09-01T17:54:41","guid":{"rendered":"https:\/\/css-tricks.com\/?page_id=350656"},"modified":"2022-07-11T09:29:27","modified_gmt":"2022-07-11T16:29:27","slug":"outline-color","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/properties\/o\/outline-color\/","title":{"rendered":"outline-color"},"content":{"rendered":"\n
The We usually set the outline of an element using the shorthand property:<\/p>\n\n\n\n According to specs, If the browser doesn\u2019t support the The following example makes the outline of the button red once it\u2019s focused:<\/p>\n\n\n\n An outline is typically used to indicate focus on elements, which can be useful for non-mouse interactions for accessibility reasons and it can generally benefit all users.<\/p>\n\n\n\n It\u2019s very likely that you would want to change the outline color to match your brand or to make it more noticeable. And this is when Not only we need to ensure that the contrast ratio between the outline color and the background it\u2019s on is high enough to ensure clear visibility, but also in cases where there is no space between the outline and the element \u2014 then we need to check the contrast ratio between the outline color and the background of the element itself.<\/p>\n\n\n\n Non-text UI controls, like buttons, must have a color contrast ratio of at least 3:1 against adjacent colors<\/strong>, according to WCAG Success Criterion 1.4.3<\/a>.<\/p>\n\n\n\n Sara Soueidan explains this very well in her \u201cA guide to designing accessible, WCAG-compliant focus indicators\u201d<\/a> article. You can learn a lot more about WCAG\u2019s contrast ratios and how they\u2019re determined in Stacy Arellano\u2019s deep dive article<\/a>.<\/p>\n\n\n Play with outline properties in the following demo:<\/p>\n\n\n\noutline-color<\/code> CSS property specifies the color of an element’s outline. What\u2019s an outline? An outline<\/dfn> is a line that is drawn around elements \u2014 outside the border edge \u2014 that is used for accessibility or decoration purposes when that element is in focus.<\/p>\n\n\n\n
button {\n outline-color: #e435;\n}<\/code><\/pre>\n\n\n\n
outline-color<\/code> is a constituent property in the
outline<\/code><\/a> shorthand and is defined in the CSS Basic User Interface Module Level 4<\/a> specification which is currently in Editor\u2019s Draft status.<\/p>\n\n\n\n\n\n\n
Usage<\/h3>\n\n\n
a:focus {\n outline: 0.1em solid darkgray;\n}<\/code><\/pre>\n\n\n
Syntax<\/h3>\n\n\n
outline-color: <color>| invert<\/code><\/pre>\n\n\n\n
invert<\/code> (
currentColor<\/code>, in case
invert<\/code> is not supported)<\/li>
invert<\/code>, the computed value is
invert<\/code>. For the color value, if the value is translucent, the computed value will be the
rgba()<\/code> corresponding one. If it isn’t, it will be the
rgb()<\/code> corresponding one. The transparent keyword maps to
rgba(0,0,0,0)<\/code>.<\/li>
Values<\/h3>\n\n\n
\/* Keyword value *\/\noutline-color: invert;\n\n\/* <color> values *\/\noutline-color: #333;\noutline-color: darkorange;\noutline-color: hsl(210,100%,44%);\n\n\/* Global values *\/\noutline-width: initial;\noutline-width: inherit;\noutline-width: unset;<\/code><\/pre>\n\n\n\n
<color><\/code>:<\/strong> Defines the color of the outline and accepts
<rgb()><\/code>,
<rgba()><\/code>,
<hsl()><\/code>,
<hsla()><\/code>,
<hex-color><\/code>,
<named-color><\/code>,
currentcolor<\/code> and
<deprecated-system-color><\/code><\/li>
invert<\/code>:<\/strong> The default value. Specifies an inverted value of the background color of where the outline is rendered, therefore it ensures that the outline is visible.<\/li>
initial<\/code>:<\/strong> Applies the property\u2019s default setting, which is
invert<\/code>.<\/li>
inherit<\/code>:<\/strong> Adopts the
outline-color<\/code> value of the parent.<\/li>
unset<\/code>:<\/strong> Removes the current
outline-color<\/code> from the element.<\/li><\/ul>\n\n\n\n
invert<\/code> value, then the initial value of the
outline-color<\/code> property is the currentColor<\/strong> keyword, but at the time of writing,
invert<\/code> is considered invalid in all modern browsers. You can check the browser support at caniuse<\/a>.<\/p>\n\n\n
Example<\/h3>\n\n\n
button {\n outline-width: 1px;\n outline-style: solid;\n outline-color: gray;\n}\n\nbutton:focus {\n outline-color: red;\n} <\/code><\/pre>\n\n\n
Accessibility<\/h3>\n\n\n
outline-color<\/code> comes in handy. But make sure your custom color meet WCAG\u2019s requirements<\/strong>, particularly Success Criterion 2.4.7<\/a> which details a visible focus state.<\/p>\n\n\n\n
Demo<\/h3>\n\n\n