HTML - DOM Style Object borderTop Property



HTML DOM Style Object borderTop property sets or returns the top border properties of an element. It is a shorthand notation for border-top-width, border-top-style and border-top-color.

Syntax

Given below are the syntax to get or set the borderTop property.

Set the borderTop property:
object.style.borderTop= "width | style | color | initial | inherit";
Get the borderTop property:
object.style.borderTop;

Property Values

Value Description
width It sets the top border width.
style It sets the top border style.
color It sets the top border color.
initial It is used to set this property to it's default value.
inherit It is used to inherit the property of it's parent element.

Return value

It returns a string value which represents top border width, style and color property of an element.

Example of HTML DOM Style Object 'borderTop' Property

The following example sets a top border to a section element.

<!DOCTYPE html>
<html>
<head>
    <title>
        HTML DOM Style Object borderTop Property
    </title>
    <style>
        section {
            border : solid 1px;
        }
    </style>
</head>
<body>
    <button onclick="fun()">Add top Border</button>
    <section id="border">
        Welcome to Tutorials Point...
    </section>
    <script>
        function fun() {
            document.getElementById("border")
                .style.borderTop = "4px solid #04af2f";
        }
    </script>
</body>
</html>

Supported Browsers

Property Chrome Edge Firefox Safari Opera
borderTop Yes 1 Yes 12 Yes 1 Yes 1 Yes 3.5
html_dom.htm
Advertisements