Easy Tutorial
❮ Css Form Css Combinators ❯

CSS Border


CSS Border Properties

CSS border properties allow you to specify the style and color of an element's border.

Border on all four sides

Red bottom border

Rounded border

Left border with width and blue color


Border Styles

The border-style property specifies what kind of border to display.

border-style property is used to define the style of the border

border-style Values:

none: Default no border

dotted: Defines a dotted border

dashed: Defines a dashed border

solid: Defines a solid border

double: Defines two borders. The width of the two borders is the same as the border-width value

groove: Defines a 3D grooved border. The effect depends on the border color value

ridge: Defines a 3D ridged border. The effect depends on the border color value

inset: Defines a 3D inset border. The effect depends on the border color value

outset: Defines a 3D outset border. The effect depends on the border color value

Try it »


Border Width

You can specify the width of the border with the border-width property.

There are two ways to specify the width of the border: you can specify a length value, such as 2px or 0.1em (with units like px, pt, cm, em, etc.), or use one of the three keywords: thick, medium (default), and thin.

Note: CSS does not define the exact width of the three keywords, so one user might set thick, medium, and thin to be equal to 5px, 3px, and 2px respectively, while another user might set them to 3px, 2px, and 1px.

Example

p.one
{
    border-style:solid;
    border-width:5px;
}
p.two
{
    border-style:solid;
    border-width:medium;
}

Border Color

The border-color property is used to set the color of the border. The colors can be set as:

You can also set the border color to "transparent".

Note: The border-color property does not work alone; it must be used with the border-style property to set the border style first.

Example

p.one
{
    border-style:solid;
    border-color:red;
}
p.two
{
    border-style:solid;
    border-color:#98bf21;
}

Border - Individual Sides

In CSS, you can specify different borders for different sides:

Example

p
{
    border-top-style:dotted;
    border-right-style:solid;
    border-bottom-style:dotted;
    border-left-style:solid;
}

The above example can also be set with a single property:

Example

border-style:dotted solid;

The border-style property can have 1-4 values:

The above examples use the border-style property. However, it can also be used with border-width and border-color.


Border - Shorthand Property

The above examples use multiple properties to set the border.

You can also set the border in one property.

You can set in the "border" property:

Example

border:5px solid red;

More Examples

All border properties in one declaration

Set the style of the bottom border Set the Width of the Left Border

Set the Color of All Four Borders

Set the Color of the Right Border


CSS Border Properties

Property Description
border A shorthand property for setting the properties of all four sides in one declaration.
border-style Used to set the style of all borders of an element, or individually set the border styles for each side.
border-width A shorthand property for setting the width of all borders of an element, or individually set the border width for each side.
border-color A shorthand property for setting the color of all visible parts of the borders of an element, or individually set the color for each side.
border-bottom A shorthand property for setting all properties of the bottom border in one declaration.
border-bottom-color Sets the color of the bottom border of an element.
border-bottom-style Sets the style of the bottom border of an element.
border-bottom-width Sets the width of the bottom border of an element.
border-left A shorthand property for setting all properties of the left border in one declaration.
border-left-color Sets the color of the left border of an element.
border-left-style Sets the style of the left border of an element.
border-left-width Sets the width of the left border of an element.
border-right A shorthand property for setting all properties of the right border in one declaration.
border-right-color Sets the color of the right border of an element.
border-right-style Sets the style of the right border of an element.
border-right-width Sets the width of the right border of an element.
border-top A shorthand property for setting all properties of the top border in one declaration.
border-top-color Sets the color of the top border of an element.
border-top-style Sets the style of the top border of an element.
border-top-width Sets the width of the top border of an element.
border-radius Sets rounded borders.
❮ Css Form Css Combinators ❯