CSS border-left-width Property
The border-left-width property sets the thickness of an element's left border.
It accepts non-negative CSS length values and the keywords thin, medium, and thick. The property controls only the width of the physical left border, leaving its style and color unchanged.
border-left-width Syntax
The property accepts a non-negative length or one of three predefined width keywords.
selector {
border-left-width: 5px;
}
The general syntax is:
selector {
border-left-width: <line-width>;
}
Pixel Width
.panel {
border-left-width: 5px;
}
Relative Width
.panel {
border-left-width: 0.5rem;
}
Thin Border
.panel {
border-left-width: thin;
}
Medium Border
.panel {
border-left-width: medium;
}
Thick Border
.panel {
border-left-width: thick;
}
Zero Width
.panel {
border-left-width: 0;
}
Calculated Width
.panel {
border-left-width: calc(2px + 0.2rem);
}
CSS Custom Property
.panel {
border-left-width: var(--accent-width);
}
CSS-Wide Keywords
.inherited {
border-left-width: inherit;
}
.reset {
border-left-width: initial;
}
.unset {
border-left-width: unset;
}
.reverted {
border-left-width: revert;
}
.layer-reverted {
border-left-width: revert-layer;
}
Negative lengths and percentages are not valid values for border-left-width.
Property Values
The border-left-width property accepts three width keywords, non-negative CSS lengths, and CSS-wide keywords.
| Value | Description |
|---|---|
thin |
A thin border width determined by the browser. |
medium |
A medium border width determined by the browser. This is the initial value. |
thick |
A thick border width determined by the browser. |
<length> |
A non-negative CSS length such as 1px, 0.25rem, or 0.5em. |
0 |
Sets the left border width to zero. |
calc() |
Calculates a width using a valid length expression that resolves to a non-negative value. |
var() |
Uses a custom property containing a valid width value. |
inherit |
Inherits the computed left border width from the parent. |
initial |
Resets the specified width to medium. |
unset |
Resets the specified 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 the corresponding border style is none or hidden |
| Animation type | By computed length |
| Percentages | Not accepted |
| Negative values | Not accepted |
| Property type | Longhand |
| Physical edge | Left |
The specified width does not guarantee a visible border. The corresponding border style must also allow the border to be drawn.
How It Works
The browser uses border-left-width to determine how much space the left border occupies when the border style is visible.
Step 1: Set the Width
.panel {
border-left-width: 5px;
}
No border appears because the initial border style is none.
Step 2: Add a Border Style
.panel {
border-left-width: 5px;
border-left-style: solid;
}
The border becomes visible using the initial currentcolor color.
Step 3: Set the Color
.panel {
border-left-width: 5px;
border-left-style: solid;
border-left-color: #1769aa;
}
The result is a 5-pixel solid blue left border.
Step 4: Change Only the Width
.panel {
border-left: 5px solid #1769aa;
border-left-width: 10px;
}
The left border becomes 10 pixels thick without changing its style or color.
Step 5: Use a Shorthand
.panel {
border-left: 10px solid #1769aa;
}
The shorthand sets the width, style, and color in one declaration.
Keyword Widths
The keywords thin, medium, and thick provide predefined border widths.
thin
.panel {
border-left: thin solid #1769aa;
}
Creates a thin border suitable for subtle separators.
medium
.panel {
border-left: medium solid #1769aa;
}
Creates a medium-width border. This is the initial border width.
thick
.panel {
border-left: thick solid #1769aa;
}
Creates a thicker border for stronger emphasis.
Keyword Comparison
.thin-panel {
border-left: thin solid #1769aa;
}
.medium-panel {
border-left: medium solid #1769aa;
}
.thick-panel {
border-left: thick solid #1769aa;
}
The browser determines the actual thickness of each keyword. Their relative ordering is maintained, but exact pixel measurements are not guaranteed.
Use explicit lengths when a design requires a precise border width.
Length Values
The property accepts non-negative CSS lengths, including absolute and relative units.
Pixels
.panel {
border-left: 5px solid #1769aa;
}
Pixels provide a straightforward way to specify border thickness.
rem Units
.panel {
border-left-width: 0.4rem;
border-left-style: solid;
border-left-color: #1769aa;
}
The width is calculated relative to the root element's font size.
em Units
.panel {
border-left-width: 0.4em;
border-left-style: solid;
border-left-color: #1769aa;
}
The width is calculated relative to the element's font size.
Viewport Units
.panel {
border-left-width: 0.5vw;
border-left-style: solid;
border-left-color: #1769aa;
}
The width is calculated relative to the viewport width.
Calculated Width
.panel {
border-left-width: calc(2px + 0.2rem);
border-left-style: solid;
border-left-color: #1769aa;
}
Clamped Width
.panel {
border-left-width: clamp(2px, 0.5vw, 8px);
border-left-style: solid;
border-left-color: #1769aa;
}
The clamp() function limits the calculated width between the minimum and maximum values.
Zero Width
.panel {
border-left-width: 0;
}
A zero-width border occupies no space.
Invalid Negative Width
.panel {
border-left-width: -5px;
}
This declaration is invalid because negative border widths are not allowed.
Invalid Percentage
.panel {
border-left-width: 10%;
}
Percentages are not accepted as border width values.
For most interfaces, pixels or relative font-based units provide predictable results.
Border Visibility
A nonzero border width does not always produce a visible border.
Width Without a Style
.panel {
border-left-width: 8px;
}
No border appears because the initial style is none.
Visible Border
.panel {
border-left: 8px solid #1769aa;
}
Style none
.panel {
border-left-width: 8px;
border-left-style: none;
border-left-color: #1769aa;
}
The computed border width becomes zero.
Style hidden
.panel {
border-left-width: 8px;
border-left-style: hidden;
border-left-color: #1769aa;
}
The computed border width also becomes zero. The hidden style has special behavior in collapsed table border conflicts.
Transparent Border
.panel {
border-left: 8px solid transparent;
}
The border retains its width and occupies space, but it is invisible.
Zero Width
.panel {
border-left: 0 solid #1769aa;
}
No visible line appears because the width is zero.
When a border does not appear, check its style, width, color, and any border-image settings.
Width, Style, and Color
The left border is controlled by three related longhand properties.
| Property | Purpose |
|---|---|
border-left-width |
Sets the thickness of the left border. |
border-left-style |
Sets the line style of the left border. |
border-left-color |
Sets the color of the left border. |
Individual Properties
.panel {
border-left-width: 6px;
border-left-style: solid;
border-left-color: #1769aa;
}
Equivalent Shorthand
.panel {
border-left: 6px solid #1769aa;
}
Change Width Only
.panel {
border-left: 6px solid #1769aa;
border-left-width: 12px;
}
Change Style Only
.panel {
border-left: 6px solid #1769aa;
border-left-style: dashed;
}
Change Color Only
.panel {
border-left: 6px solid #1769aa;
border-left-color: #27ae60;
}
Use the longhand properties when changing one component without resetting the others.
Shorthand Properties
Several CSS border shorthands can set or override border-left-width.
border-left Shorthand
.panel {
border-left: 6px solid #1769aa;
}
Sets the width, style, and color of the left border.
border-width Shorthand
.panel {
border-style: solid;
border-width: 2px 4px 6px 8px;
}
The four values apply to the top, right, bottom, and left borders, respectively. The left border becomes 8 pixels thick.
Two-Value border-width
.panel {
border-style: solid;
border-width: 3px 7px;
}
The top and bottom borders are 3 pixels thick. The left and right borders are 7 pixels thick.
border Shorthand
.panel {
border: 2px solid #cccccc;
border-left-width: 8px;
}
All borders begin at 2 pixels, but the left border becomes 8 pixels thick.
Later Shorthand Override
.panel {
border-left-width: 10px;
border-left: 4px solid #1769aa;
}
The later shorthand changes the left border width to 4 pixels.
Omitted Width in a Shorthand
.panel {
border-left-width: 10px;
border-left: solid #1769aa;
}
The later shorthand resets the specified border width to medium.
Shorthand declarations reset omitted components to their initial values rather than preserving earlier declarations.
Physical vs. Logical Border Widths
The border-left-width property always controls the physical left border. Logical border widths adapt to writing mode and direction.
| Writing Mode | Direction | Logical Property Matching Left |
|---|---|---|
horizontal-tb |
ltr |
border-inline-start-width |
horizontal-tb |
rtl |
border-inline-end-width |
vertical-rl |
ltr or rtl |
border-block-end-width |
vertical-lr |
ltr or rtl |
border-block-start-width |
Physical Left Border
.panel {
border: 2px solid #1769aa;
border-left-width: 8px;
}
The left border remains 8 pixels thick regardless of writing direction.
Logical Inline-Start Border
.panel {
border: 2px solid #1769aa;
border-inline-start-width: 8px;
}
In horizontal left-to-right writing, the left border becomes 8 pixels thick. In right-to-left writing, the right border becomes 8 pixels thick.
Logical Inline-End Border
.panel {
border: 2px solid #1769aa;
border-inline-end-width: 8px;
}
In horizontal left-to-right writing, the right border becomes 8 pixels thick. In right-to-left writing, the left border becomes 8 pixels thick.
Vertical Writing
.panel {
writing-mode: vertical-rl;
border: 2px solid #1769aa;
border-left-width: 8px;
}
The left border remains 8 pixels thick even though the inline axis is vertical.
Use physical border widths when the left edge must remain fixed. Use logical border widths when the border should follow the writing direction.
Box Sizing and Layout
Border width contributes to an element's dimensions and can affect the space available for its content.
Default content-box
.panel {
box-sizing: content-box;
width: 300px;
padding: 20px;
border-left: 10px solid #1769aa;
border-right: 2px solid #cccccc;
}
The declared width applies to the content box. Padding and borders are added outside that width.
Ignoring margins, the total outer width is 352 pixels: 300 pixels of content, 40 pixels of horizontal padding, and 12 pixels of horizontal borders.
Using border-box
.panel {
box-sizing: border-box;
width: 300px;
padding: 20px;
border-left: 10px solid #1769aa;
border-right: 2px solid #cccccc;
}
The declared width includes the padding and borders. The total outer width remains 300 pixels, while the content area becomes narrower.
Changing Border Width on Hover
.panel {
border-left: 4px solid #1769aa;
}
.panel:hover {
border-left-width: 12px;
}
Changing the border width can affect layout or content space, depending on the element's sizing rules.
Avoiding Layout Changes
.panel {
border-left: 12px solid transparent;
}
.panel:hover {
border-left-color: #1769aa;
}
The border width remains constant, so the hover state does not change the border's contribution to layout.
Outline Alternative
.panel {
border-left: 4px solid #1769aa;
}
.panel:focus-visible {
outline: 3px solid #1769aa;
outline-offset: 3px;
}
Outlines do not take up space in the CSS box model and can provide a visible focus indicator without changing border dimensions.
Cascade and Overrides
The CSS cascade determines which left border width applies when multiple declarations target the same edge.
Later Declaration
.panel {
border-left-width: 4px;
border-left-width: 8px;
}
The later 8-pixel declaration wins when both have equal cascade priority.
Higher Specificity
.panel {
border-left-width: 4px;
}
.panel.featured {
border-left-width: 10px;
}
The featured panel uses a 10-pixel left border when its border style is visible.
Shorthand Override
.panel {
border-left: 4px solid #1769aa;
border-left-width: 10px;
}
The later longhand changes the width to 10 pixels.
Physical and Logical Conflict
.panel {
border: 2px solid #1769aa;
border-left-width: 8px;
border-inline-start-width: 12px;
}
In horizontal left-to-right writing, the later logical declaration changes the left border width to 12 pixels when cascade priority is otherwise equal.
In horizontal right-to-left writing, the logical declaration targets the right border instead, leaving the physical left border at 8 pixels.
CSS Layers
@layer base, components;
@layer base {
.panel {
border-left-width: 4px;
}
}
@layer components {
.panel {
border-left-width: 8px;
}
}
For normal declarations, the later layer takes precedence.
When a border width appears incorrect, check shorthand resets, selector specificity, cascade layers, border styles, and conflicting logical declarations.
CSS Custom Properties
CSS custom properties allow border widths to be reused across components and themes.
Shared Width
:root {
--accent-border-width: 6px;
}
.panel {
border-left-width: var(--accent-border-width);
border-left-style: solid;
border-left-color: #1769aa;
}
Fallback Width
.panel {
border-left: 5px solid #1769aa;
border-left-width: var(--panel-width, 5px);
}
The fallback is used when the custom property is unavailable or has the guaranteed-invalid value.
Component Variants
.notice {
--notice-border-width: 5px;
border-left: var(--notice-border-width) solid #1769aa;
}
.notice.featured {
--notice-border-width: 10px;
}
.notice.compact {
--notice-border-width: 2px;
}
Theme-Based Width
:root {
--panel-border-width: 4px;
}
[data-theme="bold"] {
--panel-border-width: 8px;
}
.panel {
border-left: var(--panel-border-width) solid #1769aa;
}
Calculated Custom Property
:root {
--base-border-width: 2px;
}
.panel {
border-left-width: calc(var(--base-border-width) * 3);
border-left-style: solid;
border-left-color: #1769aa;
}
Custom properties help maintain consistent border thickness across multiple components.
Interactive States
The left border width can change in response to hover, focus, selection, and other interface states.
Hover State
.panel {
border-left: 4px solid #1769aa;
}
.panel:hover {
border-left-width: 8px;
}
Focus State
.form-field {
border-left: 3px solid #cccccc;
}
.form-field:focus {
border-left-width: 6px;
}
Keyboard Focus
.form-field {
border-left: 3px solid #cccccc;
}
.form-field:focus-visible {
border-left-width: 6px;
outline: 2px solid #1769aa;
outline-offset: 2px;
}
The outline provides an additional visible keyboard focus indicator.
Selected Item
.selectable-panel {
border-left: 3px solid #cccccc;
}
.selectable-panel.is-selected {
border-left-width: 8px;
border-left-color: #1769aa;
}
Current Navigation Item
.nav-link {
border-left: 4px solid transparent;
}
.nav-link[aria-current="page"] {
border-left-width: 4px;
border-left-color: #1769aa;
}
Invalid Form Field
.form-field {
border-left: 3px solid #cccccc;
}
.form-field[aria-invalid="true"] {
border-left-width: 6px;
border-left-color: #c0392b;
}
Changing border width can affect layout. For states that should not shift nearby content, consider keeping the width constant and changing the border color instead.
Transitions and Animation
The border-left-width property can transition and animate between compatible computed length values.
Basic Width Transition
.panel {
border-left: 4px solid #1769aa;
transition: border-left-width 0.3s ease;
}
.panel:hover {
border-left-width: 12px;
}
The border gradually becomes thicker when hovered.
Width and Color Transition
.panel {
border-left: 4px solid #1769aa;
transition: border-left-width 0.3s ease, border-left-color 0.3s ease;
}
.panel:hover {
border-left-width: 10px;
border-left-color: #27ae60;
}
Keyframe Animation
@keyframes border-width-change {
from {
border-left-width: 4px;
}
to {
border-left-width: 12px;
}
}
.animated-panel {
border-left: 4px solid #1769aa;
animation: border-width-change 2s ease-in-out infinite alternate;
}
Reduced Motion Preference
.panel {
border-left: 4px solid #1769aa;
transition: border-left-width 0.3s ease;
}
.panel:hover {
border-left-width: 12px;
}
@media (prefers-reduced-motion: reduce) {
.panel {
transition: none;
}
}
Avoiding Layout Animation
.panel {
border-left: 12px solid transparent;
transition: border-left-color 0.3s ease;
}
.panel:hover {
border-left-color: #1769aa;
}
This alternative keeps the border width constant while revealing its color.
Animating border width can trigger layout recalculation. Use it selectively, especially in interfaces containing many elements.
Responsive Design
The left border width can adapt to viewport size, container size, and design requirements.
Media Query
.panel {
border-left: 8px solid #1769aa;
}
@media (max-width: 600px) {
.panel {
border-left-width: 4px;
}
}
Container Query
.panel-container {
container-type: inline-size;
}
.panel {
border-left: 4px solid #1769aa;
}
@container (min-width: 500px) {
.panel {
border-left-width: 10px;
}
}
Fluid Border Width
.panel {
border-left-width: clamp(3px, 0.5vw, 10px);
border-left-style: solid;
border-left-color: #1769aa;
}
Relative Units
.panel {
border-left-width: 0.4rem;
border-left-style: solid;
border-left-color: #1769aa;
}
Responsive Custom Property
:root {
--panel-border-width: 8px;
}
@media (max-width: 600px) {
:root {
--panel-border-width: 4px;
}
}
.panel {
border-left: var(--panel-border-width) solid #1769aa;
}
Responsive border widths can maintain visual balance across different screen and component sizes.
Practical Uses
The border-left-width property is useful for emphasizing content, distinguishing components, and creating visual hierarchy.
Information Notice
.info-notice {
padding: 20px;
border-left: 5px solid #1769aa;
background-color: #f3f8fc;
}
Featured Content
.featured-panel {
padding: 20px;
border-left: 10px solid #27ae60;
background-color: #f4fbf6;
}
Subtle Separator
.sidebar-item {
padding-left: 15px;
border-left: 2px solid #cccccc;
}
Decorative Quote
blockquote {
margin: 20px 0;
padding-left: 20px;
border-left: 8px solid #1769aa;
}
Selected Card
.card {
border-left: 3px solid #cccccc;
}
.card.is-selected {
border-left-width: 8px;
border-left-color: #1769aa;
}
Active Navigation
.nav-link {
border-left: 4px solid transparent;
}
.nav-link[aria-current="page"] {
border-left-color: #1769aa;
}
Form Validation
.form-field {
border-left: 3px solid #cccccc;
}
.form-field[aria-invalid="true"] {
border-left-width: 6px;
border-left-color: #c0392b;
}
Use consistent border widths to establish a clear visual hierarchy. Important interface states should also be communicated through text or accessible attributes.
border-left-width Example
The following example demonstrates different left border widths while keeping the style and color consistent.
<div class="border-left-width-demo">
<div class="demo-box width-1">1px Border</div>
<div class="demo-box width-3">3px Border</div>
<div class="demo-box width-5">5px Border</div>
<div class="demo-box width-8">8px Border</div>
<div class="demo-box width-12">12px Border</div>
<div class="demo-box width-16">16px Border</div>
</div>
.border-left-width-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}
.border-left-width-demo .demo-box {
padding: 20px;
border-left-style: solid;
border-left-color: #1769aa;
background-color: #f3f8fc;
color: #173b5e;
font-weight: bold;
}
.border-left-width-demo .width-1 {
border-left-width: 1px;
}
.border-left-width-demo .width-3 {
border-left-width: 3px;
}
.border-left-width-demo .width-5 {
border-left-width: 5px;
}
.border-left-width-demo .width-8 {
border-left-width: 8px;
}
.border-left-width-demo .width-12 {
border-left-width: 12px;
}
.border-left-width-demo .width-16 {
border-left-width: 16px;
}
Each example uses a solid blue left border. Only the border width changes.
The thicker borders create stronger visual emphasis and occupy more space along the left edge.
Important Considerations
Keep the following points in mind when using border-left-width:
- Purpose: Sets the thickness of the physical left border.
- Property type: Longhand.
- Initial value:
medium. - Inheritance: The property is not inherited.
- Physical edge: Always targets the left side.
- Keywords:
thin,medium, andthick. - Length values: Non-negative CSS lengths are accepted.
- Percentages: Not accepted.
- Negative values: Not accepted.
- Zero width: Produces no visible border thickness.
- Style none: Causes the computed border width to become zero.
- Style hidden: Causes the computed border width to become zero.
- Transparent color: Can preserve border space without displaying a visible line.
- Style: Controlled separately by
border-left-style. - Color: Controlled separately by
border-left-color. - Shorthand:
border-leftsets width, style, and color together. - Shorthand resets: Later shorthand declarations may replace the width.
- Logical borders: May target the same physical edge depending on writing mode and direction.
- Box sizing: Border width contributes to the element's box dimensions.
- Animation: Compatible computed length values can be interpolated.
- Layout: Changing border width may affect layout or content space.
- Custom properties: Can store reusable border widths.
- Responsive design: Supports media queries and container queries.
- Accessibility: Do not rely on border thickness alone to communicate important states.
- Browser support: Supported by all major browsers.
Use border-left-width when the left border's thickness needs to change without resetting its style or color.
Browser Support
The border-left-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 CSS functions used to calculate widths may vary by browser version.
.panel {
border-left-width: 6px;
border-left-style: solid;
border-left-color: #1769aa;
}
For current compatibility details, visit Can I Use? and search for border-left-width.
Specifications
The border-left-width 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 width values and how border styles affect computed border widths.
