EN
CSS - difference between outline and border
3 points
In this article, we would like to show you the difference between outline and border in CSS.
Quick answer:
An outline is a line drawn outside the element or element's border.
Outline doesn't affect on the web page layout, it means: outline doesn't shift area and sibling elements.

In the below example we compare three elements:
- element with border,
- element with outline
- and with both of them.
As we can see, outline creates additional layout neutral 'border' around elements.
xxxxxxxxxx
1
2
<html>
3
<head>
4
<style>
5
6
* {
7
box-sizing: border-box; /* <--- used only to get better visualization */
8
}
9
10
body {
11
display: flex; /* <------------ used only to get better visualization */
12
}
13
14
div {
15
margin: 20px; /* <------------ used only to get better visualization */
16
height: 130px; /* <------------ used only to get better visualization */
17
width: 130px; /* <------------ used only to get better visualization */
18
}
19
20
.border {
21
border: 5px solid lightgray;
22
}
23
24
.outline {
25
outline: 15px solid #3085D6; /* change 15px to 45px to see the effect */
26
}
27
28
</style>
29
</head>
30
<body>
31
<div class="border">border</div>
32
<div class="outline">outline</div>
33
<div class="border outline">border + outline</div>
34
</html>