Search
Close this search box.
Course Content
CSS Basic
0/1
CSS Selectors
0/1
CSS Comments
0/1
CSS Backgrounds
0/1
CSS Borders
0/1
CSS Outline
0/1
CSS Fonts
0/1
CSS Height and Width
0/1
CSS Margins and Paddings
0/2
CSS Icons
0/1
CSS Links
0/1
CSS Lists
0/1
CSS Tables
0/1
CSS Display Properties
0/1
CSS Max-Width Property
0/1
CSS Positioning Elements
0/1
CSS Z-Index Property
0/1
CSS Overflow
0/1
CSS Float
0/1
CSS Opacity
0/1
CSS Forms
0/1
CSS Dropdowns
0/1
CSS Buttons
0/1
CSS Media Queries
0/1
About Lesson

Definition:

The outline property in CSS is used to set the style, color, and width of an outline around an element. It is often used to highlight an element on the page. The outline property is similar to the border property but is not a part of the box model, so it doesn’t affect the layout of the document.

Syntax:

selector{

outline: outline-color outline-style outline-width;

}

  • outline-color: Specifies the color of the outline. It can be a color name, a hexadecimal value, a RGB value, or the invert keyword.

  • outline-style: Specifies the style of the outline, such as dotted, dashed, solid, double, etc.

  • outline-width: Specifies the width of the outline. It can be a specific value (e.g., 2px), or one of the predefined values (thin, medium, thick).

Example:

<!DOCTYPE html>
<html lang=”en”>
<head>
    <meta charset=”UTF-8″>
    <meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
    <title>Text Formatting</title>
    <style>
.outlined {
      width: 200px;
      height: 100px;
      background-color: lightblue;
      margin: 20px;
      padding: 10px;
      /* outline shorthand property: outline-color outline-style outline-width; */
      outline: 2px solid red;
    }
    </style>
</head>
<body>
    <div class=”outlined”>
        This is an element with an outline.
      </div>
   
</body>
</html>

Output:

In this example, a div element with the class outlined is styled with a light blue background. The outline property is used to create a red solid outline around the element with a width of 2px. You can modify the values of outline-color, outline-style, and outline-width to achieve different outline effects based on your design preferences.