CSS outline
The CSS outline
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 declaration. It is used to draw a line around elements outside the border edge to make them stand out. Outlines do not take up space and do not affect the layout of the document.
1. Outline Style
The outline-style
property specifies the style of the outline. It can take the following values: none
, solid
, dotted
, dashed
, double
, groove
, ridge
, inset
, and outset
.
Example:
In this example, a solid blue outline with a width of 2px is applied to the heading.
2. Outline Width
The outline-width
property specifies the width of the outline. It can take values like thin
, medium
, thick
, or a specific size (e.g., px
, em
).
Example:
Here, a solid red outline with a width of 5px is applied to the paragraph.
3. Outline Color
The outline-color
property sets the color of the outline. It can take any color value, such as color name
, hex value
, rgb value
, rgba value
, etc.
Example:
In this example, a green dotted outline with a width of 3px is applied to the button.
4. Shorthand Outline Property
The outline
shorthand property sets all the outline properties in a single declaration: outline: [outline-width] [outline-style] [outline-color];
.
Example:
Here, a purple dashed outline with a width of 4px is applied to the div element using the shorthand property.
5. Outline Offset
The outline-offset
property adds space between the outline and the edge or border of an element. This property is helpful for creating some visual separation.
Example:
In this example, an orange solid outline with a width of 3px is applied to the div element, and it is offset by 10px from the border of the element.
This tutorial covers the basics of the CSS outline
property. For more tutorials and examples, visit codeswithpankaj.com.
Last updated