Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Usage of border-width property in CSS
The border-width property sets the thickness of an element's border, not the color. It defines how wide the border should be around an element.
Syntax
border-width: value;
Values
The border-width property accepts the following values:
- Length values: px, em, rem, etc. (e.g., 2px, 1em)
- Keywords: thin, medium, thick
- Multiple values: Define different widths for each side
Example: Basic Border Width
<html>
<head>
<style>
.border-example {
border-width: 3px;
border-style: solid;
border-color: #333;
padding: 10px;
margin: 10px 0;
}
</style>
</head>
<body>
<p class="border-example">
Example showing border width and style
</p>
</body>
</html>
Different Border Widths
<html>
<head>
<style>
.thin-border { border: thin solid #000; padding: 8px; margin: 5px 0; }
.medium-border { border: medium solid #000; padding: 8px; margin: 5px 0; }
.thick-border { border: thick solid #000; padding: 8px; margin: 5px 0; }
.custom-border { border: 5px solid #000; padding: 8px; margin: 5px 0; }
</style>
</head>
<body>
<p class="thin-border">Thin border</p>
<p class="medium-border">Medium border</p>
<p class="thick-border">Thick border</p>
<p class="custom-border">Custom 5px border</p>
</body>
</html>
Multiple Values
You can specify different widths for each side using multiple values:
<html>
<head>
<style>
.multi-border {
border-width: 2px 4px 6px 8px; /* top right bottom left */
border-style: solid;
border-color: #666;
padding: 15px;
}
</style>
</head>
<body>
<p class="multi-border">
Different border widths: top(2px), right(4px), bottom(6px), left(8px)
</p>
</body>
</html>
Key Points
- border-width only works when border-style is set
- Default value is medium (typically 3px)
- Can accept 1-4 values for different sides
- Must be used with border-style for visible borders
Conclusion
The border-width property controls border thickness, not color. Use it with border-style and border-color for complete border styling.
Advertisements
