Course Content
CSS Basic
0/1
CSS Selectors
0/1
CSS Comments
0/1
CSS Backgrounds
0/1
CSS Borders
0/1
CSS Outline
0/1
CSS Fonts
0/1
CSS Height and Width
0/1
CSS Margins and Paddings
0/2
CSS Icons
0/1
CSS Links
0/1
CSS Lists
0/1
CSS Tables
0/1
CSS Display Properties
0/1
CSS Max-Width Property
0/1
CSS Positioning Elements
0/1
CSS Z-Index Property
0/1
CSS Overflow
0/1
CSS Float
0/1
CSS Opacity
0/1
CSS Forms
0/1
CSS Dropdowns
0/1
CSS Buttons
0/1
CSS Media Queries
0/1
About Lesson

CSS Borders:

CSS borders allow you to define the style, color, and width of the borders around HTML elements. Borders can be applied to various elements such as divs, paragraphs, headings, images, and more. You can customize borders using properties like border-width, border-style, and border-color.

Basic Border Properties:

  1. border-width: Specifies the width of the border. It can be set to a specific value (e.g., 1px, 2px) or one of the following values: thin, medium, thick.

  2. border-style: Specifies the style of the border. Common values include solid, dashed, dotted, double, and more.

  3. border-color: Specifies the color of the border. It can be set to a color name, a hex value, an RGB value, or other color representations.

  4. border: It is a Border shorthand property that can make your CSS more concise and easier to read. It’s particularly useful when you want to set all three border properties at once with consistent values. Remember that the order matters: width, style, and color. If you omit a value, it will use the default value for that property.
  5. border-radius: border-radius in CSS is a property that allows you to create rounded corners for elements. It defines the radius of a quarter ellipse that forms the outer edge of the border box of an element. By setting the border-radius, you can soften the appearance of sharp corners and create a more visually pleasing design.

Syntax:

 
selector {
border-width: value;
border-style: value;
border-color: value;
//shorthand property
border: (border-width) (border-style) (border-color); 
//radius of border
border-radius: value;
}
 

Example:

<!DOCTYPE html>
<html lang=”en”>
<head>
    <meta charset=”UTF-8″>
    <meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
    <title>CSS Colors Example</title>
    <style>
        /* Apply a border to paragraphs */
        p {
            border-width: 2px;
            /* Width of the border */
            border-style: dashed;
            /* Style of the border */
            border-color: #333;
            /* Color of the border */
            padding: 10px;
            /* Add padding for better visibility */
        }
        /* Apply a different border to images */
        img {
            border-width: 4px;
            border-style: solid;
            border-color: #008080;
        }
        /* Apply a rounded border to a div */
        .rounded-box {
           /*shorthand property*/
            border: 3px Solid #ff4500;
        /* Border radius for rounded corners */
            border-radius: 10px;
            padding: 20px;
            margin: 20px;
        }
    </style>
</head>
<body>
    <h1>CSS Borders</h1>
    <p>This is a paragraph with a dashed border.</p>
    <p style=”border-style: dotted; border-color: #800080;”>Another paragraph with a dotted border.</p>
    <img src=”logo-dark.png” alt=”Example Image”>
    <div class=”rounded-box”>
        <p>This div has a rounded border.</p>
    </div>
</body>
</html>

Output: