Introduction
Borders help separate parts of a webpage visually. They make sections clear and attractive.
Jump into concepts and practice - no test required
selector {
border-style: none | solid | dotted | dashed | double | groove | ridge | inset | outset;
}border-style to set the type of border around an element.border-style with border-width and border-color for full border control.div {
border-style: solid;
}p {
border-style: dotted;
}button {
border-style: dashed;
}section {
border-style: double;
}<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Border Styles Example</title> <style> .solid-border { border-style: solid; border-width: 0.2rem; border-color: #007acc; padding: 1rem; margin: 1rem 0; } .dotted-border { border-style: dotted; border-width: 0.2rem; border-color: #e67e22; padding: 1rem; margin: 1rem 0; } .dashed-border { border-style: dashed; border-width: 0.2rem; border-color: #27ae60; padding: 1rem; margin: 1rem 0; } .double-border { border-style: double; border-width: 0.4rem; border-color: #c0392b; padding: 1rem; margin: 1rem 0; } </style> </head> <body> <section class="solid-border">This box has a solid border.</section> <section class="dotted-border">This box has a dotted border.</section> <section class="dashed-border">This box has a dashed border.</section> <section class="double-border">This box has a double border.</section> </body> </html>
border-style to none, no border will show even if width and color are set.border-top-style, border-right-style, etc.border-style value creates a solid continuous line around an element?border-style property controls the line style of borders. Common values include solid, dotted, dashed, and double.solid value creates a continuous, unbroken line around the element.div?dashed. Incorrect values like dash, dashes, or dot are not recognized.border-style: dashed; correctly applies a dashed border style to the element.p {
border-width: 3px;
border-style: double;
border-color: blue;
}double border style draws two parallel lines with a small space between them. The total thickness is controlled by border-width.div {
border-style: solid;
border-width: 0;
border-color: red;
}div.card { border-style: solid; } sets this correctly.div.card:hover { border-style: dotted; } changes the border style to dotted when the mouse is over the card.