Open In App

Which property specifies the width of a border in CSS ?

In this article, we will learn to set the border’s size of any element using the CSS border-width property. It can take up to 4 values. Users can consider the below values for the border-width property and use them according to their requirements. 

border-width property values:



 Syntax:

border-width: thin | medium | thick | any-length | initial | inherit;

Users can specify the border for only one side using the below border-width sub-properties.



Example 1: If only one value is specified for the border-width property, It considers the same width for all four sides. The below example sets the medium border for all four sides. Users can see the medium border is applied on all four sides of the HTML div element.




<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>Border-width</title>
    <style>
        .text {
            border: solid;
            border-width: medium;
            width: 400px;
            height: 400px;
            margin: 30px auto;
            font-size: 35px;
            color: green;
            vertical-align: center;
        }
    </style>
</head>
  
<body>
    <div class="text">
        <h2>GeeksforGeeks</h2>
        <h2>GeeksforGeeks</h2>
        <h2>GeeksforGeeks</h2>
    </div>
</body>
</html>

Output: 

 

Example 2: If three values are specified for the border-width property, it considers the first width for the top, the second width for the left and right sides, and the third width for the bottom side border. The below example sets the thin border for the top side, a 20px border for the left and right sides, medium border for the bottom side. Users can see the thin border for the top side, 20px for the left and right sides, and the medium border for the bottom side.




<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>Border-width</title>
    <style>
        .text {
            border: solid;
            border-width: thin thick;
            width: 400px;
            height: 400px;
            margin: 30px auto;
            font-size: 35px;
            color: green;
            vertical-align: center;
        }
    </style>
</head>
  
<body>
    <div class="text">
        <h2>GeeksforGeeks</h2>
        <h2>GeeksforGeeks</h2>
        <h2>GeeksforGeeks</h2>
    </div>
</body>
</html>

Output: 

 

Example 3: If four values are specified for the border-width property, it considers the first width for the top, the second width for the right, the third width for the bottom, and the fourth width for the left side. The below example set 5px border for the top side, 10px border for the right side, 15px border for the left side, and 20px border for the bottom side.  Users can see the 5px border for the top, 10px border for the right side, 15px border for the left side, and 20px border for the bottom side.




<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>Border-width</title>
    <style>
        .text {
            border: solid;
            border-width: thin 20px medium;
            width: 400px;
            height: 400px;
            margin: 30px auto;
            font-size: 35px;
            color: green;
            vertical-align: center;
        }
    </style>
</head>
  
<body>
    <div class="text">
        <h2>GeeksforGeeks</h2>
        <h2>GeeksforGeeks</h2>
        <h2>GeeksforGeeks</h2>
    </div>
</body>
</html>

Output:

 

Example 4: Users can see how we can set up different values for every border side. Users can see the top border is 5px, right border is 1px, bottom border is 20px, and left border is initial (medium). 




<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>Border-width</title>
    <style>
        .text {
            border: solid;
            border-top-width: 5px;
            border-right-width: 1px;
            border-bottom-width: 20px;
            border-left-width: initial;
            width: 400px;
            height: 400px;
            margin: 30px auto;
            font-size: 35px;
            color: green;
            vertical-align: center;
        }
    </style>
</head>
  
<body>
    <div class="text">
        <h2>GeeksforGeeks</h2>
        <h2>GeeksforGeeks</h2>
        <h2>GeeksforGeeks</h2>
    </div>
</body>
</html>

Output: 

 

Supported Browsers: The border-width property is supported by the below browsers.


Article Tags :