Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS border Property

Posted in CSS Tutorial
Updated on Oct 02, 2024
By Mari Selvan
👁️ 20 - Views
⏳ 4 mins
💬 1 Comment
CSS border Property

Photo Credit to CodeToFun

🙋 Introduction

The border property in CSS is a shorthand property used to set the border around an element. This property allows you to define the width, style, and color of the border in a single declaration.

Borders are an essential aspect of web design, as they help define the boundaries of elements and enhance the overall visual structure of a webpage.

💡 Syntax

The border property can be used in various ways, allowing you to specify one, two, or all three border attributes (width, style, color).

Syntax
Copied
Copy To Clipboard
element {
  border: width style color;
}

🎛️ Default Value

If the border property is used without specifying any values, the default value is medium none color. This means the border will not be visible as its style is set to none.

🏠 Property Values

  • width: Defines the thickness of the border. It can be specified in pixels (px), ems (em), or keywords like thin, medium, thick.
  • style: Determines the appearance of the border. Common values include:
    • none: No border (default).
    • solid: A solid line.
    • dotted: A series of dots.
    • dashed: A series of dashes.
    • double: Two solid lines.
    • groove: A 3D grooved border that appears as though it is carved into the page.
    • ridge: A 3D ridged border that appears as though it is coming out of the page.
    • inset: A 3D inset border that makes the element appear embedded.
    • outset: A 3D outset border that makes the element appear raised.
  • color: Defines the color of the border. It can be specified using color names (e.g., red), hexadecimal values (e.g., #ff0000), RGB values (e.g., rgb(255, 0, 0)), or HSL values (e.g., hsl(0, 100%, 50%)).

📄 Example

In this example, we'll create a solid black border around a div element with a width of 2 pixels.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS border Example</title>
  <style>
    div {
      border: 2px solid black;
      padding: 10px;
    }
  </style>
</head>
<body>
  <h1>Div with Custom Border</h1>
  <div>
    This div element has a 2px solid black border.
  </div>
</body>
</html>

🖥️ Browser Compatibility

The border property is widely supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. This property has been a part of the CSS specification since the early versions, so it works consistently across different platforms and devices.

🎉 Conclusion

The border property is a versatile and widely-used CSS property that allows you to easily add borders to elements, helping to define and highlight different sections of your webpage.

By mastering the border property and its associated values, you can create visually appealing designs that enhance the user experience. Experiment with different border styles, widths, and colors to see how they can transform the look of your web projects.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy