Code has been added to clipboard!

The Outline CSS Property

Reading time 1 min
Published Sep 26, 2019
Updated Oct 1, 2019

Defining the outline in CSS

To draw an outline around an element, you need to use the outline CSS property:

Example
p {
    border: 2px solid gray;
    outline: 6px dotted blue;
}

CSS outline property syntax

This property is actually a shorthand for three subproperties that define an outline in CSS:

  • outline-width
  • outline-style
  • outline-color

As with all CSS shorthands, you need to omit the names of the subproperties and only list their values:

outline: width style color;

Subproperty Default value Definition
outline‑width medium CSS outline thickness defined in keywords (thin, medium, or thick) or length units
outline‑style none CSS outline style defined in keywords (auto, none, dotted, dashed, solid, double, groove, ridge, inset, or outset)
outline‑color currentColor or invert CSS outline color defined in keywords (currentColor, or invert), color names, RGB, RGBA, HEX, HSL or HSLA values

Border and outline in CSS

An outline is similar to a border – however, there are a few differences. Unlike borders, outlines do not take up space in CSS. They also don't have to be rectangle-shaped.

One element can have both a border and an outline in CSS. You can specify the offset between them by using the outline-offset property:

Example
div {       
    border: 1px solid green;       /* Set border properties */
    outline: 1px solid hotpink;       /* Set outline properties */
    outline-offset: 15px;        /* Set the distance between the outline and border*/
}

Browser support

Chrome
1+
Edge
12+
Firefox
1.5+
IE
8+
Opera
7+
Safari
1.2+

Mobile browser support

Chrome
18+
Firefox
4+
Opera
10.1+
Safari
3.1+
Tutorial
CSS3 Features
Syntax
Classes
ID Selectors
Attribute Selectors
Stylesheets
Inline
Internal
External
Box Model
Children Selectors
Pseudo Classes
Pseudo Elements
Variables
Counters
Text
Fonts
Web Fonts
Backgrounds
Background Images
Colors
Gradients
Opacity / Transparency
Shadow Effects
Transitions
Tooltip
Transform
Animations
Layout — Display
Layout — Position
Layout — Float
Layout — Clear
Layout — Horizontal & Vertical Align
Multiple Columns
Introduction
Responsive Web Design — Viewport
Responsive Web Design — Grid View
Responsive Web Design — Media Queries
Responsive Web Design — Flexbox Layout
Responsive Web Design — Images
Responsive Web Design — Videos
Borders
Margin
Padding
Width
Height
Outline
Links
Lists
Tables
Dropdown Menu
Navigation Bar
Images
Image Gallery
Border Images
Forms
Rounded Corners
Buttons
Box-Sizing
Selector Reference
Pagination Examples
Code Examples
CSS3 Browser Support Reference
Functions Reference
Speech Module Reference
Units
Web Safe Font Combinations
Cheat Sheet
:hover
@font-face
@keyframes
@media
align-content
align-items
align-self
all
animation
backface-visibility
background
background-clip
background-color
background-image
background-origin
background-position
background-size
border
border-image
border-radius
border-style
box-shadow
box-sizing
color
columns
filter
flex
flex-basis
flex-direction
flex-flow
flex-grow
flex-shrink
flex-wrap
font
font-family
font-size
font-size-adjust
font-stretch
font-style
font-weight
hanging-punctuation
justify-content
line-height
margin
offset
opacity
order
outline
overflow
padding
perspective
position
resize
tab-size
text-align
text-decoration
text-emphasis
text-transform
text-shadow
transform
transition-property
translate
vertical-align
word-break
word-wrap
z-index