Tillitsdone
down Scroll to discover

CSS border-left Customize Left Borders Easily

Learn how to use the CSS border-left property to customize the left border of elements.

Discover available options for width, style, and color.
thumbnail

Introduction

The border-left property in CSS is a shorthand that lets you set the width, style, and color of an element’s left border all at once. It’s useful for quickly adding a custom border to the left side of an element. This property is especially useful for creating UI elements like sidebars, navigation menus, and highlighted sections. By using border-left, you can enhance the visual clarity and hierarchy of your web pages.

Specification

The border-left property is part of the CSS Backgrounds and Borders Module Level 3 specification. This module defines the properties and behaviors related to the backgrounds and borders of elements in CSS. The border-left property is specifically addressed in the section on border shorthands, where it is described as a shorthand for setting the width, style, and color of the left border of an element.

Syntax

The border-left property in CSS allows you to set the width, style, and color of an element’s left border using a single line of code. This shorthand property combines three individual properties: border-left-width, border-left-style, and border-left-color.

Here is the basic syntax for the border-left property:

border-left: border-width border-style border-color;

Each component of the border-left property can be specified in any order, and one or two of them may be omitted. If any component is not specified, it will default to its initial value.

Examples of border-left Syntax

/* Sets only the width of the left border */
border-left: 1px;
/* Sets the width and style of the left border */
border-left: 2px dotted;
/* Sets the width, style, and color of the left border */
border-left: medium dashed blue;
/* Global values */
border-left: inherit;
border-left: initial;
border-left: revert;
border-left: revert-layer;
border-left: unset;

Values

The border-left property accepts the following values:

  • <border-width>: Specifies the width of the border. See border-left-width for more details.
  • <border-style>: Defines the style of the border. See border-left-style for more details.
  • <color>: Sets the color of the border. See border-left-color for more details.

By using these values, you can customize the appearance of the left border to fit your design needs.

Constituent Properties

The border-left property is a shorthand that combines several individual properties related to the left border of an element. This shorthand allows you to set the width, style, and color of the left border in a single declaration, making it easier to manage and customize the appearance of the border. The constituent properties of border-left are:

  1. border-left-width:
    • Description: This property specifies the width of the left border.
    • Values: Accepts lengths (e.g., px, em), and keywords like thin, medium, and thick.
    • Example:
      border-left-width: 2px; /* Sets the width of the left border to 2 pixels */
  2. border-left-style:
    • Description: This property defines the style of the left border.
    • Values: Includes options like none, dotted, dashed, solid, double, groove, ridge, inset, and outset.
    • Example:
      border-left-style: dashed; /* Sets the style of the left border to dashed */
  3. border-left-color:
    • Description: This property sets the color of the left border.
    • Values: Accepts any valid CSS color value, including named colors, hex codes, RGB values, etc.
    • Example:
      border-left-color: blue; /* Sets the color of the left border to blue */

By using the border-left shorthand, you can simplify your CSS and ensure consistency in the styling of the left border. Here’s an example of how the shorthand combines these properties:

border-left: 2px dashed blue; /* Sets a 2px wide dashed blue border on the left */

Formal Definition

The border-left property in CSS is formally defined as a shorthand property that encompasses three individual properties related to the left border of an element. This shorthand allows developers to set the width, style, and color of the left border in a single declaration, making it a powerful tool for web design and development.

Initial Value

The initial value of the border-left property is a combination of the initial values of its constituent properties:

  • border-left-width: medium
  • border-left-style: none
  • border-left-color: currentcolor

Applies To

The border-left property can be applied to all elements, including the ::first-letter pseudo-element. This makes it a versatile property for customizing the appearance of various UI components.

Inherited

No, the border-left property is not inherited from the parent element by default.

Computed Value

The computed value of the border-left property is determined by the values of its constituent properties:

  • border-left-width: The absolute length or 0 if the border-left-style is none or hidden.
  • border-left-style: As specified in the CSS.
  • border-left-color: The computed color value.

Animation Type

The border-left property can be animated based on the types of its constituent properties:

  • border-left-color: Animates as a color value, with interpolation occurring on the red, green, and blue components.
  • border-left-style: Animates discretely, meaning it can switch between styles without intermediate steps.
  • border-left-width: Animates as a length, with interpolation occurring as floating-point numbers.

Formal Syntax

The border-left property in CSS follows a specific syntax that allows you to set the width, style, and color of the left border of an element. The formal syntax is defined as follows:

border-left: <line-width> || <line-style> || <color>;

Each component of the border-left property can be specified in any order, and one or two of them may be omitted. If any component is not specified, it will default to its initial value.

Components of the Formal Syntax

  1. <line-width>:
    • Values: <length> | thin | medium | thick
    • Description: Specifies the width of the border. You can use various units to define the width, such as pixels (px), ems (em), or predefined keywords like thin, medium, and thick.
  2. <line-style>:
    • Values: none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset
    • Description: Defines the style of the border. This can include options like none, dotted, dashed, solid, double, groove, ridge, inset, and outset. Each style creates a unique visual effect for the border.
  3. <color>:
    • Values: Any valid CSS color value, including named colors, hex codes, RGB values, etc.
    • Description: Sets the color of the border. You can use any valid CSS color value to customize the appearance of the left border.

Global Values

In addition to the specific values for width, style, and color, the border-left property also accepts global values that can be applied to any CSS property:

  • initial: Resets the property to its default value.
  • inherit: Inherits the value from the parent element.
  • revert: Resets the property to the user agent’s default.
  • revert-layer: Resets the property to the next outer layer’s value.
  • unset: Resets the property to its natural value, which means it behaves like inherit if the property is inherited or like initial if not.

Example of Formal Syntax

/* Sets the width, style, and color of the left border */
border-left: 2px dashed blue;
/* Sets only the width of the left border */
border-left: 1px;
/* Sets the width and style of the left border */
border-left: 2px dotted;
/* Global values */
border-left: inherit;
border-left: initial;
border-left: revert;
border-left: revert-layer;
border-left: unset;

Examples

The border-left property in CSS is a versatile tool for adding a left border to elements. Here are several examples demonstrating how to use this property effectively:

Example 1: Basic Usage

This example shows how to apply a simple solid left border to a div element.

HTML:

<div class="example1">This box has a border on the left side.</div>

CSS:

.example1 {
border-left: 4px solid blue;
background-color: gold;
height: 100px;
width: 100px;
font-weight: bold;
text-align: center;
}

Example 2: Different Border Styles

This example demonstrates how to apply different border styles to multiple elements.

HTML:

<div class="example2 solid">3px solid steelblue border</div>
<div class="example2 double">5px double lightblue border</div>
<div class="example2 dashed">3px dashed red border</div>

CSS:

.example2 {
background-color: lightgray;
height: 50px;
width: 200px;
margin: 10px;
font-weight: bold;
text-align: center;
}
.solid {
border-left: 3px solid steelblue;
}
.double {
border-left: 5px double lightblue;
}
.dashed {
border-left: 3px dashed red;
}

Example 3: Using Global Values

This example demonstrates how to use global values with the border-left property.

HTML:

<div class="example3 inherit">Inherited border</div>
<div class="example3 initial">Initial border</div>
<div class="example3 revert">Revert border</div>

CSS:

.example3 {
background-color: lightcoral;
height: 50px;
width: 200px;
margin: 10px;
font-weight: bold;
text-align: center;
}
.inherit {
border-left: inherit;
}
.initial {
border-left: initial;
}
.revert {
border-left: revert;
}

Browser Compatibility

The border-left property is widely supported across all major web browsers, making it a reliable choice for adding left borders to elements in your web designs. This property has been a part of the CSS specification for many years, ensuring compatibility with both modern and older browsers.

Browser Support

BrowserVersionRelease Date
Google Chrome1.0Dec 2008
Firefox1.0Nov 2004
Internet Explorer4.0Sep 1997
Microsoft Edge12.0Jul 2015
Opera3.5Nov 1998
Safari1.0Jun 2003

Key Points

  • Google Chrome: Supported since the first version in December 2008.
  • Firefox: Supported since the initial release in November 2004.
  • Internet Explorer: Supported since version 4.0 in September 1997.
  • Microsoft Edge: Supported since the first version in July 2015.
  • Opera: Supported since version 3.5 in November 1998.
  • Safari: Supported since the first version in June 2003.

Ensuring Compatibility

While the border-left property is well-supported, it’s always a good practice to test your web designs across different browsers and devices to ensure consistent appearance and functionality.

Conclusion

The border-left property is a powerful and versatile tool for web developers and designers. Its widespread browser support makes it a reliable choice for enhancing the visual design of your web pages.

See Also

To further enhance your understanding and usage of CSS properties related to borders, you may find the following resources helpful:

These resources will help you create more sophisticated and visually appealing web designs.

icons/css-4.svg CSS Blogs
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.