CSS border-style Property

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

Overview

Borders are the user-friendly components of our web design. Styling a border adds to the overall feel of our website. Recall how we used to add pretty borders to our school projects to make them presentable and earn more points. We've created zigzags, waves, and other patterns around our projects. Similarly, we may use such borders in our website design to draw attention to our content. We can choose the desired border type by using the CSS border style property.

  • The CSS border style is a shorthand property that specifies the line style of an element's border.
  • It can be used to set the border style to solid, dashed line, double line, dotted, or one of the other possible values.
  • The top, right, bottom, and left borders of an element can each have a different style.

Syntax

The border-style property sets the style of an element's four borders. This property accepts a keyword for the line style. We can specify the border style as dotted, double, solid, or dashed. Using parameters like outset, inset, etc., we could even give our border a three-dimensional aspect. The element can also inherit the border style from its parent.

In the following sections of the article, we will discuss the values that the border-style property supports in more detail.

Constituent Properties

The border-style property is a shorthand property that specifies the line style for each border side. We can individually style each border side by using the following properties:

Constituent PropertyDescriptionSyntax
border-top-styleSets the style of the top border of an element.border-top-style:<line-style > ;
border-right-styleSets the style of the right border of an element.border-right-style:<line-style > ;
border-bottom-styleSets the style of the bottom border of an element.border-bottom-style:<line-style > ;
border-left-styleSets the style of the left border of an element.border-left-style:<line-style > ;

The example below demonstrates the constituent CSS properties for border-color.

HTML

CSS

Output

output-css-properties-of-border-color

To see the live output, visit the following link.

The border-style is none by default. It is the same as having a border with no width

CSS Border-style Shorthand Property

  • We can specify a single value if we want the border to be uniformly styled.
  • Two values set the horizontal and vertical values, respectively.
  • Three values specify the top, vertical, and bottom values.
  • The CSS border-style property can even have four different values.

NOTE : We can memorize the order of arguments by enumerating the sides of a rectangle clockwise, starting from the top, moving right, then bottom, and finishing at the left.

CSS Border-style Property Values

The border-style property can be specified using the following values:

ValueDescriptionSyntax
noneIt is the default value. It is the same as having no border or a border with no widths.border-style ;
hiddenIt displays no border, just as none does. Hidden takes precedence over all the other styles.border-style ;
dottedIt displays rounded dots with a radius half the value of the computed border width.border-style ;
dashedIt displays a series of short, square-ended dashes.border-style ;
solidIt displays a solid straight line.border-style;
doubleIt displays two straight lines.border-style ;
grooveThe border appears 3D with a carved appearance .border-style;
ridgeThe border appears 3D with a exctruded appearance .border-style;
insetIt displays a border that gives the element a 3D embedded appearance.border-style;
outsetIt displays a border that gives the element a 3D embossed appearance.border-style;
initialIt sets the property to its default value.border-style;
inheritThe element inherits the border style from its parent.border-style;

NOTE: The effect of groove, ridge, inset, and outset line style values depends on the border’s color.

Examples

We can understand the CSS border style property through the following code.

EXAMPLE 1

HTML

CSS

Output

output-css-border-style-property

To see the live output, visit the following link.

EXAMPLE 2

Let us use the constituent and shorthand properties in the following example.

HTML

CSS

Output

output-shorthand-and-constituent-properties

To see the live output, visit the following link.

Browser Support

The following browsers support the CSS border style property:

BrowserVersion
Google Chrome2.0
Safari1.0
Mozilla Firefox1.0
Microsoft Edge12.0
Chrome Android18
Firefox for Android4
Opera Android10.1
Safari on iOS1
OperaSamsung Internet1.0
WebView Android4.4

Conclusion

  • The CSS border style property sets the line style of an element's border.
  • We can modify the style of the bottom, left, top, and right borders by using constituent properties like border-style-top, border-style-right, etc.
  • We can define the border style using values like dotted, double, solid, initial, inherit, etc.
  • The effect of groove, ridge, inset, and outset line style values depends on the border's color.
  • CSS border style related properties: border, border-top-style, border-right-style, border-bottom-style, and border-left-style.
  • Other related properties: border width, border color, etc.