# How to set the color of the outline around an element with JavaScript?

JavascriptFront End ScriptsWeb Development

To set the outline color, use the outlineColor property. You can try to run the following code to set the color of the outline around an element with JavaScript:

## Example

Live Demo

<!DOCTYPE html>
<html>
<style>
#box {
width: 450px;
background-color: orange;
border: 3px solid red;
}
</style>
<body>
<p>Click below to add Outline Color.</p>
<div id="box">
<p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
<p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
<p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
</div>
<br>
<button type="button" onclick="display()">Set Outline Color</button>
<br>
<script>
function display() {
document.getElementById("box").style.outline = "thick solid";
document.getElementById("box").style.outlineColor = "#5F5F5F";
}
</script>
</body>
</html>
Published on 27-Feb-2018 14:14:28