Introduction

In CSS, border property is used to enable a border around HTML element and border property also has different properties to change the border like color, style, and width.
CSS Border Properties
CSS Border Properties are used to create a border to a particular element and it also defines the boundary of the element.
Border Style
To define the type of the border, which is applied to the HTML element, the border-style property is used.
Syntax
selected_element
{
border-style:style_type;
}
The type of style is listed below.
  • dotted
    To define a dotted border style, dotted border style is used.
    Example
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <style>
    5. h1 {
    6. border-style: dotted;
    7. }
    8. </style>
    9. </head>
    10. <body>
    11. <h1>c# corner</h1>
    12. <p>c-sharpcorner.com</p>
    13. </html>
    Output
  • solid
    To define a solid border style, dotted border style is used.
    Example
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <style>
    5. h1 {
    6. border-style: solid;
    7. }
    8. </style>
    9. </head>
    10. <body>
    11. <h1>c# corner</h1>
    12. <p>c-sharpcorner.com</p>
    13. </html>
    Output
  • dashed
    To define the dashed border style, dashed border style is used.
    Example
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <style>
    5. h1 {
    6. border-style: dashed;
    7. }
    8. </style>
    9. </head>
    10. <body>
    11. <h1>c# corner</h1>
    12. <p>c-sharpcorner.com</p>
    13. </html>
    Output
  • double
    To define the double border style, double border style is used.
    Example
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <style>
    5. h1 {
    6. border-style: double;
    7. }
    8. </style>
    9. </head>
    10. <body>
    11. <h1>c# corner</h1>
    12. <p>c-sharpcorner.com</p>
    13. </html>
    Output

  • groove
    To define 3D grooved border style, groove border style is used.
    Example
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <style>
    5. h1 {
    6. border-style: Groove;
    7. }
    8. </style>
    9. </head>
    10. <body>
    11. <h1>c# corner</h1>
    12. <p>c-sharpcorner.com</p>
    13. </html>
    Output
  • hidden
    To define hidden border style, hidden border style is used.
    Example
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <style>
    5. h1 {
    6. border-style: hidden;
    7. }
    8. </style>
    9. </head>
    10. <body>
    11. <h1>c# corner</h1>
    12. <p>c-sharpcorner.com</p>
    13. </html>
    Output

  • none
    To define no border, no border style is used.
    Example
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <style>
    5. h1 {
    6. border-style: none;
    7. }
    8. </style>
    9. </head>
    10. <body>
    11. <h1>c# corner</h1>
    12. <p>c-sharpcorner.com</p>
    13. </html>
    Output

  • inset
    To define 3D inset border style, inset border style is used.
    Example
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <style>
    5. h1 {
    6. border-style: inset;
    7. }
    8. </style>
    9. </head>
    10. <body>
    11. <h1>c# corner</h1>
    12. <p>c-sharpcorner.com</p>
    13. </html>
    Output
  • outset
    To define 3D outset border style, an outset border style is used.
    Example
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <style>
    5. h1 {
    6. border-style: outset;
    7. }
    8. </style>
    9. </head>
    10. <body>
    11. <h1>c# corner</h1>
    12. <p>c-sharpcorner.com</p>
    13. </html>
    Output
  • ridge
    To define 3D ridged border style, ridge border style is used.
    Example
    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <style>
    5. h1 {
    6. border-style: ridge;
    7. }
    8. </style>
    9. </head>
    10. <body>
    11. <h1>c# corner</h1>
    12. <p>c-sharpcorner.com</p>
    13. </html>
    Output

Border Width
  • To define the width of the border, the border-width property is used.
  • We can define a border within px, pt, cm, em, etc.
  • We can also use three pre-defined values: thin, medium, or thick. to define border width.
Syntax
selected_element
{
border-width:value;
}
Example
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. h1 {
  6. border-style: solid;
  7. border-width: 5px;
  8. }
  9. </style>
  10. </head>
  11. <body>
  12. <h1>c# corner</h1>
  13. <p>c-sharpcorner.com</p>
  14. </html>
Output
We also define the border width, using different units like-
  • border-width:medium
  • border-width:thin
  • border-width:thik
Border Color
To define the border color of the HTML element, the border-color property is used
In CSS, we can define the color, using-
  • Name of the color.
  • Hex value of the color.
  • The RGB value of the color.
Example 1
In this example, we will use the name of the color.
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. h1 {
  6. border-style: solid;
  7. border-color: red;
  8. }
  9. </style>
  10. </head>
  11. <body>
  12. <h1>c# corner</h1>
  13. <p>c-sharpcorner.com</p>
  14. </html>
Output
Example 2
In this example, we will use RGB value of the color.
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. h1 {
  6. border-style: solid;
  7. border-color: rgb(255, 0, 0);
  8. }
  9. </style>
  10. </head>
  11. <body>
  12. <h1>c# corner</h1>
  13. <p>c-sharpcorner.com</p>
  14. </html>
Output
Example 3
In this example, we will use Hex value of the color.
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. h1 {
  6. border-style: solid;
  7. border-color: #FF0000;
  8. }
  9. </style>
  10. </head>
  11. <body>
  12. <h1>c# corner</h1>
  13. <p>c-sharpcorner.com</p>
  14. </html>
Output
Rounded Borders
To define a rounded border of the HTML element, the border-radius property is used.
Syntax
selected_element\
{
border-radius:value;
}
Example
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. h1 {
  6. border-style: solid;
  7. border-color: #FF0000;
  8. border-radius: 10px;
  9. }
  10. </style>
  11. </head>
  12. <body>
  13. <h1>c# corner</h1>
  14. <p>c-sharpcorner.com</p>
  15. </html>
Output

Conclusion

In this article, we studied CSS - Border.