Overview
A CSS outline is a line that is drawn around elements, outside the borders, prior to the margin, to give the element additional visibility to the user.
For example, the text element below has a red, dotted, 5px outline applied to it.
div {
outline: red dotted 5px;
}
This element (text) has a 5px red outline on all four sides, outside of the black border.
Note
The outline is NOT calculated into the size of an element and may actually overlap the margin, or if there’s no margin, other elements next to it.
Outline Properties
- CSS – outline PropertyThe outline property is a shorthand property for outline-width, outline-style, and outline-color. It draws a line around elements outside any borders.
- CSS – outline-color PropertyThe outline-color property specifies the color of an outline, a drawn line around elements outside any borders.
- CSS – outline-offset PropertyThe outline-color property specifies the color of an outline, a drawn line around elements outside any borders.
- CSS – outline-style PropertyThe outline-style property specifies the style of an outline drawn around an element.
- CSS – outline-width PropertyThe outline-width specifies the width of an outline drawn around an element.
CSS Notes:
- The “inherit”, “initial” and “unset” keywords can be used with any CSS property to set its value
- In CSS there are many ways to express a color value in a property
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.