How to set all outline properties in a single declaration with JavaScript?

To set all outline properties in one declaration, use the outline property. It sets the following properties: outline-width, outline-style, and outline-color.


You can try to run the following code to learn how to work with outline properties −

Live Demo

<!DOCTYPE html>
         #box {
            border: 2px dashed blue;
      <div id="box">This is a div.</div>
      <button type="button" onclick="display()">Click to set Outline</button>
         function display() {
            document.getElementById("box").style.outline = "5px solid red";