Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

outline — an element's outline

The outline shorthand sets an outline's thickness, style, and color without changing page layout. It is useful for highlighting keyboard focus, among other purposes.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

outline: <'outline-width'> || <'outline-style'> || <'outline-color'>;

outline sets outline-width, outline-style, and outline-color together. Components can appear in any order; || means at least one is required. Omitted components return to their initial values. The property is not inherited.

Unlike border, an outline takes up no layout space, so it can overlap neighboring elements. It can be nonrectangular and has no separate per-side properties. The independent outline-offset property sets the gap and is not reset by the outline shorthand.

Supply a style such as solid: the initial outline-style: none produces no visible outline. auto leaves the appearance to the browser, making it unsuitable for pixel-identical tests. Do not remove a focus outline using outline: none without an alternative visible highlight.

The example shows a white Continue button with a black border. The solid blue 3px outline appears only when the button matches :focus-visible, such as when you Tab to it. A 4px gap separates the outline from the border.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Outline example</title>
<style>
  body { margin: 32px; background: white; }
  button {
    padding: 8px 16px;
    border: 1px solid black;
    background: white;
    color: black;
  }
  button:focus-visible {
    outline: 3px solid #005fcc;
    outline-offset: 4px;
  }
</style>
<button type="button">Continue</button>
</html>

Result

A white Continue button with a black border. When the button receives keyboard focus, a solid blue 3px outline appears, separated from the border by a 4px gap.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources