- Services
- Case Studies
- Technologies
- NextJs development
- Flutter development
- NodeJs development
- ReactJs development
- About
- Contact
- Tools
- Blogs
- FAQ
rick@tillitsdone.com
+66824564755
Mastering CSS border-width A Comprehensive Guide
Discover the CSS border-width property, its use cases, and available options.
Learn how to set border widths for different sides of an element and enhance your web design.
Learn how to set border widths for different sides of an element and enhance your web design.

Formal Definition
The border-width
property in CSS is a shorthand that sets the width of an element’s border. It combines the values of border-top-width
, border-right-width
, border-bottom-width
, and border-left-width
.
Initial Value:
medium
for all sides.
Applies To:
- All elements, including the
::first-letter
pseudo-element.
Inherited:
- No, the
border-width
property is not inherited.
Computed Value:
- The absolute length or
0
if the border style isnone
orhidden
.
Animation Type:
- The
border-width
property is animatable. Each constituent property is animated as a length value.
Syntax:
border-width = <line-width>{1,4}
<line-width> = <length> | thin | medium | thick
Explanation:
<line-width>
: Defines the border width as a nonnegative length or a keyword (thin
,medium
,thick
). The exact thickness is implementation-specific.
Examples
Example: Applying Different Values
This example covers using single, double, triple, and quadruple values to set the border width for various sides of the element.
HTML
<!DOCTYPE html><html><head> <title>border-width Property Examples</title> <style> div { margin-bottom: 20px; border-style: solid; border-color: blue; } </style></head><body> <h1 style="color: green;">Website</h1>
<!-- Single Value --> <p>border-width: 5px</p> <div style="border-width: 5px;"> This div has a 5px border on all sides. </div>
<!-- Two Values --> <p>border-width: 5px 10px</p> <div style="border-width: 5px 10px;"> This div has a 5px border for the top/bottom and 10px for the left/right. </div>
<!-- Three Values --> <p>border-width: 1px 2em 1.5cm</p> <div style="border-width: 1px 2em 1.5cm;"> This div has a 1px border for the top, 2em for the left/right, and 1.5cm for the bottom. </div>
<!-- Four Values --> <p>border-width: 1px 2em 0 4rem</p> <div style="border-width: 1px 2em 0 4rem;"> This div has a 1px border for the top, 2em for the right, 0 for the bottom, and 4rem for the left. </div></body></html>
Explanation:
- Single Value:
border-width: 5px;
sets a 5px border for all sides. - Two Values:
border-width: 5px 10px;
sets a 5px border for the top/bottom and 10px for the left/right. - Three Values:
border-width: 1px 2em 1.5cm;
sets a 1px border for the top, 2em for the left/right, and 1.5cm for the bottom. - Four Values:
border-width: 1px 2em 0 4rem;
sets a 1px border for the top, 2em for the right, 0 for the bottom, and 4rem for the left.
Example: Three Values for Border Width
HTML
<!DOCTYPE html><html><head> <title>Border Width Property - Three Values</title> <style> div { margin-bottom: 10px; border-style: solid; border-color: blue; } </style></head><body> <h1 style="color: green;">Website</h1> <p>border-width: 5px 10px 15px</p> <div style="border-width: 5px 10px 15px;"> This div has a border of 5px for the top, 10px for the right/left, and 15px for the bottom. </div></body></html>
Example: Four Values for Each Side
HTML
<!DOCTYPE html><html><head> <title>Border Width Property - Four Values</title> <style> div { margin-bottom: 10px; border-style: solid; border-color: black; } </style></head><body> <h1 style="color: green;">Website</h1> <p>border-width: 5px 10px 15px 20px</p> <div style="border-width: 5px 10px 15px 20px;"> This div has a border of 5px for the top, 10px for the right, 15px for the bottom, and 20px for the left. </div></body></html>
Browser Compatibility
The border-width
property works well across all major web browsers, ensuring consistent display of your border styles. Here’s a quick look at browser compatibility:
Supported Browsers
- Google Chrome: Full support since version 1.0 (December 2008).
- Mozilla Firefox: Full support since version 1.0 (November 2004).
- Microsoft Edge: Full support since its initial release (July 2015).
- Internet Explorer: Full support since version 4.0 (September 1997).
- Opera: Full support since version 3.5 (November 1998).
- Safari: Full support since version 1.0 (June 2003).
Tips for Ensuring Compatibility
To make sure your web pages look great across different browsers, follow these tips:
- Use Standard Units: Stick to units like pixels (
px
), ems (em
), and rems (rem
) for border widths. - Test Across Browsers: Regularly test your web pages on multiple browsers and devices.
- Fallback Options: Use fallback options like
initial
orinherit
to handle any unexpected behavior.
Additional Resources
For more information and related properties, you can explore the following resources:
- Border-Related Shorthand Properties:
border
: A shorthand property that sets the width, style, and color of an element’s border.border-style
: Defines the style of an element’s border.border-color
: Sets the color of an element’s border.
- Border Width-Related Properties:
border-top-width
: Specifies the width of the top border of an element.border-right-width
: Defines the width of the right border of an element.border-bottom-width
: Sets the width of the bottom border of an element.border-left-width
: Specifies the width of the left border of an element.
- Additional Resources:
- CSS Backgrounds and Borders Module Level 3: The official specification for the
border-width
property and related background and border properties. - MDN Web Docs: A comprehensive resource for learning about CSS properties and best practices in web development.
- CSS Backgrounds and Borders Module Level 3: The official specification for the
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.






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 209 Articles
Explore Popular JavaScript library for building user interfaces with a component-based architecture.
169 Articles
Explore UI toolkit for building natively compiled applications for mobile, web, and desktop from a single codebase.
150 Articles
Explore JavaScript runtime for building scalable, high-performance server-side applications.
60 Articles
Explore React framework enabling server-side rendering and static site generation for optimized performance.
40 Articles
Explore Superset of JavaScript adding static types for improved code quality and maintainability.
39 Articles
Explore Utility-first CSS framework for rapid UI development.
130 Articles
Explore Programming language known for its simplicity, concurrency model, and performance.
70 Articles
Explore Astro is an all-in-one web framework. It includes everything you need to create a website, built-in.
40 Articles
Explore Versatile testing framework for JavaScript applications supporting various test types.
337 Articles
Explore CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
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.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
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.
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.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.