How to set the color of an elements border with JavaScript?

JavascriptWeb DevelopmentFront End Scripts

To set the color of an element's border in JavaScript, use the borderColor property.


You can try to run the following code to learn how to set a color of an element's border −

Live Demo

<!DOCTYPE html>
         #box {
            height: 300px;
            width: 200px;
            border: thick dashed yellow;
      <div id="box">
         <p>DEMO TEXT</p>
         <p>DEMO TEXT</p>
         <p>DEMO TEXT</p>
         <p>DEMO TEXT</p>
      <button type="button" onclick="display()">Set new color of border</button>
         function display() {
            document.getElementById("box").style.borderColor = "green";
Published on 27-Feb-2018 06:01:34