CSS border-style Property

The border-style property sets the line style of an element's top, right, bottom, and left borders.

It is a shorthand for border-top-style, border-right-style, border-bottom-style, and border-left-style. You can assign the same style to all four sides or specify different styles using one to four values.

Available styles include solid, dotted, dashed, double, and several three-dimensional effects. A border normally needs a style other than none or hidden to become visible.

border-style Syntax

The border-style property accepts one to four border style keywords.

selector {
  border-style: solid;
}

The general syntax is:

selector {
  border-style: <line-style>{1,4};
}

One Value

.box {
  border-style: solid;
}

All four borders use a solid line.

Two Values

.box {
  border-style: solid dashed;
}

The top and bottom borders are solid. The right and left borders are dashed.

Three Values

.box {
  border-style: solid dashed dotted;
}

The top border is solid, the right and left borders are dashed, and the bottom border is dotted.

Four Values

.box {
  border-style: solid dashed dotted double;
}

The values apply to the top, right, bottom, and left borders in that order.

CSS-Wide Keywords

.inherited {
  border-style: inherit;
}
.reset {
  border-style: initial;
}
.unset {
  border-style: unset;
}
.reverted {
  border-style: revert;
}
.layer-reverted {
  border-style: revert-layer;
}

CSS-wide keywords must be used alone, not mixed with individual border style values.

Property Values

The property supports ten border line styles and the standard CSS-wide keywords.

Value Description
none Displays no border. The corresponding computed border width becomes zero.
hidden Displays no border, but takes precedence in collapsed table border conflict resolution.
dotted Displays a series of dots.
dashed Displays a series of short line segments.
solid Displays a continuous line.
double Displays two parallel lines separated by a gap.
groove Creates a carved or recessed appearance.
ridge Creates a raised ridge appearance.
inset Creates an inward or sunken appearance.
outset Creates an outward or raised appearance.
inherit Inherits the computed border styles from the parent.
initial Resets all four border styles to none.
unset Resets all four border styles to none because the longhand properties are not inherited.
revert Reverts the border styles according to cascade origin rules.
revert-layer Reverts the border styles according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value none for all four sides
Inherited No
Applies to Elements that support the border properties
Computed value As specified for each longhand
Animation type Discrete for each border style longhand
Accepted values One to four line style keywords
Property type Shorthand
Longhand properties border-top-style, border-right-style, border-bottom-style, border-left-style

The shorthand assigns styles to physical sides of the element, regardless of its writing direction.

How It Works

The browser uses the specified border styles to determine how each side of an element's border is drawn.

Step 1: Create a Box

.box {
  width: 240px;
  padding: 20px;
  background-color: #f3f8fc;
}

Step 2: Set the Border Width

.box {
  border-width: 4px;
}

The border width is specified, but the border is not visible because the default style is none.

Step 3: Set the Border Style

.box {
  border-style: solid;
}

All four borders become solid lines.

Step 4: Set the Border Color

.box {
  border-color: #1769aa;
}

The solid borders use the specified blue color.

Step 5: Change Individual Sides

.box {
  border-style: solid dashed dotted double;
}

Each physical side now uses a different line style.

Border style, width, and color work together to determine the final appearance of an element's border.

One to Four Values

The number of values determines which sides receive each style.

Number of Values Value Order
One All four sides
Two Top and bottom | Right and left
Three Top | Right and left | Bottom
Four Top | Right | Bottom | Left

One Style for Every Side

.box {
  border-style: dashed;
}

Vertical and Horizontal Styles

.box {
  border-style: solid dotted;
}

The top and bottom borders are solid, while the left and right borders are dotted.

Different Bottom Border

.box {
  border-style: solid dashed double;
}

The top border is solid, the side borders are dashed, and the bottom border is double.

Four Different Styles

.box {
  border-style: solid dashed dotted double;
}

Each side receives its own style, starting at the top and moving clockwise.

Only the Bottom Border

.box {
  border-style: none none solid;
}

The top, right, and left borders are hidden, while the bottom border is solid.

Only the Left Border

.box {
  border-style: none none none solid;
}

Only the left border is drawn.

The one-to-four-value pattern is the same as the patterns used by border-width, border-color, margin, and padding.

Border Style Types

Each border style keyword produces a different visual treatment.

none

.box {
  border: 5px none #1769aa;
}

No border is displayed, and the computed border width is zero.

hidden

.box {
  border: 5px hidden #1769aa;
}

No border is displayed. This style has special behavior when resolving collapsed table borders.

dotted

.box {
  border: 5px dotted #1769aa;
}

Displays a series of dots. The shape and spacing of the dots can vary by browser.

dashed

.box {
  border: 5px dashed #1769aa;
}

Displays a series of short line segments. Dash lengths and spacing can vary by browser.

solid

.box {
  border: 5px solid #1769aa;
}

Displays a continuous line.

double

.box {
  border: 8px double #1769aa;
}

Displays two parallel lines separated by a gap. The total thickness, including the gap, equals the specified border width.

groove

.box {
  border: 8px groove #1769aa;
}

Creates a recessed appearance using contrasting shades of the border color.

ridge

.box {
  border: 8px ridge #1769aa;
}

Creates a raised ridge appearance.

inset

.box {
  border: 8px inset #1769aa;
}

Creates the appearance of a sunken element.

outset

.box {
  border: 8px outset #1769aa;
}

Creates the appearance of a raised element.

For most modern interface designs, solid, dashed, and dotted provide predictable results. Three-dimensional styles are useful when a raised or recessed appearance is desired.

none vs. hidden

Both none and hidden prevent a border from being drawn, but they behave differently in collapsed table border conflict resolution.

Using none

.box {
  border-style: none;
}

No border is drawn, and the computed border width is zero.

Using hidden

.box {
  border-style: hidden;
}

No border is drawn, and the computed border width is zero.

Collapsed Table Borders

table {
  border-collapse: collapse;
}
td {
  border: 2px solid #1769aa;
}
td.no-border {
  border-style: none;
}
td.hidden-border {
  border-style: hidden;
}

When borders compete along the same edge in a collapsed table, hidden takes precedence and suppresses that border. The none style has the lowest priority, so another competing border may still be displayed.

Separate Table Borders

table {
  border-collapse: separate;
}

With separate borders, none and hidden both prevent the corresponding border from being displayed.

For ordinary elements, none is generally the appropriate choice when removing a border.

Three-Dimensional Styles

The groove, ridge, inset, and outset values create simulated depth by changing the appearance of border colors.

Groove - Recessed Edge

.panel {
  border: 10px groove #1769aa;
}

The border appears carved into the surrounding surface.

Ridge - Raised Edge

.panel {
  border: 10px ridge #1769aa;
}

The border appears raised above the surrounding surface.

Inset - Sunken Element

.panel {
  border: 10px inset #1769aa;
}

The element appears pressed inward.

Outset - Raised Element

.panel {
  border: 10px outset #1769aa;
}

The element appears to project outward.

Using Different 3D Styles

.panel {
  border-width: 10px;
  border-style: groove ridge inset outset;
  border-color: #1769aa;
}

Each side uses a different three-dimensional style.

The exact shading and appearance of these styles are browser-dependent. A wider border usually makes the effect easier to see.

Border Width and Color

Border style works with border-width and border-color to determine how a border is displayed.

Style Only

.box {
  border-style: solid;
}

A border can appear because the initial border width is medium and the initial border color is currentcolor.

Style and Width

.box {
  border-style: dashed;
  border-width: 4px;
}

Style and Color

.box {
  border-style: dotted;
  border-color: #1769aa;
}

All Three Properties

.box {
  border-style: solid;
  border-width: 3px;
  border-color: #1769aa;
}

Different Widths and Styles

.box {
  border-style: solid dashed dotted double;
  border-width: 2px 4px 6px 8px;
  border-color: #1769aa;
}

Different Colors and Styles

.box {
  border-style: solid dashed dotted double;
  border-width: 6px;
  border-color: #1769aa #c04b37 #27805c #8054a5;
}

Using currentcolor

.box {
  color: #1769aa;
  border-style: solid;
  border-width: 3px;
  border-color: currentcolor;
}

The border uses the element's current text color.

A specified border width does not guarantee a visible border. When the corresponding border style is none or hidden, the computed width is zero.

Shorthand Interactions

The border-style shorthand controls the styles of all four physical borders. Other border shorthands can also set or reset these styles.

border-style Shorthand

.box {
  border-style: solid dashed;
}

Sets the top and bottom borders to solid and the left and right borders to dashed.

border Shorthand

.box {
  border: 3px solid #1769aa;
}

Sets the width, style, and color of all four borders.

border-top Shorthand

.box {
  border-style: solid;
  border-top: 5px dashed #c04b37;
}

The top border becomes dashed, while the other sides remain solid.

Individual Style Longhand

.box {
  border-style: solid;
  border-bottom-style: dotted;
}

Only the bottom border style is changed.

Later border Shorthand

.box {
  border-style: dashed;
  border: 3px solid #1769aa;
}

The later border shorthand resets all four border styles to solid.

Later border-style Shorthand

.box {
  border: 3px solid #1769aa;
  border-style: dashed;
}

The border width and color remain unchanged, but all four styles become dashed.

The border-style shorthand does not reset border widths or colors. However, it can change their visible effect by setting a side to none or hidden.

Physical vs. Logical Borders

The border-style shorthand assigns styles to physical sides: top, right, bottom, and left. These sides do not change when the writing direction changes.

Physical Border Styles

.box {
  border-style: solid dashed dotted double;
}

The values always apply to the physical top, right, bottom, and left sides.

Logical Block Borders

.box {
  border-block-start-style: solid;
  border-block-end-style: dashed;
}

The styles follow the logical block-start and block-end edges.

Logical Inline Borders

.box {
  border-inline-start-style: solid;
  border-inline-end-style: dashed;
}

The styles follow the logical inline-start and inline-end edges.

Horizontal Left-to-Right

.box {
  writing-mode: horizontal-tb;
  direction: ltr;
  border-inline-start-style: solid;
}

The inline-start border is on the left.

Horizontal Right-to-Left

.box {
  writing-mode: horizontal-tb;
  direction: rtl;
  border-inline-start-style: solid;
}

The inline-start border is on the right.

Logical Shorthand

.box {
  border-block-style: solid dashed;
  border-inline-style: dotted double;
}

The first shorthand sets block-start and block-end styles. The second sets inline-start and inline-end styles.

Use logical border properties when border placement should adapt to the writing mode or direction of the content.

Box Sizing and Layout

Border styles can affect an element's dimensions because visible borders contribute to the box model.

Content-Box Sizing

.box {
  box-sizing: content-box;
  width: 200px;
  padding: 20px;
  border-width: 5px;
  border-style: solid;
}

The border adds to the declared width of the content box.

Border-Box Sizing

.box {
  box-sizing: border-box;
  width: 200px;
  padding: 20px;
  border-width: 5px;
  border-style: solid;
}

The declared width includes the padding and borders.

Removing a Border Style

.box {
  border-width: 5px;
  border-style: none;
}

The computed border widths become zero because the styles are none.

Adding a Border on Hover

.box {
  border: 3px solid transparent;
}
.box:hover {
  border-style: dashed;
  border-color: #1769aa;
}

Using a transparent border in the initial state reserves the border space and avoids a layout shift when the style changes.

Changing From none to solid

.box {
  border-width: 4px;
  border-style: none;
}
.box:hover {
  border-style: solid;
}

The computed border width changes from zero to 4 pixels, which can affect layout.

When designing interactive borders, reserve the required border width in the initial state if layout stability is important.

Cascade and Overrides

The CSS cascade determines which border style declarations take effect when multiple rules target the same element.

Later Declaration

.box {
  border-style: solid;
  border-style: dashed;
}

The later dashed style wins when cascade priority is otherwise equal.

Higher Specificity

.box {
  border-style: solid;
}
.box.featured {
  border-style: double;
}

Individual Side Override

.box {
  border-style: solid;
  border-left-style: dashed;
}

The left border becomes dashed, while the other sides remain solid.

Later Shorthand Override

.box {
  border-left-style: dashed;
  border-style: solid;
}

The later shorthand sets all four border styles to solid.

CSS Layers

@layer base, components;
@layer base {
  .box {
    border-style: solid;
  }
}
@layer components {
  .box {
    border-style: dashed;
  }
}

For normal declarations, the later layer takes precedence.

Resetting Border Styles

.box {
  border-style: dashed;
}
.box.reset {
  border-style: none;
}

The reset class removes all four visible borders.

Remember that shorthand declarations can override individual longhand values when their cascade priority is higher.

CSS Custom Properties

Custom properties can store reusable border styles and make component variations easier to maintain.

Shared Border Style

:root {
  --default-border-style: solid;
}
.box {
  border-style: var(--default-border-style);
}

Fallback Style

.box {
  border-style: var(--border-style, solid);
}

Component Variants

.card {
  --card-border-style: solid;
  border: 3px var(--card-border-style) #1769aa;
}
.card.dashed {
  --card-border-style: dashed;
}
.card.dotted {
  --card-border-style: dotted;
}

Four-Side Style Variable

:root {
  --border-styles: solid dashed dotted double;
}
.box {
  border-style: var(--border-styles);
}

Theme-Based Styles

.theme-standard {
  --panel-border-style: solid;
}
.theme-decorative {
  --panel-border-style: double;
}
.panel {
  border-width: 5px;
  border-color: #1769aa;
  border-style: var(--panel-border-style, solid);
}

Custom properties help keep border styling consistent across reusable interface components.

Interactive States

Border styles can change in response to hover, focus, selection, and other component states.

Hover State

.card {
  border: 3px solid #1769aa;
}
.card:hover {
  border-style: dashed;
}

Focus State

.control {
  border: 2px solid #888888;
}
.control:focus-visible {
  border-style: solid;
  border-color: #1769aa;
  outline: 2px solid #1769aa;
  outline-offset: 2px;
}

Selected Component

.card {
  border: 3px solid #cccccc;
}
.card.is-selected {
  border-style: double;
  border-color: #1769aa;
}

Current Navigation Item

.nav-link {
  border-bottom: 3px solid transparent;
}
.nav-link[aria-current="page"] {
  border-bottom-style: solid;
  border-bottom-color: #1769aa;
}

Invalid Form Control

input {
  border: 2px solid #888888;
}
input:invalid {
  border-style: dashed;
  border-color: #c04b37;
}

Border style changes can reinforce interactive states, but they should not be the only indication of important information.

Transitions and Animation

Border style changes are discrete. Browsers switch between styles rather than smoothly interpolating their shapes.

Discrete Style Change

.box {
  border: 4px solid #1769aa;
  transition: border-style 0.3s ease;
}
.box:hover {
  border-style: dashed;
}

The border style changes discretely rather than gradually transforming from solid to dashed.

Smooth Border Color Transition

.box {
  border: 3px solid #1769aa;
  transition: border-color 0.3s ease;
}
.box:hover {
  border-color: #c04b37;
}

Border colors can interpolate smoothly between compatible color values.

Smooth Border Width Transition

.box {
  box-sizing: border-box;
  border: 2px solid #1769aa;
  transition: border-width 0.3s ease;
}
.box:hover {
  border-width: 8px;
}

Border width can animate smoothly, although changing it may affect the content area or layout.

Keyframe Style Change

@keyframes border-style-change {
  0% {
    border-style: solid;
  }
  50% {
    border-style: dashed;
  }
  100% {
    border-style: dotted;
  }
}
.animated-box {
  border: 4px solid #1769aa;
  animation: border-style-change 3s infinite;
}

The animation switches between the specified styles at discrete points.

Reduced Motion Preference

.box {
  border: 3px solid #1769aa;
  transition: border-color 0.3s ease;
}
.box:hover {
  border-color: #c04b37;
}
@media (prefers-reduced-motion: reduce) {
  .box {
    transition: none;
  }
}

For smooth visual changes, animate border color or width rather than expecting border style keywords to interpolate.

Responsive Design

Border styles can change according to viewport size, container dimensions, and component layout.

Media Query

.panel {
  border: 4px solid #1769aa;
}
@media (max-width: 600px) {
  .panel {
    border-style: dashed;
  }
}

Container Query

.panel-container {
  container-type: inline-size;
}
.panel {
  border: 3px solid #1769aa;
}
@container (min-width: 500px) {
  .panel {
    border-style: double;
  }
}

Mobile-Only Bottom Border

.panel {
  border: 3px solid #1769aa;
}
@media (max-width: 600px) {
  .panel {
    border-style: none none solid;
  }
}

Responsive Border Width

.panel {
  border-style: solid;
  border-color: #1769aa;
  border-width: clamp(2px, 0.5vw, 6px);
}

Direction-Aware Border

.panel {
  border-inline-start: 4px solid #1769aa;
  border-block-end-style: dashed;
}

Logical border properties are useful when border placement must follow the writing direction of the content.

Responsive border styles can simplify a layout by removing decorative borders or emphasizing different edges at smaller screen sizes.

Practical Uses

The border-style property is useful for content panels, separators, cards, form controls, and decorative interface elements.

Solid Content Panel

.content-panel {
  padding: 20px;
  border: 3px solid #1769aa;
  background-color: #f3f8fc;
}

Dashed Information Box

.information-box {
  padding: 20px;
  border: 3px dashed #1769aa;
  background-color: #f3f8fc;
}

Dotted Separator

.separator {
  border: 0;
  border-top: 3px dotted #888888;
}

Double Border Heading

.section-heading {
  padding-bottom: 12px;
  border-bottom: 6px double #1769aa;
}

Mixed Border Styles

.feature-card {
  padding: 20px;
  border-width: 4px;
  border-style: solid dashed;
  border-color: #1769aa;
}

Decorative Ridge Panel

.decorative-panel {
  padding: 20px;
  border: 10px ridge #1769aa;
}

Bottom-Only Navigation Indicator

.nav-item {
  border-width: 0 0 3px;
  border-style: solid;
  border-color: transparent;
}
.nav-item[aria-current="page"] {
  border-bottom-color: #1769aa;
}

Highlighted Form Group

.form-group {
  padding: 20px;
  border: 2px dashed #1769aa;
}

Choose a border style that supports the purpose of the component. Solid borders work well for general structure, while dashed and dotted borders can distinguish secondary or decorative boundaries.

border-style Example

The following example displays all ten border styles and demonstrates how one to four values control individual sides.

<div class="border-style-demo">
  <div class="demo-box none">none</div>
  <div class="demo-box hidden">hidden</div>
  <div class="demo-box dotted">dotted</div>
  <div class="demo-box dashed">dashed</div>
  <div class="demo-box solid">solid</div>
  <div class="demo-box double">double</div>
  <div class="demo-box groove">groove</div>
  <div class="demo-box ridge">ridge</div>
  <div class="demo-box inset">inset</div>
  <div class="demo-box outset">outset</div>
  <div class="demo-box mixed">Four Styles</div>
  <div class="demo-box bottom-only">Bottom Only</div>
</div>
.border-style-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 20px;
}
.border-style-demo .demo-box {
  box-sizing: border-box;
  min-height: 100px;
  padding: 20px;
  border-width: 8px;
  border-color: #1769aa;
  background-color: #f3f8fc;
  color: #173b5e;
  font-weight: bold;
  text-align: center;
}
.border-style-demo .none {
  border-style: none;
}
.border-style-demo .hidden {
  border-style: hidden;
}
.border-style-demo .dotted {
  border-style: dotted;
}
.border-style-demo .dashed {
  border-style: dashed;
}
.border-style-demo .solid {
  border-style: solid;
}
.border-style-demo .double {
  border-style: double;
}
.border-style-demo .groove {
  border-style: groove;
}
.border-style-demo .ridge {
  border-style: ridge;
}
.border-style-demo .inset {
  border-style: inset;
}
.border-style-demo .outset {
  border-style: outset;
}
.border-style-demo .mixed {
  border-style: solid dashed dotted double;
}
.border-style-demo .bottom-only {
  border-style: none none solid;
}
Browser Result
none
dotted
dashed
solid
double
groove
ridge
inset
outset
Four Styles
Bottom Only

The none and hidden examples display no border. The other examples show different line patterns or simulated three-dimensional effects.

The Four Styles example applies a different style to each side. The Bottom Only example draws a solid bottom border while leaving the other sides without borders.

Important Considerations

Keep the following points in mind when using border-style:

  • Purpose: Sets the line style of all four physical borders.
  • Property type: Shorthand for the four physical border style longhands.
  • Initial value: none for each side.
  • Inheritance: Border styles are not inherited.
  • Accepted values: One to four line style keywords.
  • Value order: Top, right, bottom, left when four values are provided.
  • none: Removes the visible border and produces a computed border width of zero.
  • hidden: Suppresses competing borders in collapsed table border conflict resolution.
  • dotted and dashed: Dot and dash patterns can vary by browser.
  • double: Uses two lines separated by a gap within the specified border width.
  • 3D styles: Groove, ridge, inset, and outset create simulated depth.
  • Border width: Determines the thickness of visible borders.
  • Border color: Determines the color used to draw borders.
  • Shorthand interaction: The border shorthand can reset border styles.
  • Physical sides: The property always targets top, right, bottom, and left.
  • Logical alternatives: Use logical border style properties for direction-aware borders.
  • Box sizing: Visible border widths contribute to the box model.
  • Custom properties: Can store reusable style keywords.
  • Animation: Border style changes are discrete rather than smoothly interpolated.
  • Browser support: The property is widely supported.

Use border-style when you need to control the appearance of multiple border sides with a single declaration.

Browser Support

The border-style property is widely available and supported in Chrome, Edge, Firefox, Safari, and other major browsers.

The basic border styles and one-to-four-value shorthand syntax have long-standing browser support. The precise appearance of dotted, dashed, and three-dimensional styles may differ between browsers and operating systems.

.box {
  border-width: 4px;
  border-style: solid dashed;
  border-color: #1769aa;
}

This example uses established CSS border features and does not require a vendor prefix.

For current compatibility details, visit Can I Use? and search for border-style.

Specifications

The border-style property is defined in the CSS Backgrounds and Borders Module Level 3 specification.

CSS Backgrounds and Borders Module Level 3

The specification defines the available border styles, their rendering behavior, and the relationship between the shorthand and its individual longhand properties.