Loading course content...
Loading course content...
Code Playground is only enabled on larger screen sizes.
The border is not visible by default, but that can be changed by setting the border-style property.
p {
border-style: solid;
}Other possible values for border-style include:
| Value | Description |
|---|---|
dotted | Series of round dots. |
dashed | Series of short dashes. |
solid | Single continuous line. |
double | Two parallel lines |
groove | 3D grooved effect (appears carved in). |
ridge | 3D ridged effect (opposite of groove). |
inset | Makes the element look embedded (3D effect). |
outset | Makes the element look raised (3D effect). |
none (default) | No border is drawn. |
hidden | Looks like none. |
Try these options in the playground and pay extra attention to none and hidden.
They are visually the same, but you should be careful not to misuse them.
none indicates the element has no border at all, and hidden indicates that the element does have a border, just not visible.
This small difference is crucial because the border itself has thickness, and if not calculated correctly, it might lead to problems when sizing elements.
You can further customize the border by setting its width, color, and radius:
p {
border-style: solid;
border-width: 4px;
border-color: red;
border-radius: 10px;
}The border-width property accepts either numeric values such as 2px, 1rem, and 0.25em, or keyword values such as thin, medium, and thick.
The border-color property defines the border color using the same methods we discussed in the CSS colors lesson.
And finally, the border-radius property defines the radius to create a rounded border. It accepts either length values or percentage values.
To make the border completely rounded, you can set the border-radius to larger than or equal to 50%:
p {
border-style: solid;
border-width: 4px;
border-color: red;
border-radius: 60%;
}Besides the properties discussed above, there are also properties that allow you to customize individual sides of the border:
p {
border-top-style: solid;
border-right-style: dotted;
border-bottom-style: double;
border-left-style: dashed;
}Similar variants also exist for border-width, border-color, and border-radius.
If you want a simpler syntax, use the border-style property mentioned above, and pass multiple values. This allows you to customize each individual sides.
The syntax is as follows:
border-style: <top> <right> <bottom> <left>;
border-style: <top> <left_and_right> <bottom>;
border-style: <top_and_bottom> <left_and_right>;
border-style: <all>;Once again, the same pattern holds for border-width, border-color, and border-radius.
border shorthandLastly, CSS offers an ultimate shorthand property, border, which allows you to customize width, style, and color together.
p {
border: 2px dashed red;
}However, you cannot customize individual sides with this property.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="/styles.css"> </head> <body> <p>Hello, World!</p> </body> </html>