How To Work CSS Border - border, border-radius

In web design and development, “border” and “border-radius” are CSS properties used to style the appearance of elements such as divs, images, and buttons. They are commonly used for creating borders around elements and rounding the corners of those elements. Let me explain each property with examples:

Border:

The border property is used to set the border of an HTML element. It has three components: border-width, border-style, and border-color. Here’s the syntax:


border: border-width border-style border-colo

border-width: Specifies the width of the border. You can use values like 1px, 2px, or 3px. border-style: Defines the style of the border, such as solid, dotted, dashed, etc. border-color: Sets the color of the border using color names or hexadecimal values. Example:


div {
  border: 2px solid #007bff;
  /* This creates a 2px solid blue border around the div */
}

Border-Radius:

The border-radius property is used to round the corners of an element, making it appear as a circle or a rounded rectangle. It has a single value, which determines the radius of the rounded corners. Example:


div {
  border-radius: 10px;
  /* This rounds the corners of the div with a 10px radius */
}

You can also specify the border-radius for each corner individually, which allows you to create more complex shapes. The syntax is as follows:


div {
  border-radius: top-left top-right bottom-right bottom-left;
}

Example:


div {
  border-radius: 10px 20px 10px 20px;
  /* This rounds the top-left and bottom-right corners with a 10px radius
     and the top-right and bottom-left corners with a 20px radius */
}

Combining both properties, you can create elements with customized borders and rounded corners. For instance:


button {
  border: 2px solid #ff0000;
  border-radius: 15px;
  /* This creates a button with a 2px solid red border and 15px rounded corners */
}

These are some basic examples of how to use the border and border-radius properties in CSS. You can further customize and combine these properties to achieve the desired visual effects for your web elements.

Previous
How To Work CSS Size - Width, Height, Max-Height, Max-Width Also Padding And Marging
Next
The Fundamental Concept in Web design and Layout of CSS Box Model.