×

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:


Related Topics

Cascading Style Sheet

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

7 minutes read.

How to make smooth bounce animation using CSS

The smooth bouncing animation project is done with the help of HTML and CSS. This project gives so much fun and excitement to the users. What is HTML? The HTML or HyperText...

2 minutes read.

CSS Important

CSS Important: CSS !important property is used to provide more importance, as compared to other CSS properties. The meaning of this property is “This is important.” This property enables CSS...

2 minutes read.

CSS Masking

CSS Masking The CSS mask property is applied to hide a component with the use of the masking or clipping an image at any specific point. The masking depicts the use...

3 minutes read.

CSS 2d Transform

Transform property in CSS is used mainly for enhancing the effects and to animate the elements. Transform is an effect that changes the shape, size and position of an element. It helps...

6 minutes read.

CSS Visibility

Visibility in CSS: This visibility property in CSS is employed to describe whether the components are visible or not. Note: An invisible component also grabs the space over the page. If...

2 minutes read.

CSS Background-clip

CSS Background-clip: The background-clip property describes the background’s painting area. It limits an area where the image or color of the background appears by using any clipping box. Everything will...

2 minutes read.

What is CSS

CSS stands for Cascading Style Sheet. It gives an additional style to the HTML document. A cascading style sheet is a language that is designed to define the document formatting...

3 minutes read.

CSS Display

CSS Display: The CSS Display property is one of an essential property among all other properties of CSS. The display property specifies how the HTML elements should be displayed on...

4 minutes read.

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...

4 minutes read.

How to change background color in CSS

How to change background color in CSS? The background-color property in CSS would be used to specify the color of an element's background. As the element's background, it uses solid colors. The...

3 minutes read.

CSS Background

CSS Background The properties of CSS background are applied to describe the effects of background on the element. Here are five properties of background that affects various elements of HTML: Background-colorBackground-imageBackground-repeatBackground-attachment Background-position Background-color The color of the background...

7 minutes read.

CSS Loader

CSS Loader The loader is the animation that can alert a visitor regarding the loading of the page. We need to wait for some time. It will be helpful if any...

4 minutes read.

CSS Functions

CSS functions are used for different CSS properties. Every front-end developer should have knowledge of all CSS functions. It makes the coding easier. FunctionsExplanationattr().It returns the value of an attribute of...

5 minutes read.

CSS Animation

CSS Animation: The animation property of CSS is applied to make animation over any webpage. It is used as the animation replacement made by JavaScript and Flash. Rules of CSS3 @keyframes The...

3 minutes read.

CSS Inline

What is CSS? CSS is an acronym for Cascading Style Sheets. CSS is the language that we use to style an HTML document. It specifies how HTML components should appear. CSS...

4 minutes read.

CSS Content Property

Content Property The content attribute produces dynamic content. It can be applied with any pseudo-element ::after and ::before. These CSS properties are entirely supported inside every browser and applied to include...

5 minutes read.

CSS Introduction

CSS stands for Cascading Style Sheet. It is a design language which is used to design the web pages. It was developed by Håkon Wium Lie on October 10, 1994. It provides...

1 minute read.

CSS Checkbox style

CSS Checkbox style: It is an element of HTML, which is used to get input from various users. It is difficult to style any checkbox. However, some elements make it...

6 minutes read.

CSS Font-Size

A Cascading Style Sheet (CSS) is a simple design scripting language intended to simplify the process of making web pages more visually appealing with the kind of high-level formatting. Cascading...

3 minutes read.