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
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
Coursera
Pros
  • Professional service
  • Flexible timetables
  • A variety of features to choose from
Main Features
  • Professional certificates of completion
  • University-level courses
  • Multiple Online degree programs
Datacamp
Pros
  • Great user experience
  • Offers quality content
  • Very transparent with their pricing
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable

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+

Latest Udacity Coupon Found:

Verified STAFF PICK

75% OFF COURSES

Udacity Black Friday Offer

The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!

Expiration date: 19/01/2021
3176 People Used
Only 97 Left
Rating
5.0