CSS Border Properties
CSS Border Properties
The CSS border properties allow you to specify the style, width, and color of an
element's border.
The border-style property can have from one to four values (for the top border,
right border, bottom border, and the left border).
Example
Demonstration of the different border styles:
Result:
A dotted border.
A dashed border.
A solid border.
A double border.
No border.
A hidden border.
A mixed border.
<!DOCTYPE html>
<html>
<head>
<style>
p.dotted {border-style: dotted;}
p.dashed {border-style: dashed;}
p.solid {border-style: solid;}
p.double {border-style: double;}
p.groove {border-style: groove;}
p.ridge {border-style: ridge;}
p.inset {border-style: inset;}
p.outset {border-style: outset;}
p.none {border-style: none;}
p.hidden {border-style: hidden;}
p.mix {border-style: dotted dashed solid double;}
</style>
</head>
<body>
</body>
</html>
The width can be set as a specific size (in px, pt, cm, em, etc) or by using one of
the three pre-defined values: thin, medium, or thick.
The border-width property can have from one to four values (for the top border,
right border, bottom border, and the left border).
5px border-width
Example
<!DOCTYPE html>
<html>
<head>
<style>
p.one {
border-style: solid;
border-width: 5px;
}
p.two {
border-style: solid;
border-width: medium;
}
p.three {
border-style: dotted;
border-width: 2px;
}
p.four {
border-style: dotted;
border-width: thick;
}
p.five {
border-style: double;
border-width: 15px;
}
p.six {
border-style: double;
border-width: thick;
}
p.seven {
border-style: solid;
border-width: 2px 10px 4px 20px;
}
</style>
</head>
<body>
</body>
</html>
The border-color property can have from one to four values (for the top border,
right border, bottom border, and the left border).
Red border
Example
<!DOCTYPE html>
<html>
<head>
<style>
p.one {
border-style: solid;
border-color: red;
}
p.two {
border-style: solid;
border-color: green;
}
p.three {
border-style: solid;
border-color: red green blue yellow;
}
</style>
</head>
<body>
</body>
</html>
In CSS, there are also properties for specifying each of the borders (top, right,
bottom, and left):
</body>
</html>
Example 2
<!DOCTYPE html>
<html>
<head>
<style>
p{
border-style: dotted solid;
}
</style>
</head>
<body>
</body>
</html>
In CSS, there are also properties for specifying each of the borders (top, right,
bottom, and left):
Different Border Styles
Example
p {
border-top-style: dotted;
border-right-style: solid;
border-bottom-style: dotted;
border-left-style: solid;
}
Try it Yourself »
Example
p {
border-style: dotted solid;
}
Try it Yourself »
border-style: dotted;
o all four borders are dotted
To shorten the code, it is also possible to specify all the individual border
properties in one property.
The border property is a shorthand property for the following individual border
properties:
border-width
border-style (required)
border-color
Example
<!DOCTYPE html>
<html>
<head>
<style>
p{
border: 5px solid red;
}
</style>
</head>
<body>
</body>
</html>
Left Border
<!DOCTYPE html>
<html>
<head>
<style>
p{
border-left: 6px solid red;
background-color: lightgrey;
}
</style>
</head>
<body>
</body>
</html>
Bottom Border
<!DOCTYPE html>
<html>
<head>
<style>
p{
border-bottom: 6px solid red;
background-color: lightgrey;
}
</style>
</head>
<body>
<h2>The border-bottom Property</h2>
<p>This property is a shorthand property for border-bottom-width, border-
bottom-style, and border-bottom-color.</p>
</body>
</html>
Normal border
Round border
Rounder border
Roundest border
Example
<!DOCTYPE html>
<html>
<head>
<style>
p.normal {
border: 2px solid red;
}
p.round1 {
border: 2px solid red;
border-radius: 5px;
}
p.round2 {
border: 2px solid red;
border-radius: 8px;
}
p.round3 {
border: 2px solid red;
border-radius: 12px;
}
</style>
</head>
<body>
</body>
</html>