/

HTML / CSS / JavaScript Tutorial

CSS Property: border-top-color

[this page | pdf | back links]

The CSS (CSS1) border-top-color property sets the colour 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

color

Specified CSS colour

transparent

Transparent

 

Default Value:

The current CSS colour of the element

JavaScript syntax:

e.g. object.style.borderTopColor="red"

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-color: red;}
</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.borderTopColor = "red";
</script>

</body>
</html>

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


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile