CSS Outline

The CSS outline property is used to set a line around an element, outside the border. Unlike borders, outlines do not take up space and are not affected by padding or margin. They are commonly used for accessibility (e.g., focus indicators) and styling elements with emphasis.

Key Points on CSS Outline:

Syntax for CSS Outline:

Syntax Example

/* Outline shorthand syntax */
        outline: width style color;
                
        /* Example */
        outline: 2px solid red;

Examples of CSS Outline:

The following examples demonstrate how to use different outline properties:

Code Example: Outline

div {
            outline: 3px dashed blue;
        }

Output

This div has a blue dashed outline.

Code Example: Outline Color

div {
            outline-color: green;
        }

Output

This div has a green outline.

Common Outline Properties:

To make the outline more accessible, ensure it is visible and clearly distinct when focusing on elements. Outlines should not be removed entirely for interactive elements like links and form inputs to support keyboard navigation.