CSS Border

CSS border is a key property used to characterize and style the borders around HTML components. Borders assume a vital part in website composition, assisting with making separation, emphasis, and stylish allure. In CSS, you can utilize a few border-related properties to control the style, variety, size, and shape of these borders. In this article, we will investigate these CSS border properties and how to really utilize them.

Key Points on CSS Border:

Value Description
none It doesn't define any border.
dotted It is used to define a dotted border.
dashed It is used to define a dashed border.
solid It is used to define a solid border.
double It defines two borders with the same border-width value.
groove It defines a 3d grooved border. Effect is generated according to the border-color value.
ridge It defines a 3d ridged border. Effect is generated according to the border-color value.
inset It defines a 3d inset border. Effect is generated according to the border-color value.
outset It defines a 3d outset border. Effect is generated according to the border-color value.

Syntax for CSS Border Properties:

Syntax Example


        /* Border shorthand syntax */
        .border: width style color;
        
        /* Example */
        .border: 2px solid #000000;

Examples of CSS Border Properties:

The following examples demonstrate the usage of different border properties:

Code Example: Solid Border


            .div {
            border: 2px solid black;
            padding:20px;
                 }

Output

This div has a solid black border.

Code Example: Dotted Border


            .div {
            border: 3px dotted red;
            padding:20px;
                 }

Output

This div has a dotted red border.

Code Example: Border Radius


            .div {
            border: 4px solid blue;
            border-radius: 10px;
                 }

Output

This div has rounded corners.

Common Border Properties:

When using borders, be mindful of the visual balance between content and borders. Avoid using too thick or overwhelming borders that might distract from the content itself.