/

HTML / CSS / JavaScript Tutorial

CSS Property: border

[this page | pdf | back links]

The CSS (CSS1) border property is a shorthand property combining (up to) 3 of the border properties.

 

Valid property values (other than inherit and initial) are defined by the elements of the shorthand. Shorthand elements (in the order in which they appear):

 

-        border-width

-        border-style

-        border-color

 

Default Value:

See individual properties

JavaScript syntax:

e.g. object.style.border="2px solid red"

Inherited:

No

Animatable:

See individual properties

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
p {width: 200px}
p.x1 {border: thin solid blue;}
</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.border = "thin solid blue";
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyBorder() {
  var x = document.createElement("DIV"); x.style.border = "thin solid blue"; return (window.getComputedStyle(x, null).border == "thin solid blue");
}


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile