CSS border-top-style Property

The border-top-style property sets the line style of an element's top border.

It determines whether the top border appears solid, dotted, dashed, double, or with a three-dimensional effect. The property also accepts none and hidden to suppress the border.

Unlike the border-top shorthand, border-top-style changes only the border style. The width and color are controlled separately.

border-top-style Syntax

Specify one border style keyword to control the appearance of the top border.

selector {
  border-top-style: solid;
}

The general syntax is:

selector {
  border-top-style: <line-style>;
}

Solid Border

.panel {
  border-top-style: solid;
}

Dashed Border

.panel {
  border-top-style: dashed;
}

Dotted Border

.panel {
  border-top-style: dotted;
}

Double Border

.panel {
  border-top-style: double;
}

Hidden Border

.panel {
  border-top-style: hidden;
}

CSS-Wide Keywords

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

Only one border style keyword or one CSS-wide keyword is allowed per declaration. Values such as solid dashed are invalid for this individual property.

Property Values

The border-top-style property supports ten border style keywords.

Value Description
none Displays no top border. This is the initial value.
hidden Displays no top border and has special precedence in collapsed table border conflicts.
dotted Displays a series of dots.
dashed Displays a series of short line segments.
solid Displays one continuous line.
double Displays two parallel lines separated by a gap.
groove Displays a border that appears carved into the surface.
ridge Displays a border that appears raised from the surface.
inset Displays a border that makes the element appear recessed.
outset Displays a border that makes the element appear raised.

CSS-Wide Keywords

Value Description
inherit Uses the computed top border style of the parent element.
initial Resets the top border style to none.
unset Resets the property to none because it is not inherited.
revert Reverts the property according to the cascade origin.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value none
Inherited No
Applies to All elements
Computed value Specified keyword
Animation type Discrete
Property type Longhand
Physical side Top

The property accepts style keywords only. Border widths and colors must be declared separately or through a shorthand property.

How It Works

The browser combines the top border style with its width and color to determine how the border is drawn.

Step 1: Create an Element

<div class="panel">
  This panel has a styled top border.
</div>

Step 2: Add Basic Styling

.panel {
  padding: 24px;
  background-color: #f3f7fa;
}

Step 3: Set the Border Style

.panel {
  border-top-style: solid;
}

The browser displays a solid top border using the default medium width and the current text color unless other border properties override them.

Step 4: Set the Width and Color

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

Step 5: Change the Style

.panel {
  border-top-style: dashed;
}

The top border becomes dashed while its existing width and color remain unchanged.

Step 6: Remove the Border

.panel {
  border-top-style: none;
}

The top border disappears. Its computed width becomes zero when the style is none.

The other three border sides are unaffected by changes to border-top-style.

Basic Border Styles

The most common border styles are solid, dashed, dotted, and double.

Solid

.panel {
  border-top: 4px solid #1769aa;
}

A solid border creates a continuous line. It is commonly used for cards, separators, navigation, and highlighted sections.

Dashed

.panel {
  border-top: 4px dashed #1769aa;
}

A dashed border consists of separate line segments. The length and spacing of the dashes are determined by the browser.

Dotted

.panel {
  border-top: 4px dotted #1769aa;
}

A dotted border consists of dots. Their appearance and spacing can vary between browsers.

Double

.panel {
  border-top: 8px double #1769aa;
}

A double border displays two parallel lines separated by a gap. The specified width includes both lines and the space between them.

Comparing Styles

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

For clear visual comparisons, apply the same border width and color to each element. A thicker width makes the double style easier to distinguish.

Three-Dimensional Border Styles

Four border styles create a raised or recessed appearance using variations of the border color.

Groove

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

The groove style creates a carved or recessed appearance.

Ridge

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

The ridge style creates a raised appearance, visually opposite to groove.

Inset

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

The inset style uses shading that contributes to a recessed appearance when viewed as part of a complete border.

Outset

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

The outset style uses shading that contributes to a raised appearance when viewed as part of a complete border.

Using a Complete 3D Border

.recessed {
  border: 8px inset #1769aa;
}
.raised {
  border: 8px outset #1769aa;
}

Applying these styles to all four sides makes the three-dimensional effect more noticeable.

Considerations for 3D Styles

The exact shading depends on the browser and the border color. Very thin borders may not show the effect clearly.

For precise visual control, gradients and box shadows may be more suitable than traditional 3D border styles.

none vs. hidden

Both none and hidden suppress the visible top border, but they behave differently in collapsed table border conflicts.

none

.panel {
  border-top-style: none;
}

The top border is not displayed, and its computed width is zero.

hidden

.panel {
  border-top-style: hidden;
}

The top border is also not displayed, and its computed width is zero.

Difference in Collapsed Tables

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

With collapsed table borders, none has the lowest conflict priority. A visible border from an adjacent cell can still appear.

The hidden style takes precedence in border conflict resolution and suppresses the shared border.

Which Should You Use?

Use none when removing a border from ordinary elements. Use hidden when its special behavior is needed for collapsed table borders.

Border Width and Color

The visible appearance of the top border depends on three properties: style, width, and color.

Border Style

.panel {
  border-top-style: solid;
}

Border Width

.panel {
  border-top-width: 5px;
}

Border Color

.panel {
  border-top-color: #1769aa;
}

Combining All Three

.panel {
  border-top-style: dashed;
  border-top-width: 5px;
  border-top-color: #1769aa;
}

Equivalent Shorthand

.panel {
  border-top: 5px dashed #1769aa;
}

Using currentColor

.panel {
  color: #1769aa;
  border-top-width: 4px;
  border-top-style: solid;
  border-top-color: currentColor;
}

The border color follows the element's computed text color.

Zero Width

.panel {
  border-top-style: solid;
  border-top-width: 0;
}

A zero-width border is not visible, even when the style is solid.

Default Width

.panel {
  border-top-style: solid;
}

If the width has not been changed, its specified initial value is medium. The computed width becomes zero when the border style is none or hidden.

Setting width, style, and color explicitly produces more predictable visual results.

Border Shorthands

The border-top-style property is a longhand component of several border shorthand properties.

border-top Shorthand

.panel {
  border-top: 4px solid #1769aa;
}

The shorthand sets the top border's width, style, and color together.

border-style Shorthand

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

The values apply clockwise: top, right, bottom, and left. The top border receives solid.

border Shorthand

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

This shorthand sets the width, style, and color for all four border sides.

Overriding One Side

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

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

Shorthand Override

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

The later shorthand resets the top border style to solid.

Omitted Style in a Shorthand

.panel {
  border-top-style: dashed;
  border-top: 5px #1769aa;
}

The later border-top shorthand resets the omitted style component to its initial value, none, so the top border is not displayed.

Use the individual property when you need to change the top border's appearance without resetting its width or color.

Individual Border Sides

CSS provides a separate border style property for each physical side of an element.

Top Border

.panel {
  border-top-style: solid;
}

Right Border

.panel {
  border-right-style: dashed;
}

Bottom Border

.panel {
  border-bottom-style: dotted;
}

Left Border

.panel {
  border-left-style: double;
}

Different Styles on Every Side

.panel {
  border-width: 5px;
  border-color: #1769aa;
  border-top-style: solid;
  border-right-style: dashed;
  border-bottom-style: dotted;
  border-left-style: double;
}

Equivalent Shorthand

.panel {
  border-width: 5px;
  border-color: #1769aa;
  border-style: solid dashed dotted double;
}

The shorthand is convenient when setting several sides at once. Individual properties are useful for targeted changes.

Physical vs. Logical Borders

The border-top-style property always targets the physical top border, regardless of the element's writing mode or text direction.

Logical border properties identify edges according to the block and inline directions.

Physical Top Border

.panel {
  border-top-style: solid;
}

Logical Block-Start Border

.panel {
  border-block-start-style: solid;
}

Horizontal Writing Mode

.panel {
  writing-mode: horizontal-tb;
  border-block-start-style: dashed;
}

In horizontal top-to-bottom writing mode, the block-start edge is the physical top edge.

Vertical Right-to-Left Writing Mode

.panel {
  writing-mode: vertical-rl;
  border-block-start-style: dashed;
}

In vertical right-to-left writing mode, the block-start edge is the physical right edge.

Vertical Left-to-Right Writing Mode

.panel {
  writing-mode: vertical-lr;
  border-block-start-style: dashed;
}

In vertical left-to-right writing mode, the block-start edge is the physical left edge.

Physical and Logical Conflict

.panel {
  writing-mode: horizontal-tb;
  border-top-style: solid;
  border-block-start-style: dashed;
}

Both declarations target the physical top border in this writing mode. The later declaration wins when cascade priority is otherwise equal.

Logical Border Shorthand

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

This shorthand sets the width, style, and color of the logical block-start border.

Use physical properties for fixed edge placement and logical properties when borders should follow the writing mode.

Table Borders

Border styles can behave differently when applied to tables using border-collapse: collapse.

Separate Table Borders

table {
  border-collapse: separate;
}
td {
  border-top: 2px solid #1769aa;
}

Each cell draws its own border independently.

Collapsed Table Borders

table {
  border-collapse: collapse;
}
td {
  border: 2px solid #1769aa;
}

Adjacent cell borders share an edge, and the browser resolves competing border declarations.

Using none

td.no-top-border {
  border-top-style: none;
}

A neighboring visible border may still appear along the shared edge.

Using hidden

td.hidden-top-border {
  border-top-style: hidden;
}

The hidden style suppresses the shared border when it participates in collapsed border conflict resolution.

3D Styles in Collapsed Tables

table {
  border-collapse: collapse;
}
td {
  border-top: 5px groove #1769aa;
}

In the collapsed border model, groove is rendered like ridge, and inset and outset are rendered like groove and ridge, respectively.

For predictable table separators, solid borders are usually the simplest choice.

Cascade and Overrides

The CSS cascade determines which top border style applies when multiple declarations target the same element.

Later Declaration

.panel {
  border-top-style: solid;
  border-top-style: dashed;
}

The later declaration wins when cascade priority is otherwise equal.

Higher Specificity

.panel {
  border-top-style: solid;
}
.panel.featured {
  border-top-style: double;
}

Shorthand Override

.panel {
  border-top-style: dashed;
  border-style: solid;
}

The later shorthand sets all four border styles to solid.

Longhand Override

.panel {
  border-style: solid;
  border-top-style: dotted;
}

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

CSS Layers

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

For normal declarations, the later layer takes precedence.

Resetting the Style

.panel {
  border-top-style: solid;
}
.panel.no-top-border {
  border-top-style: none;
}

The reset class removes the visible top border.

When troubleshooting a border style, inspect declarations involving border-top-style, border-style, border-top, and border.

CSS Custom Properties

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

Shared Border Style

:root {
  --top-border-style: solid;
}
.panel {
  border-top-style: var(--top-border-style);
}

Fallback Style

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

Component Variants

.card {
  --top-border-style: solid;
  border-top-width: 4px;
  border-top-color: #1769aa;
  border-top-style: var(--top-border-style);
}
.card.featured {
  --top-border-style: double;
}
.card.secondary {
  --top-border-style: dashed;
}

Complete Border Variables

:root {
  --border-width: 4px;
  --border-style: solid;
  --border-color: #1769aa;
}
.panel {
  border-top: var(--border-width) var(--border-style) var(--border-color);
}

State-Based Custom Property

.panel {
  --top-border-style: solid;
  border-top: 4px var(--top-border-style) #1769aa;
}
.panel.is-active {
  --top-border-style: dashed;
}

Custom properties are useful when several components share the same border styles or when styles change according to component state.

Transitions and Animation

The border-top-style property has a discrete animation type. Browsers switch between style keywords rather than gradually transforming one pattern into another.

Changing Style on Hover

.panel {
  border-top: 4px solid #1769aa;
}
.panel:hover {
  border-top-style: dashed;
}

The style changes when the pointer enters or leaves the element.

Discrete Transition

.panel {
  border-top: 4px solid #1769aa;
  transition: border-top-style 0.4s;
}
.panel:hover {
  border-top-style: dotted;
}

The transition does not morph a solid line into dots. The style switches at a discrete point during the transition.

Smooth Border Color Transition

.panel {
  border-top: 4px solid #1769aa;
  transition: border-top-color 0.3s ease;
}
.panel:hover {
  border-top-color: #c04b37;
}

Smooth Border Width Transition

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

Unlike border style, compatible border width and color values can interpolate smoothly.

Keyframe Style Changes

@keyframes change-border-style {
  0%, 100% {
    border-top-style: solid;
  }
  50% {
    border-top-style: dashed;
  }
}
.animated-panel {
  border-top: 5px solid #1769aa;
  animation: change-border-style 3s infinite;
}

Reduced Motion Preference

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

For smooth visual effects, animate border color, border width, or a separate decorative element rather than expecting border style keywords to interpolate.

Responsive Design

The top border style can change according to viewport width, container size, or component state.

Media Query

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

Container Query

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

Remove Border on Small Screens

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

Responsive Width and Style

.panel {
  border-top: 6px double #1769aa;
}
@media (max-width: 600px) {
  .panel {
    border-top-width: 2px;
    border-top-style: solid;
  }
}

Logical Border Alternative

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

Logical border properties can adapt to writing modes, while physical properties always target the same visual side.

Responsive border styling can simplify small-screen layouts without changing the HTML structure.

Practical Uses

The border-top-style property is useful for section separators, highlighted cards, navigation elements, and interface accents.

Section Separator

.section {
  padding-top: 24px;
  border-top: 2px solid #cccccc;
}

Featured Card

.featured-card {
  padding: 24px;
  background-color: #f3f7fa;
  border-top: 6px solid #1769aa;
}

Dashed Divider

.divider {
  border-top: 3px dashed #777777;
}

Dotted Information Panel

.information-panel {
  padding: 20px;
  border-top: 4px dotted #1769aa;
}

Double-Line Heading

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

Active Navigation Item

.nav-link {
  border-top: 3px solid transparent;
}
.nav-link.active {
  border-top-color: #1769aa;
}

Using a transparent border in the default state reserves space and helps prevent layout shifts when the active color appears.

Notification Panel

.notification {
  padding: 20px;
  background-color: #fff8e8;
  border-top: 5px solid #b7791f;
}

Conditional Border Style

.status-panel {
  border-top: 4px solid #1769aa;
}
.status-panel.is-pending {
  border-top-style: dashed;
}
.status-panel.is-complete {
  border-top-style: solid;
}

Different line styles can communicate component states, but important status information should also be conveyed through text or another accessible indicator.

border-top-style Example

The following example displays all ten border style keywords using the same width and color for comparison.

<div class="border-top-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>
.border-top-style-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 20px;
}
.border-top-style-demo .demo-box {
  box-sizing: border-box;
  min-height: 90px;
  padding: 20px;
  border-top-width: 8px;
  border-top-color: #1769aa;
  background-color: #e7f3fc;
  color: #173b5e;
  font-weight: bold;
  text-align: center;
}
.border-top-style-demo .none {
  border-top-style: none;
}
.border-top-style-demo .hidden {
  border-top-style: hidden;
}
.border-top-style-demo .dotted {
  border-top-style: dotted;
}
.border-top-style-demo .dashed {
  border-top-style: dashed;
}
.border-top-style-demo .solid {
  border-top-style: solid;
}
.border-top-style-demo .double {
  border-top-style: double;
}
.border-top-style-demo .groove {
  border-top-style: groove;
}
.border-top-style-demo .ridge {
  border-top-style: ridge;
}
.border-top-style-demo .inset {
  border-top-style: inset;
}
.border-top-style-demo .outset {
  border-top-style: outset;
}
Browser Result
none
dotted
dashed
solid
double
groove
ridge
inset
outset

The none and hidden examples have no visible top border. The other examples demonstrate the different line patterns and shading effects.

The exact appearance of dotted, dashed, and three-dimensional styles may vary between browsers.

Important Considerations

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

  • Purpose: Controls the line style of the physical top border.
  • Initial value: none.
  • Inheritance: The property is not inherited.
  • Accepted values: Ten predefined border style keywords.
  • Single value: Only one style keyword is allowed.
  • Width and color: Controlled separately by border-top-width and border-top-color.
  • Default width: The specified initial width is medium, but the computed width is zero for none and hidden.
  • Default color: The initial border color is currentColor.
  • Physical side: Always targets the top edge regardless of writing mode.
  • Logical alternative: Use border-block-start-style for the logical block-start edge.
  • none: Removes the visible border and has the lowest precedence in collapsed table border conflicts.
  • hidden: Removes the visible border and suppresses competing collapsed table borders.
  • double: Requires sufficient width for its two lines and gap to appear clearly.
  • 3D styles: Shading and appearance can vary between browsers.
  • Shorthand interactions: Later border, border-top, or border-style declarations may override the property.
  • Animation: Border style keywords change discretely rather than interpolating smoothly.
  • Layout: Changing from none to a visible style can change the computed border width and affect layout.
  • Browser support: The property is widely supported.

Use border-top-style when you need to change the appearance of the top border without modifying its width, color, or the other three border sides.

Browser Support

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

All ten standard border style keywords are supported in modern browsers without vendor prefixes.

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

This declaration creates a dashed top border in modern browsers.

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

Specifications

The border-top-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 border style keywords, their rendering behavior, and how border styles interact with border widths and colors.