inside scrollbar with rounded corner

by Guillaume Seguin

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Rounded Block with Custom Scrollbar</title>
</head>
<body>

  <div class="scroll-card">
    <h2>Rounded Scroll Block</h2>
    <p>This box features rounded corners (<code>border-radius: 20px</code>) and an internal scrollbar triggered by <code>overflow-y: auto</code> once the content exceeds its fixed height.</p>
    <p>The scrollbar is styled using modern standard CSS properties (<code>scrollbar-width</code> and <code>scrollbar-color</code>) along with <code>::-webkit-scrollbar</code> pseudoelements for complete cross-browser styling.</p>
    <p>Adding vertical margins (<code>margin: 12px 0</code>) to the scrollbar track prevents the thumb from clipping against the curved outer edges of the card, preserving a clean aesthetic.</p>
    <p>Feel free to scroll back up and inspect the smooth rounding!</p>
  </div>

</body>
</html>

CSS

* {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    body {
      font-family: system-ui, -apple-system, sans-serif;
      background-color: #f3f4f6;
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
      padding: 1.5rem;
    }

    .scroll-card {
      width: 100%;
      max-width: 420px;
      height: 320px;
      background-color: #ffffff;
      border-radius: 20px;
      padding: 1.5rem;
      box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
      border: 1px solid #e5e7eb;

      /* Enable vertical scrollbar inside the block */
      overflow-y: auto;

      /* Standard scrollbar styling (Firefox & modern browsers) */
      scrollbar-width: thin;
      scrollbar-color: #cbd5e1 transparent;
    }

    .scroll-card h2 {
      font-size: 1.25rem;
      color: #0f172a;
      margin-bottom: 0.75rem;
    }

    .scroll-card p {
      color: #475569;
      line-height: 1.6;
      margin-bottom: 1rem;
    }