CSS border-right-width Property
The border-right-width property sets the thickness of an element's right border.
It accepts the keywords thin, medium, and thick, or a non-negative CSS length such as 1px, 0.25rem, or 0.5em. The property changes only the width component, leaving the specified border style and color unchanged.
The property controls the physical right border regardless of writing mode or text direction. A visible border style is required for the specified width to produce a visible border.
border-right-width Syntax
The property accepts a width keyword, a non-negative length, or a CSS-wide keyword.
selector {
border-right-width: 5px;
}
The general syntax is:
selector {
border-right-width: <line-width>;
}
Keyword Values
.thin-border {
border-right-width: thin;
}
.medium-border {
border-right-width: medium;
}
.thick-border {
border-right-width: thick;
}
Pixel Width
.panel {
border-right-width: 6px;
}
rem Width
.panel {
border-right-width: 0.375rem;
}
em Width
.panel {
border-right-width: 0.5em;
}
Zero Width
.panel {
border-right-width: 0;
}
Calculated Width
.panel {
border-right-width: calc(2px + 0.25rem);
}
Custom Property
.panel {
border-right-width: var(--accent-width, 5px);
}
CSS-Wide Keywords
.inherited {
border-right-width: inherit;
}
.reset {
border-right-width: initial;
}
.unset {
border-right-width: unset;
}
.reverted {
border-right-width: revert;
}
.layer-reverted {
border-right-width: revert-layer;
}
Negative lengths and percentage values are not accepted. The unit may be omitted when the width is zero.
Property Values
The border-right-width property supports three width keywords and non-negative CSS lengths.
| Value | Description |
|---|---|
thin |
Uses the browser's thin border width. |
medium |
Uses the browser's medium border width. This is the initial value. |
thick |
Uses the browser's thick border width. |
<length> |
Sets a non-negative border width using a CSS length unit. |
0 |
Sets the border width to zero. |
inherit |
Inherits the computed right border width from the parent. |
initial |
Resets the width to medium, subject to the border style. |
unset |
Resets the width to medium because the property is not inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | medium |
| Inherited | No |
| Applies to | Elements that support border properties |
| Computed value | Absolute length, or zero when border-right-style is none or hidden |
| Animation type | By computed value type (length) |
| Percentages | Not accepted |
| Negative values | Not accepted |
| Property type | Longhand |
| Physical edge | Right |
The specified width determines the border's thickness only when the corresponding border style is not none or hidden.
How It Works
The browser uses border-right-width to determine the thickness of the right border when a visible border style is present.
Step 1: Set the Width
.panel {
border-right-width: 6px;
}
No right border appears because the initial border style is none.
Step 2: Add a Visible Style
.panel {
border-right-width: 6px;
border-right-style: solid;
}
The browser draws a 6-pixel solid border using currentcolor.
Step 3: Set the Color
.panel {
border-right-width: 6px;
border-right-style: solid;
border-right-color: #1769aa;
}
The right border is now 6 pixels wide and blue.
Step 4: Increase the Width
.panel {
border-right: 6px solid #1769aa;
border-right-width: 12px;
}
The border becomes 12 pixels wide while retaining its style and color.
Step 5: Remove the Width
.panel {
border-right: 6px solid #1769aa;
border-right-width: 0;
}
The border is no longer visible because its width is zero.
Use the longhand when changing the border thickness without resetting its existing style or color.
Keyword Widths
The thin, medium, and thick keywords provide predefined border widths.
thin
.panel {
border-right: thin solid #1769aa;
}
medium
.panel {
border-right: medium solid #1769aa;
}
thick
.panel {
border-right: thick solid #1769aa;
}
Comparing Keyword Widths
.thin {
border-right: thin solid #1769aa;
}
.medium {
border-right: medium solid #1769aa;
}
.thick {
border-right: thick solid #1769aa;
}
The browser determines the exact thickness of each keyword. Common implementations use approximately 1 pixel for thin, 3 pixels for medium, and 5 pixels for thick, but these values are not guaranteed.
Default Width
.panel {
border-right-style: solid;
border-right-color: #1769aa;
}
Because no width is specified, the browser uses the initial medium value.
Use explicit lengths when a design requires a predictable border thickness.
CSS Length Units
The border-right-width property supports non-negative CSS lengths, including absolute and relative units.
Pixels
.panel {
border-right: 5px solid #1769aa;
}
Pixels are commonly used for precise borders and dividers.
rem Units
.panel {
border-right: 0.375rem solid #1769aa;
}
The width is based on the root element's font size.
em Units
.panel {
border-right: 0.5em solid #1769aa;
}
The width is based on the element's font size.
Viewport Units
.panel {
border-right: 0.5vw solid #1769aa;
}
The width changes with the viewport width. This can produce unusually thick borders on large screens.
Container Query Units
.panel-container {
container-type: inline-size;
}
.panel {
border-right: 1cqi solid #1769aa;
}
The width is based on the query container's inline size.
Using calc()
.panel {
border-right: calc(2px + 0.25rem) solid #1769aa;
}
Using clamp()
.panel {
border-right: clamp(2px, 0.5vw, 8px) solid #1769aa;
}
The calculated width is constrained between 2 and 8 pixels.
Using min()
.panel {
border-right: min(6px, 0.5vw) solid #1769aa;
}
Using max()
.panel {
border-right: max(2px, 0.25rem) solid #1769aa;
}
Calculated values must resolve to a valid non-negative length. Percentage values are not supported as border widths.
Zero and Invalid Values
The right border width must be non-negative. A width of zero is valid, but negative values and percentages are not.
Valid Zero
.panel {
border-right-width: 0;
}
Zero With a Unit
.panel {
border-right-width: 0px;
}
Both declarations set the width to zero.
Invalid Negative Width
.panel {
border-right-width: -5px;
}
Negative border widths are invalid. The browser ignores this declaration.
Invalid Percentage
.panel {
border-right-width: 10%;
}
Percentage values are not accepted.
Invalid Unitless Length
.panel {
border-right-width: 5;
}
A nonzero length requires a unit.
Valid Calculated Width
.panel {
border-right-width: max(0px, calc(8px - 0.5rem));
}
The max() function prevents the calculated width from becoming negative.
If a width declaration is invalid, the browser ignores it or handles it according to the applicable computed-value rules.
Border Visibility
A nonzero border-right-width does not guarantee a visible border. The style and color also affect the result.
Width Without Style
.panel {
border-right-width: 8px;
border-right-color: #1769aa;
}
No right border appears because the initial border style is none.
Visible Border
.panel {
border-right-width: 8px;
border-right-style: solid;
border-right-color: #1769aa;
}
Style none
.panel {
border-right-width: 8px;
border-right-style: none;
border-right-color: #1769aa;
}
The computed width becomes zero because the style is none.
Style hidden
.panel {
border-right-width: 8px;
border-right-style: hidden;
border-right-color: #1769aa;
}
The computed width also becomes zero.
Transparent Color
.panel {
border-right: 8px solid transparent;
}
The border occupies space but is not visibly painted.
Zero Width
.panel {
border-right: 0 solid #1769aa;
}
The border is not visible because its thickness is zero.
When a right border is missing, inspect the computed width, style, and color before changing the width value.
The CSS Box Model
The right border is part of the CSS box model. Its width contributes to the total horizontal space occupied by an element.
Content Width and Border
.panel {
width: 300px;
padding: 20px;
border-right: 10px solid #1769aa;
}
With the default content-box sizing, the declared 300-pixel width applies to the content area.
If the left border is zero, the outer width excluding margins is:
300px content + 40px padding + 10px right border = 350px
Increasing the Border Width
.panel {
width: 300px;
padding: 20px;
border-right: 20px solid #1769aa;
}
The outer width increases to 360 pixels, assuming no other borders.
Removing the Border Width
.panel {
width: 300px;
padding: 20px;
border-right: 0 solid #1769aa;
}
The outer width becomes 340 pixels.
Margin and Border
.panel {
width: 300px;
padding: 20px;
margin-right: 15px;
border-right: 10px solid #1769aa;
}
The right margin adds spacing outside the border. It is not included in the border width.
Border vs. Outline
.panel {
border-right: 6px solid #1769aa;
outline: 2px solid #27ae60;
}
The border participates in the box model. The outline is drawn outside the border edge without taking up layout space.
Consider the box model when changing border widths on fixed-size elements or closely spaced layouts.
box-sizing
The box-sizing property determines whether the declared width includes borders and padding.
content-box
.panel {
box-sizing: content-box;
width: 300px;
padding: 20px;
border-right: 10px solid #1769aa;
}
The content width is 300 pixels. Padding and the right border increase the element's outer width.
border-box
.panel {
box-sizing: border-box;
width: 300px;
padding: 20px;
border-right: 10px solid #1769aa;
}
The declared width includes the content, padding, and borders. The outer width remains 300 pixels, assuming the specified width can accommodate those components.
Increasing Width With border-box
.panel {
box-sizing: border-box;
width: 300px;
padding: 20px;
border-right: 20px solid #1769aa;
}
The border becomes thicker, and the available content width decreases.
Global border-box Sizing
*, *::before, *::after {
box-sizing: border-box;
}
This common layout rule makes declared widths include padding and borders.
Using border-box can make border width changes easier to manage, although large borders can still affect available content space.
Shorthand Interactions
The border-right-width property can be set or reset by several border shorthand properties.
border-right Shorthand
.panel {
border-right: 6px solid #1769aa;
}
This sets the right border width, style, and color.
Override the Width
.panel {
border-right: 6px solid #1769aa;
border-right-width: 12px;
}
The right border becomes 12 pixels wide.
Later Shorthand Reset
.panel {
border-right-width: 12px;
border-right: solid #1769aa;
}
The later shorthand resets the width to medium.
border-width Shorthand
.panel {
border-width: 2px 4px 6px 8px;
}
The four values apply to the top, right, bottom, and left borders. The right border width is 4 pixels.
Override border-width
.panel {
border: 2px solid #1769aa;
border-width: 4px;
border-right-width: 10px;
}
All borders are 4 pixels wide except the right border, which is 10 pixels wide.
border Shorthand
.panel {
border-right-width: 12px;
border: 2px solid #1769aa;
}
The later border shorthand resets the right border width to 2 pixels.
border-inline-width Shorthand
.panel {
direction: ltr;
border-inline-width: 4px 10px;
}
In horizontal left-to-right writing, the second value sets the physical right border width to 10 pixels.
Use the longhand after a shorthand when you need to change only the right border thickness.
Physical vs. Logical Borders
The border-right-width property always targets the physical right edge. Logical border width properties adapt to writing mode and direction.
Physical Right Border Width
.panel {
border-right: 6px solid #1769aa;
border-right-width: 10px;
}
The right border remains 10 pixels wide regardless of writing direction.
Logical Inline-End Width
.panel {
border-inline-end: 6px solid #1769aa;
border-inline-end-width: 10px;
}
In horizontal left-to-right writing, this targets the right border. In horizontal right-to-left writing, it targets the left border.
Logical Inline-Start Width
.panel {
border-inline-start: 6px solid #1769aa;
border-inline-start-width: 10px;
}
In horizontal right-to-left writing, this targets the right border.
Writing Mode Comparison
| Writing Mode | Direction | Logical Width Property Matching Right |
|---|---|---|
horizontal-tb |
ltr |
border-inline-end-width |
horizontal-tb |
rtl |
border-inline-start-width |
vertical-rl |
ltr or rtl |
border-block-start-width |
vertical-lr |
ltr or rtl |
border-block-end-width |
Vertical Writing Example
.panel {
writing-mode: vertical-rl;
border-right: 6px solid #1769aa;
border-right-width: 10px;
}
The 10-pixel border remains on the physical right edge.
Use physical properties when the border must stay on a fixed edge and logical properties when it should follow the writing direction.
Cascade and Overrides
The CSS cascade determines which right border width applies when multiple declarations target the same element.
Later Declaration
.panel {
border-right-width: 4px;
border-right-width: 8px;
}
The later 8-pixel value wins when cascade priority is otherwise equal.
Higher Specificity
.panel {
border-right-width: 4px;
}
.panel.featured {
border-right-width: 10px;
}
The featured panel uses the more specific declaration.
Shorthand Override
.panel {
border-right-width: 12px;
border-right: 5px solid #1769aa;
}
The later shorthand sets the right border width to 5 pixels.
Longhand Override
.panel {
border-right: 5px solid #1769aa;
border-right-width: 12px;
}
The later longhand changes only the width.
Physical and Logical Conflict
.panel {
border-right: 5px solid #1769aa;
border-right-width: 8px;
border-inline-end-width: 12px;
}
In horizontal left-to-right writing, both width declarations target the right border. The later logical declaration wins when cascade priority is otherwise equal.
CSS Layers
@layer base, components;
@layer base {
.panel {
border-right-width: 4px;
}
}
@layer components {
.panel {
border-right-width: 10px;
}
}
For normal declarations, the later layer takes precedence.
When a right border width appears incorrect, check shorthand resets, specificity, cascade layers, and conflicting logical border declarations.
CSS Custom Properties
CSS custom properties can store reusable border widths for components and themes.
Shared Border Width
:root {
--accent-width: 6px;
}
.panel {
border-right: var(--accent-width) solid #1769aa;
}
Width With Fallback
.panel {
border-right: 5px solid #1769aa;
border-right-width: var(--accent-width, 6px);
}
The fallback is used when the custom property is unavailable or has the guaranteed-invalid value.
Component Variants
.notice {
--notice-width: 4px;
border-right: var(--notice-width) solid #1769aa;
}
.notice.important {
--notice-width: 8px;
}
.notice.critical {
--notice-width: 12px;
}
Responsive Custom Property
:root {
--divider-width: 6px;
}
@media (max-width: 600px) {
:root {
--divider-width: 3px;
}
}
.panel {
border-right: var(--divider-width) solid #1769aa;
}
Calculated Custom Property
:root {
--base-border-width: 4px;
}
.panel {
border-right: calc(var(--base-border-width) * 2) solid #1769aa;
}
Separate Border Components
:root {
--border-width: 6px;
--border-style: solid;
--border-color: #1769aa;
}
.panel {
border-right: var(--border-width) var(--border-style) var(--border-color);
}
Custom properties help maintain consistent border thickness across reusable components.
Interactive States
The right border width can change in response to hover, focus, selection, and validation states.
Hover State
.panel {
border-right: 4px solid #1769aa;
}
.panel:hover {
border-right-width: 8px;
}
Focus State
.form-field {
border-right: 2px solid #cccccc;
}
.form-field:focus {
border-right-width: 5px;
border-right-color: #1769aa;
}
Keyboard Focus
.form-field {
border-right: 2px solid #cccccc;
}
.form-field:focus-visible {
border-right-width: 5px;
border-right-color: #1769aa;
outline: 2px solid #1769aa;
outline-offset: 2px;
}
Selected Card
.card {
border-right: 3px solid #cccccc;
}
.card.is-selected {
border-right-width: 8px;
border-right-color: #1769aa;
}
Current Navigation Item
.nav-link {
border-right: 2px solid transparent;
}
.nav-link[aria-current="page"] {
border-right-width: 6px;
border-right-color: #1769aa;
}
Invalid Form Field
.form-field {
border-right: 2px solid #cccccc;
}
.form-field[aria-invalid="true"] {
border-right-width: 5px;
border-right-color: #c0392b;
}
Increasing border width can affect layout. For stable interactive components, consider reserving the desired border width and changing its color instead.
Transitions and Animation
The border-right-width property supports interpolation between compatible length values.
Basic Width Transition
.panel {
border-right: 4px solid #1769aa;
transition: border-right-width 0.3s ease;
}
.panel:hover {
border-right-width: 12px;
}
The right border gradually becomes thicker when the element is hovered.
Width and Color Transition
.panel {
border-right: 4px solid #1769aa;
transition: border-right-width 0.3s ease, border-right-color 0.3s ease;
}
.panel:hover {
border-right-width: 10px;
border-right-color: #27ae60;
}
Keyframe Animation
@keyframes right-border-width-change {
from {
border-right-width: 2px;
}
to {
border-right-width: 12px;
}
}
.animated-panel {
border-right: 2px solid #1769aa;
animation: right-border-width-change 2s ease-in-out infinite alternate;
}
Multiple Width Stops
@keyframes border-widths {
0% {
border-right-width: 2px;
}
50% {
border-right-width: 10px;
}
100% {
border-right-width: 4px;
}
}
.animated-panel {
border-right: 2px solid #1769aa;
animation: border-widths 4s ease-in-out infinite;
}
Reduced Motion Preference
.panel {
border-right: 4px solid #1769aa;
transition: border-right-width 0.3s ease;
}
.panel:hover {
border-right-width: 10px;
}
@media (prefers-reduced-motion: reduce) {
.panel {
transition: none;
}
}
Border width animations can trigger layout changes. For decorative effects that do not need to affect layout, consider using an outline, box shadow, or pseudo-element.
Responsive Design
The right border width can adapt to viewport size, container size, and layout requirements.
Media Query
.panel {
border-right: 8px solid #1769aa;
}
@media (max-width: 600px) {
.panel {
border-right-width: 4px;
}
}
Container Query
.panel-container {
container-type: inline-size;
}
.panel {
border-right: 4px solid #1769aa;
}
@container (min-width: 500px) {
.panel {
border-right-width: 10px;
}
}
Responsive Border Removal
.sidebar {
border-right: 2px solid #cccccc;
}
@media (max-width: 600px) {
.sidebar {
border-right-width: 0;
border-bottom: 2px solid #cccccc;
}
}
The right border disappears on smaller screens, and a bottom border provides separation instead.
Fluid Border Width
.panel {
border-right: clamp(2px, 0.5vw, 8px) solid #1769aa;
}
The border thickness changes with viewport width while remaining within the specified limits.
Print Styles
.panel {
border-right: 8px solid #1769aa;
}
@media print {
.panel {
border-right-width: 1px;
}
}
A thinner border may be more suitable for printed documents.
Responsive border widths can help maintain consistent visual balance across different screen sizes.
Practical Uses
The border-right-width property is useful for dividers, decorative accents, navigation indicators, and component variations.
Sidebar Divider
.sidebar {
padding-right: 20px;
border-right: 2px solid #d5dce3;
}
Featured Content Accent
.featured-panel {
padding: 20px;
border-right: 10px solid #1769aa;
}
Navigation Indicator
.nav-link {
border-right: 3px solid transparent;
}
.nav-link[aria-current="page"] {
border-right-width: 6px;
border-right-color: #1769aa;
}
Status Panel
.status-panel {
border-right: 4px solid #1769aa;
}
.status-panel.important {
border-right-width: 8px;
}
.status-panel.critical {
border-right-width: 12px;
}
Decorative Quote
blockquote {
margin: 20px 0;
padding-right: 20px;
border-right: 6px solid #1769aa;
}
Form Field Accent
.form-field {
border-right: 2px solid #cccccc;
}
.form-field:focus-visible {
border-right-width: 5px;
border-right-color: #1769aa;
}
Responsive Separator
.content-column {
border-right: 4px solid #d5dce3;
}
@media (max-width: 600px) {
.content-column {
border-right-width: 0;
}
}
Choose border widths that provide clear visual separation without overwhelming the surrounding content.
border-right-width Example
The following example demonstrates keyword and length-based right border widths using the same border style and color.
<div class="border-right-width-demo">
<div class="demo-box width-thin">thin</div>
<div class="demo-box width-medium">medium</div>
<div class="demo-box width-thick">thick</div>
<div class="demo-box width-1">1px</div>
<div class="demo-box width-3">3px</div>
<div class="demo-box width-6">6px</div>
<div class="demo-box width-10">10px</div>
<div class="demo-box width-16">16px</div>
<div class="demo-box width-zero">0</div>
</div>
.border-right-width-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}
.border-right-width-demo .demo-box {
box-sizing: border-box;
padding: 20px;
border-right-style: solid;
border-right-color: #1769aa;
background-color: #f3f8fc;
color: #173b5e;
font-weight: bold;
}
.border-right-width-demo .width-thin {
border-right-width: thin;
}
.border-right-width-demo .width-medium {
border-right-width: medium;
}
.border-right-width-demo .width-thick {
border-right-width: thick;
}
.border-right-width-demo .width-1 {
border-right-width: 1px;
}
.border-right-width-demo .width-3 {
border-right-width: 3px;
}
.border-right-width-demo .width-6 {
border-right-width: 6px;
}
.border-right-width-demo .width-10 {
border-right-width: 10px;
}
.border-right-width-demo .width-16 {
border-right-width: 16px;
}
.border-right-width-demo .width-zero {
border-right-width: 0;
}
Every box uses a solid blue right border. Only the border width changes.
The thin, medium, and thick examples use browser-defined widths. The pixel examples use explicit thicknesses, while the zero-width example has no visible border.
Important Considerations
Keep the following points in mind when using border-right-width:
- Purpose: Sets the thickness of the physical right border.
- Property type: Longhand.
- Initial value:
medium. - Inheritance: The property is not inherited.
- Accepted values:
thin,medium,thick, non-negative lengths, and CSS-wide keywords. - Keyword widths: Exact thicknesses are browser-defined.
- Length units: Supports pixels, relative font units, viewport units, and other valid CSS lengths.
- Percentages: Not accepted.
- Negative lengths: Not accepted.
- Zero: Removes the border's thickness.
- Border style: Must be visible for a nonzero computed width.
- none and hidden: Cause the computed border width to become zero.
- Border color: Determines the color of the visible border.
- Shorthand interactions: Later shorthand declarations can reset the width.
- Physical edge: Always targets the right side.
- Logical borders: Can target the same edge depending on writing mode and direction.
- Box model: The right border contributes to the element's horizontal dimensions.
- box-sizing: Determines how the border width affects declared element dimensions.
- Animation: Supports interpolation between compatible length values.
- Layout changes: Increasing border width can change element dimensions or available content space.
- Custom properties: Can store reusable width values.
- Responsive design: Supports media queries, container queries, and calculated lengths.
- Accessibility: Border thickness should not be the only indicator of an important interface state.
- Browser support: Supported by all major browsers.
Use border-right-width when changing the thickness of the right border without resetting its specified style or color.
Browser Support
The border-right-width property is widely supported in Chrome, Edge, Firefox, Safari, and other major browsers.
It is a long-established CSS property and does not require vendor prefixes. Support for newer length units and calculation functions depends on browser version.
.panel {
border-right-width: 6px;
border-right-style: solid;
border-right-color: #1769aa;
}
For current compatibility details, visit Can I Use? and search for border-right-width.
Specifications
The border-right-width property is defined in the CSS Backgrounds and Borders Module Level 3 specification.
CSS Backgrounds and Borders Module Level 3
The specification defines border width values, keyword behavior, and how computed border widths interact with border styles.
