🚨 $100K in Sight: Follow Bitcoin’s Final Push Live! TRACK NOW

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
DataCamp
Pros
  • Easy to use with a learn-by-doing approach
  • Offers quality content
  • Gamified in-browser coding experience
  • The price matches the quality
  • Suitable for learners ranging from beginner to advanced
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid Certificates of completion
edX
Pros
  • A wide range of learning programs
  • University-level courses
  • Easy to navigate
  • Verified certificates
  • Free learning track available
Main Features
  • University-level courses
  • Suitable for enterprises
  • Verified certificates of completion

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

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

Mobile browser support

Browser image
Chrome
18+
Browser image
Firefox
4+
Browser image
Opera
10.1+
Browser image
Safari
3.1+