CSS Introduction

CSS Tutorial What is CSS CSS Syntax CSS Selector How to include CSS CSS Comments

CSS Attributes

CSS Background CSS Border CSS Display CSS Float CSS Font CSS Color CSS Hover CSS Important CSS Line-height CSS Margin CSS Opacity CSS Filter CSS Images CSS Overflow CSS Padding CSS Position CSS Vertical align CSS White space CSS Width Word-wrap in CSS Box-shadow in CSS Text-transform in CSS CSS Outline CSS Visibility CSS Counters CSS Clear fix CSS Icons CSS Justify-content Text-decoration in CSS CSS Lists CSS nth selector CSS Sticky CSS Background-clip CSS Checkbox-style CSS Letter-spacing CSS Navigation bar CSS Overlay CSS Root CSS Specificity CSS Text-indent CSS Text-stroke CSS Zoom CSS Order CSS Descendent selector CSS Clip CSS calc() CSS Background-blend-mode CSS radio-button CSS Superscript and subscript CSS Text-effects CSS Text-align CSS Variables CSS Page-break-before CSS Page-break-inside CSS Page-break-after CSS Content property CSS Word-spacing CSS Animation CSS @keyframes rules CSS Pseudo-classes CSS Pseudo-elements CSS Radial-gradient CSS Translate CSS Gradients CSS z-index CSS Loaders CSS Units CSS Transition CSS Masking CSS Arrow CSS Pagination

Questions

What is Bootstrap CSS What is CSS used for How to center a table in CSS What is a CSS File How to center a button in CSS How to change background color in CSS How to change the font in CSS How to change font size in CSS How to resize an image in CSS How to get rid of bullet pioints in CSS Is CSS a programming language How to edit CSS in WordPress How to use google fonts in CSS How to create blinking text using CSS How to Set Space between the Flexbox Is CSS a Programming Language

Difference

Difference between HTML and CSS Grid Vs Flexbox in CSS Difference between CSS Grid and CSS Flexbox

Misc

Create a 3D text effect using HTML and CSS Hover condition for a:before and a:after in CSS Bem CSS Boder Types CSS Features of CSS Font Face CSS Image Overlay CSS B Tag CSS Carousel CSS CSS Arrow CSS Focus Flex Grow in CSS Bem CSS Features of CSS Font Face CSS Removing Underline from Link in CSS Width Property in CSS Radio Button in CSS

CSS Outline

CSS Outline: This CSS property is quite similar to the border property of CSS. It eases us to design an additional border around the element to obtain visual attention. The CSS Outline property is easy to implement as the border property.

Let’s consider an example, which is given below:

<!DOCTYPE html>
<html>
<style type="text/css">
#box {
        background-color: #bbb;
        outline: 3px solid maroon;
        border: 3px solid blue;
        padding: 5px 10px;
}
</style>
<body>
<div id="box">Welcome to this Page</div>
</body>
</html>

Output:

The border and outline properties are quite similar, but also have some essential differences which are discussed below:

  • The first difference is that it is not probable to set a different kind of color, style, and outline for four edges of any element. On the other hand, we can set the given value for every four edges of any element while using the outline property.
  • A border is a critical part of the dimension of an element; however an outline is not any part of the dimension of an element. It illustrates that it does not affect how thick the outline we are applying on any element. Thus, its dimension would not be changed.

This CSS property is determined as a critical shorthand property. It may be categorized into outline-color, outline-style, and outline-width properties. It allows us to apply any of these attributes alone when we need it.

See an example as follows:

<!DOCTYPE html>
<html>
<style type= "text/css">
#box
{
 background-color: #bbb;
 border: 3px solid blue;
 padding: 5px 10px;
 outline-width: 3px;
 outline-style: solid;
 outline-color: maroon;
}
</style>
<body>
<div id= "box"> Welcome to this Page </div>
</body>
</html>

Output:

Explanation of above example, we used three properties of outline which are discussed as below:

outline-width: This property is quite similar to padding and margin properties. This property may be a relative value, an absolute value, or any predefined values of outline width i.e. thick, medium, or thin.

It is recommended to use a relative value or an absolute value because of different types of browsers described differently by using any predefined values of outline width like thick, medium, or thin.

outline-color: The outline-color property in CSS describes the color for an outline. It supports and allows every color that is available in the CSS and HTML.

outline-style: There are many styles of an outline available that can be applied like dotted, hidden, dashed, double, solid, groove, inset, outset, and ridge.

Consider the following example in which we demonstrate the application of various outline-styles:

Example:

<!DOCTYPE html>
<html>
<style type= "text/css">
#box
{
 border: 3px solid blue;
 padding: 5px 10px;
 outline-width: 4px;
 outline-color: maroon;
 margin: 10px;
 float: center;
}
</style>
<body>
<div id= "box" style= "outline-style: dashed;"> Dashed outline is specified here. </div>
<div id= "box" style= "outline-style: dotted;"> Dotted outline is specified here. </div>
<div id= "box" style= "outline-style: double;"> Double outline is specified here. </div>
<div id= "box" style= "outline-style: groove;"> Groove outline is specified here. </div>
<div id= "box" style= "outline-style: inset;"> Inset outline is specified here. </div>
<div id= "box" style= "outline-style: outset;"> Outset outline is specified here. </div>
<div id= "box" style= "outline-style: ridge;"> Ridge outline is specified here. </div>
<div id= "box" style= "outline-style: solid;"> Solid outline is specified here. </div>
</body>
</html>

Output:

Outline offset

An outline offset can be applied to make a distance among the border and the outline. It grabs an empty space and a length unit of CSS between the outline and the border will transparent. It then grabs a parent element’s background-color. So, we can see the visible difference among the border and the outline.

See the following example:

<!DOCTYPE html>
<html>
<style type= "text/css">
#box
{
 background-color: #bbb;
 border: 3px solid blue;
 padding: 5px 10px;
 outline: 3px solid maroon;
 outline-offset: 6px;
}
</style>
<body>
<div id= "box"> Welcome to this Page. </div>
</body>
</html>

Output: