×

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

What is a CSS File?

What is a CSS File and How to use it in Html? CSS: - CSS stands for Cascading Style Sheet. CSS is a file of style sheets that describe the presentation of...

4 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 Filter

CSS Filter CSS filter is used to apply visual effects on the images, text, and other factors of the webpage. This filter property in CSS allows us to admit the effects like...

7 minutes read.

CSS Ellipsis

The CSS ellipsis kind of is the value that mostly is used by the property: text-overflow. Here, we will discuss the following: What is CSS Ellipsis? Syntax for CSS ellipsis How to...

3 minutes read.

CSS Text-align

Text-align The text-align property of CSS sets the table-cell box’s horizontal alignment or any block element. The text-align property is the same as the CSS property vertical-align but towards any horizontal...

1 minute read.

CSS Line Height

CSS Line Height: This property in CSS can be used to describe the line box’s minimal height inside the element. It sets-up the distinction among two lines in our content. It...

3 minutes read.

Internal CSS

What is CSS? CSS stands for Cascading Style Sheet.CSS is used to apply styling the HTML elements.With CSS user can add or change color, font-size and font-family. It also helps user...

4 minutes read.

CSS :root selector

CSS :root selector This CSS pseudo-class matches any document’s root element. It chooses the parent of the highest-level inside the document DOM or tree. An element of <html> is always a...

2 minutes read.

Css Text Orientation

Introduction: The text-orientation property of CSS is used to specify the orientation of the text characters in the line of content. This property applies only with the vertical writing-mode and not...

4 minutes read.

CSS Page-break-after Attribute

Page-break-after Attribute As its name implies, the page-break-before property is applied to include page break after any element, at the time of printing a document. It adds the page break after...

5 minutes read.

CSS Browser Support

The desk underneath lists of all CSS properties and the way each belongs to it is supported in the generally unique browsers: - The quantity to the right of the browser...

2 minutes read.

How to center a table in CSS

The table is used to store and arrange the data in tabular format. The data here can be of any form like text, image, links, etc. The table is made...

3 minutes read.

CSS Dropdowns

Dropdowns are one of the maximum crucial parts of an interactive internet site. CSS is a kind used to design the drop-down menus. A drop-down essentially is a group of...

5 minutes read.

Difference between CSS Grid and CSS Flexbox

The way that information is arranged on a website reveals a lot about you or your company. Organizational abilities are just as important as having the right materials. The design...

3 minutes read.

CSS Form

You can create attractive HTML form by using CSS. Style input Fields The Input Field width properties are used to determine the width of the input field. Let us see an example of CSS style...

2 minutes read.

CSS Page-break-inside Attribute

Page-break-inside Attribute As its name implies, the page-break-before property is applied to include page break inside any element, at the time of printing any document. It adds the page break before...

3 minutes read.

CSS Overlay

CSS Overlay: It measures to cover-up something’s surface along with a coating. CSS overlay sets anything over the top area of other things. It creates a web-page more attractive. The...

8 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 Text-decoration

CSS Text-decoration: It is an essential property of CSS that is used to decorate the content of the text. It can add-on the lines above, under, and over the text....

3 minutes read.

CSS Images

Images in CSS: Images are a critical part of a web application. It includes various types of images in the web application that cannot be recommended. However, it is essential...

4 minutes read.