/

HTML / CSS / JavaScript Tutorial

CSS Property: outline

[this page | pdf | back links]

The CSS (CSS2) outline property is a shorthand property combining (up to) 3 of the outline properties.

 

Valid property values (other than inherit and initial) are defined by the elements of the shorthand. Shorthand elements (in the order in which they appear):

 

-        outline-color

-        outline-style

-        outline-width

 

Default Value:

invert none medium

JavaScript syntax:

e.g. object.style.outline="2px solid red"

Inherited:

No

Animatable:

See individual properties

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
div {width: 100px; height: 15px; border: 1px dotted black; padding: 5px;}
.x1 {outline: 2px solid blue}
</style>
</head>
<body>
Element with default property<br>
<div>abcdefgh</div><br><br>
Property set using in-file HTML style<br>
<div class="x1">abcdefgh</div><br><br>
Property set using JavaScript<br>
<div id="x2">abcdefgh</div>

<script>
document.getElementById("x2").style.outline = "2px solid blue";
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyOutline() {
  var x = document.createElement("DIV"); x.style.outline = "2px solid blue"; return (window.getComputedStyle(x, null).outline == "2px solid blue");
}


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile