css
  1. css-border

CSS Border

Borders in CSS are used to add visual separation and distinction between elements on a web page.

Border Color

Set the color of the border using the border-color property.

.bordered-element {
  border-color: #333; /* Dark gray border color */
}
Try Playground

Border Style

Define the style of the border using the border-style property. Common values include solid, dotted, dashed, double, and none.

<p class="dotted">A dotted border.</p>
<p class="dashed">A dashed border.</p>
<p class="solid">A solid border.</p>
<p class="double">A double border.</p>
<p class="groove">A groove border.</p>
<p class="ridge">A ridge border.</p>
<p class="inset">An inset border.</p>
<p class="outset">An outset border.</p>
<p class="none">No border.</p>
<p class="hidden">A hidden border.</p>
<p class="mix">A mixed border.</p>
Try Playground

Border Width

Define the width of the border using the border-width property. You can use values like 1px, 2px, 3px, etc.

.element {
  border-width: 3px; /* Border width in pixels */
}
Try Playground

Shorthand border Property:

You can use the shorthand border property to define all border properties (color, width, and style) in one line. For example:

.element {
  border: 3px solid green; /* Width, Style, and Color */
}
Try Playground

Border Radius

Use the border-radius property to create rounded corners for elements. You can specify a single value for a uniform radius or separate values for individual corners.

.element {
  border-radius: 10px; /* Uniform radius for all corners */
}
.element {
  border-radius: 10px 20px 30px 40px; /* Top-left, Top-right, Bottom-right, Bottom-left */
}
Try Playground

Multiple Borders,Border Images & Gradient Borders:

  • You can create multiple borders by stacking them using the box-shadow property. This technique allows you to create unique and complex border effects.
  • Define custom border images using the border-image property. This is especially useful for creating decorative borders with patterns or images.
  • Create gradient borders using the background-image property in combination with linear-gradient() or radial-gradient().

.element {
  box-shadow:
    0 0 0 5px red,    /* Red border */
    0 0 0 10px blue,   /* Blue border */
    0 0 0 15px green; /* Green border */
}
Try Playground
Published on: