Customize text decoration with CSS

by Fabio Dan

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>Custom Dotted Underline</title>
  <style>
    body {
      font-family: sans-serif;
      padding: 2rem;
    }

    .dotted-underline {
      display: inline;
      background-image: radial-gradient(currentColor 4px, transparent 1px);
      background-size: 6px 2px; /* space between dots and line height */
      background-repeat: repeat-x;
      background-position: 0 100%;
      padding-bottom: 2px; /* spacing between text and dots */
      text-decoration: none;
    }
  </style>
</head>
<body>

  <p>
    This is an example of a 
    <span class="dotted-underline">custom dotted underline</span> 
    using CSS with adjustable dot size and spacing.
  </p>

</body>
</html>