🇯🇵 日本語 | 🇺🇸 English | 🇪🇸 Español | 🇵🇹 Português | 🇹🇭 ไทย | 🇨🇳 中文

CSS: Adding Dotted Border-Line with border-style: dotted

📝 Usage

This template demonstrates how to use the border-style: dotted property in CSS to create a dotted border-line.

📘 Explanation

The CSS code above uses the border-style: dotted property to add a dotted border below the h1 element. You can adjust the color and thickness as needed.

🔹 Partial Code

This box has a dotted border-line.

<div class="demo-area">
  <p>This box has a dotted border-line.</p>
</div>

<style>
  .demo-area {
    margin: 20px 0;
    padding: 10px;
    border: 2px dotted #333;
    text-align: center;
    background-color: #f0f0f0;
  }
</style>

💻 Full HTML Code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>CSS: Adding Dotted Border-Line with border-style: dotted</title>
  <link rel="stylesheet" href="/assets/css/template-common.css?v=1">
  <style>
    .demo-area {
      margin: 20px 0;
      padding: 10px;
      border: 2px dotted #333;
      text-align: center;
      background-color: #f0f0f0;
    }
  </style>
</head>
<body>
  <div class="demo-area">
    <p>This box has a dotted border-line.</p>
  </div>
</body>
</html>

💻 Full Working Code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>CSS: Adding Dotted Border-Line with border-style: dotted</title>
  <link rel="stylesheet" href="/assets/css/template-common.css?v=1">
  <style>
    .demo-area {
      margin: 20px 0;
      padding: 10px;
      border: 2px dotted #333;
      text-align: center;
      background-color: #f0f0f0;
    }
  </style>
</head>
<body>
  <div class="demo-area">
    <p>This box has a dotted border-line.</p>
  </div>
</body>
</html>
Copied!

✏️ Practical Techniques for Using Dotted Borders

The border-style: dotted property is an effective way to add a light visual accent to your design. Unlike solid lines, dotted borders offer a different visual effect that can be used for separating content or as a decorative element.

🎨 Design Variations

In addition to the default black (#333), you can customize the color to match your site’s theme. For example, #007acc (blue) or #e74c3c (red) can stand out, while #999 gives a more subtle look. You can also adjust border-width to change the size of the dots and create more variation.

📐 Practical Layout Uses

Dotted borders are especially effective in the following cases:
- Dividers between sections
- Borders for form field notes
- Coupon or ticket-style designs
- Boxes for disclaimers or legal notes

⚠️ Points of Caution

Dotted borders are less visually prominent than solid ones, so they are not ideal for enclosing critical information. Also, fine dotted lines may not print well, so for print stylesheets consider switching to border-style: solid.

Dotted borders are a great decorative accent, but overusing them can create a cluttered look. Keep their use consistent across the site and limit them to specific, intentional purposes.