CSS outline is a property that allows you to add an outline to an HTML element, which is similar to a border, but it doesn’t take up any space or affect the layout of the element. Outlines are often used to highlight or focus on an element, and can be useful for accessibility purposes.
The syntax for the outline
property is as follows:
outline: [outline-width] [outline-style] [outline-color];
Here’s a breakdown of the different parts of the outline
property:
outline-width
: This sets the width of the outline. It can be specified in pixels, ems, or other length units. The default value ismedium
.outline-style
: This sets the style of the outline, such as solid, dashed, dotted, double, groove, ridge, inset, or outset. The default value isnone
.outline-color
: This sets the color of the outline. It can be specified in any valid CSS color format. The default value is the current color of the element.
Here’s an example of how to use the outline
property in CSS:
h1 {
outline: 2px solid red;
}
In this example, the h1
element will have a red outline that is 2 pixels wide and has a solid style. The outline will be drawn outside the border of the element, but will not affect the layout or positioning of the content inside the element.
It’s worth noting that the outline
property is separate from the border
property in CSS. While borders are part of the box model and affect the layout of the element, outlines are purely visual and do not affect the position or size of the element.