Outline in CSS

Outline is a line around the element, located outside the border to highlight the element.

Outline in CSS Picture 1
Illustrate the outline in the element

CSS has the following characteristics:

  1. outline-style
  2. outline-color
  3. outline-width
  4. outline-offset
  5. outline

Note : Outline is different from Border in CSS. The outline is drawn to the right of the element border and can overlap other content. In addition, the outline is not part of the element size. Element width and height are not affected by outline width.

Style of outline

The outline-style determines the style of the outline, having one of the following values:

  1. dotter - dotted line
  2. dashed - dashed line
  3. solid - straight lines
  4. double - double line
  5. groove
  6. ridge
  7. inset
  8. outset
  9. none - no borders
  10. hidden - hidden border
 p.dotted {outline-style: dotted;} 
p.dashed {outline-style: dashed;}
p.solid {outline-style: solid;}
p.double {outline-style: double;}
p.groove {outline-style: groove;}
p.ridge {outline-style: ridge;}
p.inset {outline-style: inset;}
p.outset {outline-style: outset;}

Below is a picture of how these values ​​are displayed in the browser.

Outline in CSS Picture 2
Some properties depend on values ​​that have different levels

Note: The ouline properties are only effective when using the outline-style.

The color of the outline

The outline-color is used to select outline colors. Colors can be chosen according to:

  1. name: Specific name like 'red' .
  2. RGB: RGB value like 'rgb (255, 0, 0)'
  3. HEX: HEX value like # ff0000 .
  4. invert: Reverse the color (invert) to make sure the outline is visible no matter what the background color is

Below are examples of different outline colors, noting that the elements also have a thin black border on the outline.

 p.ex1 { 
border: 1px solid black;
outline-style: solid;
outline-color: red;
}

p.ex2 {
border: 1px solid black;
outline-style: double;
outline-color: green;
}

p.ex3 {
border: 1px solid black;
outline-style: outset;
outline-color: yellow;
}

Outline in CSS Picture 3
Color example of outline in CSS

Here is an outline-color: invert, creates a reverse color so that outline can be seen no matter what color the background is.

 p.ex1 { 
border: 1px solid yellow;
outline-style: solid;
outline-color: invert;
}

Outline in CSS Picture 4
Reverse color with outline-color: invert feature

Outline of outline

The outline-width defines the width of the outline, there may be one of the following values:

  1. thin (usually 1 px)
  2. average (usually 3px)
  3. thick (usually 5px)
  4. specific sizes (in, px, pt, cm, em .)

The example below shows some outline lines with different widths.

 p.ex1 { 
border: 1px solid black;
outline-style: solid;
outline-color: red;
outline-width: thin;
}

p.ex2 {
border: 1px solid black;
outline-style: solid;
outline-color: red;
outline-width: medium;
}

p.ex3 {
border: 1px solid black;
outline-style: solid;
outline-color: red;
outline-width: thick;
}

p.ex4 {
border: 1px solid black;
outline-style: solid;
outline-color: red;
outline-width: 4px;
}

Outline in CSS Picture 5
The outline-width feature defines the width of the outline

Shortened feature of outline

The feature shortens the outline of bringing all other features into one feature, including:

  1. outline-width
  2. outline-style (required)
  3. outline-color

The outline feature is defined by 1, 2 or 3 values ​​above, the order is not important. Here are some examples of outline outline properties.

 p.ex1 {outline: dashed;} 
p.ex2 {outline: dotted red;}
p.ex3 {outline: 5px solid yellow;}
p.ex4 {outline: thick ridge pink;}

Outline in CSS Picture 6
Outline image display on the browser

Outline-offset feature

The outline-offset adds a space to the middle of the outline and the border / border of an element. The space between the element and its outline is transparent. Below is an example with an ouline located outside border 15px.

 p { 
margin: 30px;
border: 1px solid black;
outline: 1px solid red;
outline-offset: 15px;
}

Outline in CSS Picture 7
Create the gap between the outline and the border of the element

The example below shows the space between an element and its outline is transparent.

 p { 
margin: 30px;
background: yellow;
border: 1px solid black;
outline: 1px solid red;
outline-offset: 15px;
}

Outline in CSS Picture 8
The white space is between the outline and the element

Previous article: Box Model in CSS

The following article: Text in CSS

4.3 ★ | 3 Vote

May be interested

  • Top 5 best Mindmap softwareTop 5 best Mindmap software
    top 5 best mindmap software. mind mapping is a smart way of working and learning, so you can outline ideas in your work and study in branches and make it easy to observe and manage them well. than.
  • How to Write PseudocodeHow to Write Pseudocode
    this wikihow teaches you how to create a pseudocode document for your computer program. pseudocode essentially entails creating a non-programming language outline of your code's intent.https://whatis.techtarget.com/definition/pseudocode...
  • How to Convert a JPEG to a Silhouette Cut‐OutHow to Convert a JPEG to a Silhouette Cut‐Out
    if you find yourself in need of stencils, decorative outlines, or a background-free cut-out of an image, don't fret! you can easily create a cut-out from your favorite jpeg using silhouette--a free photo editing service for both mac and...
  • How to Buy RAM for Your iMacHow to Buy RAM for Your iMac
    when buying random access memory (ram) for your imac computer, you must first determine the type of ram or memory that is compatible with your specific model of imac. all imacs require the use of small outline dual inline memory modules...
  • How to Write a Test PlanHow to Write a Test Plan
    test plans outline the process of testing the functionality of software. a test plan details each step taken to achieve a certain result and states the objective of each action. the plan also highlights the projected resources, risks, and...
  • What is UPnP? Why should you disable it on your router?What is UPnP? Why should you disable it on your router?
    upnp is a network protocol (or set of network protocols). these protocols outline a specific communication method that all kinds of devices can use to instantly communicate with each other on a network.
  • What is UPnP?What is UPnP?
    upnp is a network protocol (or a set of network protocols). these protocols outline a specific communication method that every device can use to communicate instantly with each other on the network.
  • How to Disable Avira on PC or MacHow to Disable Avira on PC or Mac
    this wikihow teaches you how to disable or uninstall avira security products for windows or macos right-click on the avira icon in the system tray. it's a red icon with an outline of a white umbrella. you'll usually find it to the left of...
  • How to Make a Whale on Apple MessagesHow to Make a Whale on Apple Messages
    this wikihows teaches you how to use the outline of an apple messages bubble to send a cute whale to your friends. open a conversation in messages. you can use messages on your iphone, ipad, or ipod touch to send a whale.
  • India created an outline on shale to set the world's highest recordIndia created an outline on shale to set the world's highest record
    hundreds of people in the indian capital have set a world record together by drawing a picture on a giant slate.