HTML | DOM Style borderTopColor Property

The borderTopColor property allows us to set/get the color of top border of element.
Syntax:

  • It returns the borderTopColor property.
    object.style.borderTopColor
  • It is used to set the borderTopColor property.
    object.style.borderTopColor = "color|transparent|initial|
    inherit"
    

Return Value:The borderTopColor property returns the color of the top border of an element.
Property Values:

  • color:It specifes the top border color of corresponding element. Black is default color.
    • Syntax:
      borderTopColor = "red"

      Example:

      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      <!DOCTYPE html>
      <html>
        
      <head>
          <title>
              HTML | DOM Style borderTopColor Property
          </title>
          <style>
              #GFG_Div {
                  width: 200px;
                  margin-left: 210px;
                  border: thick solid green;
              }
          </style>
      </head>
        
      <body align="center">
          <p
           Click to change the right border 
           color of element.
          </p>
          <button type="button" onclick="myGeeks()">
           Click to change
          </button>
          <br>
          <br>
          <div id="GFG_Div">GeeksforGeeks</div>
          <script>
              function myGeeks() {
                  document.getElementById("GFG_Div")
                      .style.borderTopColor = "red";
              }
          </script>
        
      </body>
        
      </html>

      chevron_right

      
      

      Output:

      • Before Click on button
      • After Click on Button
    • Syntax:
      borderTopColor = "yellow"

      Example:

      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      <!DOCTYPE html>
      <html>
        
      <head>
          <title>
              HTML | DOM Style borderTopColor Property
          </title>
          <style>
              #GFG_Div {
                  width: 200px;
                  margin-left: 210px;
                  border: thick solid green;
              }
          </style>
      </head>
        
      <body align="center">
          <p
           Click to change the top border 
           color of element.
          </p>
          <button type="button" onclick="myGeeks()">
           Click to change
          </button>
          <br>
          <br>
          <div id="GFG_Div">GeeksforGeeks</div>
          <script>
              function myGeeks() {
                  document.getElementById("GFG_Div")
                      .style.borderTopColor = "yellow";
              }
          </script>
        
      </body>
        
      </html>

      chevron_right

      
      

      Output:

      • Before Click on button
      • After Click on Button
  • transparent:It sets the top border color of corresponding element to transparent.
    • Syntax:
      borderTopColor = "transparent"

      Example:

      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      <!DOCTYPE html>
      <html>
        
      <head>
          <title>
              HTML | DOM Style borderTopColor Property
          </title>
          <style>
              #GFG_Div {
                  width: 200px;
                  margin-left: 210px;
                  border: thick solid green;
              }
          </style>
      </head>
        
      <body align="center">
          <p
            Click to change the right border 
            color of element.</p>
          <button type="button" onclick="myGeeks()">
            Click to change
          </button>
          <br>
          <br>
          <div id="GFG_Div">GeeksforGeeks</div>
          <script>
              function myGeeks() {
                  document.getElementById("GFG_Div")
                      .style.borderTopColor = "transparent";
              }
          </script>
        
      </body>
        
      </html>

      chevron_right

      
      

      Output:

      • Before Click on button
      • After Click on Button
  • initial:When no value specified for this field, it is inherited from the parent of element. If there is no parent means this element is root then it takes initial(or default) value.
  • inherit:This keyword applies the initial(or default) value of a property to an element. The initial value should not be confused by the value specified by the browser’s style sheet. When borderColor sets to initial, It appears black(default) color.

Browser Support: The browser supported by DOM Style borderTopColor property are listed below:

  • Google Chrome
  • Internet Explorer
  • Mozilla firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.