CSS Outline 3rd Finals
CSS Outline 3rd Finals
An outline is a line that is drawn around elements, OUTSIDE the borders, to make the element "stand out".
outline-style
outline-color
outline-width
outline-offset
Note: Outline differs from borders! Unlike border, the outline is drawn outside the element's border, and may overlap
other content. Also, the outline is NOT a part of the element's dimensions; the element's total width and height is not
affected by the width of the outline.
The outline-width property specifies the width of the outline, and can have one of the following values:
The following example shows some different outlines with different colors. Also notice that these elements also
have a thin black border inside the outline:
Example
<!DOCTYPE html>
<html>
<head>
<style>
p.ex1 { border: 2px solid black; outline-style: solid; outline-color: red;}
p.ex2 { border: 2px solid black; outline-style: dotted; outline-color: blue;}
p.ex3 { border: 2px solid black; outline-style: outset; outline-color: grey;}
</style>
</head>
<body>
<h2>The outline-color Property</h2>
<p>The outline-color property is used to set the color of the outline.</p>
<p class="ex1">A solid red outline.</p>
<p class="ex2">A dotted blue outline.</p>
<p class="ex3">An outset grey outline.</p>
</body>
</html>
The outline property is a shorthand property for setting the following individual outline properties:
outline-width
outline-style (required)
outline-color
The outline property is specified as one, two, or three values from the list above. The order of the values does not
matter.
The following example shows some outlines specified with the shorthand outline property:
Example
<!DOCTYPE html>
<html>
<head>
<style>
p.ex1 {outline: dashed;}
p.ex2 {outline: dotted red;}
p.ex3 {outline: 5px solid yellow;}
p.ex4 {outline: thick ridge pink;}
</style>
</head>
<body>
<h2>The outline Property</h2>
<p class="ex1">A dashed outline.</p>
<p class="ex2">A dotted red outline.</p>
<p class="ex3">A 5px solid yellow outline.</p>
<p class="ex4">A thick ridge pink outline.</p>
</body>
</html>
The outline-offset property adds space between an outline and the edge/border of an element. The space between
an element and its outline is transparent.
The following example specifies an outline 15px outside the border edge:
Example
<!DOCTYPE html>
<html>
<head>
<style>
p { margin: 30px; border: 1px solid black; outline: 1px solid red; outline-offset: 15px;}
</style>
</head>
<body>
<h2>The outline-offset Property</h2>
<p>This paragraph has an outline 15px outside the border edge.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
p { margin: 30px; background:yellow; border: 1px solid black; outline: 1px solid red; outline-offset: 15px;}
</style>
</head>
<body>
<h2>The outline-offset Property</h2>
<p>This paragraph has an outline of 15px outside the border edge.</p>
</body>
</html>