/

HTML / CSS / JavaScript Tutorial

CSS Property: border-top-width

[this page | pdf | back links]

The CSS (CSS1) border-top-width property sets the width of the top border of an element. You should always specify the border-style property before this property, as an element must have a border before you can change its characteristics.

 

Valid property values (other than inherit and initial) are:

 

Value

Description

length

Any specified thickness as a CSS length

medium

(default value). Medium width

thick

Thick width

thin

Thin width

 

Default Value:

medium

JavaScript syntax:

e.g. object.style.borderTopWidth="4px"

Inherited:

No

Animatable:

Yes

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
p {border: thin solid black; width: 200px}
p.x1 {border-top-width: thick;}
</style>
</head>
<body>
<p>1. Element with default property</p>
<p class="x1">2. Element set using in-file HTML style</p>
<p id="x2">3. Element set using JavaScript</p>

<script>
document.getElementById("x2").style.borderTopWidth = "thick";
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyBorderTopWidth() {
  var x = document.createElement("DIV"); x.style.borderTopWidth = "thick"; return (window.getComputedStyle(x, null).borderTopWidth == "thick");
}


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile