Usage of border-top-width property in CSS

The border-top-width property in CSS controls the thickness of an element's top border. This property only takes effect when a border style is defined.

Syntax

border-top-width: value;

Property Values

Value Description Example
thin Specifies a thin border (typically 1px) border-top-width: thin;
medium Specifies a medium border (typically 3px) border-top-width: medium;
thick Specifies a thick border (typically 5px) border-top-width: thick;
length Defines width in px, em, rem, etc. border-top-width: 8px;

Example: Basic Usage

<!DOCTYPE html>
<html>
<head>
    <style>
        .demo-box {
            padding: 20px;
            border-style: solid;
            border-color: #333;
        }
        
        .thin-border {
            border-top-width: thin;
        }
        
        .medium-border {
            border-top-width: medium;
        }
        
        .thick-border {
            border-top-width: thick;
        }
        
        .custom-border {
            border-top-width: 8px;
        }
    </style>
</head>
<body>
    <div class="demo-box thin-border">
        Thin top border
    </div>
    <br>
    
    <div class="demo-box medium-border">
        Medium top border
    </div>
    <br>
    
    <div class="demo-box thick-border">
        Thick top border
    </div>
    <br>
    
    <div class="demo-box custom-border">
        Custom 8px top border
    </div>
</body>
</html>

Example: Different Units

<!DOCTYPE html>
<html>
<head>
    <style>
        .border-demo {
            margin: 10px 0;
            padding: 15px;
            border-style: solid;
            border-color: #007bff;
            background-color: #f8f9fa;
        }
    </style>
</head>
<body>
    <div class="border-demo" style="border-top-width: 2px;">
        2px top border
    </div>
    
    <div class="border-demo" style="border-top-width: 0.5em;">
        0.5em top border
    </div>
    
    <div class="border-demo" style="border-top-width: 10px;">
        10px top border
    </div>
</body>
</html>

Key Points

  • border-top-width requires border-style to be set for the border to appear
  • Default value is medium (typically 3px)
  • Accepts keywords (thin, medium, thick) and length values (px, em, rem, etc.)
  • Zero width (0) removes the top border entirely
  • Negative values are not allowed

Conclusion

The border-top-width property provides precise control over the top border thickness. Remember to define border-style for the width to take effect, and choose appropriate units based on your design requirements.

Updated on: 2026-03-15T23:18:59+05:30

70 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements