Created
February 13, 2025 16:56
-
-
Save Ebrahim-Ramadan/858302821c27c3ac7350d14110dee10b to your computer and use it in GitHub Desktop.
OTP input with css only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <input type="text" maxlength="6"> | |
| <style> | |
| input[type=text] { | |
| --w: 1ch; /* control the width for each letter */ | |
| --g: .15em; /* the gap between letters */ | |
| --b: 2px; /* the border thickness */ | |
| --c: #888; | |
| --_n: attr(maxlength type(<integer>)); | |
| font-size: 70px; | |
| line-height: 1.5; /* control the height */ | |
| letter-spacing: var(--w); | |
| font-family: monospace; | |
| width: calc(var(--_n)*(1ch + var(--w))); | |
| padding-left: calc((var(--w) - var(--g))/2); | |
| clip-path: inset(0 calc(var(--w)/2) 0 0); | |
| background: | |
| repeating-linear-gradient(90deg, | |
| var(--c) 0 var(--b),#0000 0 calc(1ch + var(--w) - var(--g) - var(--b)), | |
| var(--c) 0 calc(1ch + var(--w) - var(--g)),#0000 0 calc(1ch + var(--w))), | |
| conic-gradient(at calc(100% - var(--g) - 1px) var(--b),#0000 75%,var(--c) 0) | |
| 0 0/calc(1ch + var(--w)) calc(100% - var(--b)); | |
| } | |
| </style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment