CSS border-color Property

You are Here:

Demo

border-color: red;

CSS border-color Property

CSS border-color property sets the color of an element's border.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> div{ border-style: solid; border-color: red; } </style> </head> <body> <h1>CSS border-color Property</h1> <div> This is div container. </div> </body> </html>

Syntax

Using CSS

element{ border-color: red; }

Using Javascript

object.style.borderColor="red";

Animatable

Yes, border-color property is animatable. CSS Animatable Properties Reference.

Default Value

Default value for CSS border-color property is black.

Property Value

The following table provides a list of all values for CSS border-color property.

ValueExplanation
colorSpecifies that the border color should be user given color. Check our color combinator
transparentSpecifies that the border color should be transparent.

Using JavaScript

In the following example, we will demonstrate how to change the CSS border-color property of an element using JavaScript.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> div{ padding: 10px; margin-bottom: 10px; border-style: dashed; } </style> </head> <body> <h1>CSS border-color Property</h1> <div> This is div container. </div> <button onclick="myFunction()">Click Me</button> <script> var x = document.getElementsByTagName("div")[0]; function myFunction(){ x.style.borderColor = "red"; } </script> </body> </html>

CSS border-color is a shorthand CSS Property

The border-color is a shorthand CSS Property of the following CSS properties.

The border-color CSS property can have one, two, three, or four values.

  • border-color: red
    • all four borders are red
  • border-color: red green
    • top and bottom borders are red
    • right and left borders are green
  • border-color: red green blue
    • top border is red
    • right and left borders are green
    • bottom border is blue
  • border-color: red green blue orange
    • top border is red
    • right border is green
    • bottom border is blue
    • left border is orange

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> div{ border-style: solid; padding: 10px; } #point{ border-color: red; } #point1{ border-color: red green; } #point2{ border-color: red green blue; } #point3{ border-color: red green blue orange; } #point4{ border-color: transparent; } </style> </head> <body> <h1>CSS border-color Property</h1> <h2>border-color: red;</h2> <div id="point"> This is div container. </div> <h2>border-color: red green;</h2> <div id="point1"> This is div container. </div> <h2>border-color: red green blue;</h2> <div id="point2"> This is div container. </div> <h2>border-color: red green blue yellow;</h2> <div id="point3"> This is div container. </div> <h2>border-color: transparent;</h2> <div id="point4"> This is div container. </div> </body> </html>

Reminder

Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in CSS.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author