package showcase
import "github.com/templui/templui/components/inputotp"
templ InputOTPDefault() {
@inputotp.InputOTP() {
@inputotp.Group() {
@inputotp.Slot(inputotp.SlotProps{
Index: 0,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 1,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 2,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 3,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 4,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 5,
})
}
}
}
Installation
templui add inputotpLoad the script once in your layout:
<head>
@inputotp.Script()
</head>import "github.com/templui/templui/components/inputotp"Load the script once in your layout:
<head>
@inputotp.Script()
</head>Examples
Placeholder
package showcase
import "github.com/templui/templui/components/inputotp"
templ InputOTPPlaceholder() {
@inputotp.InputOTP() {
@inputotp.Group() {
@inputotp.Slot(inputotp.SlotProps{
Index: 0,
Placeholder: "•",
})
@inputotp.Slot(inputotp.SlotProps{
Index: 1,
Placeholder: "•",
})
@inputotp.Slot(inputotp.SlotProps{
Index: 2,
Placeholder: "•",
})
@inputotp.Separator()
@inputotp.Slot(inputotp.SlotProps{
Index: 3,
Placeholder: "•",
})
@inputotp.Slot(inputotp.SlotProps{
Index: 4,
Placeholder: "•",
})
@inputotp.Slot(inputotp.SlotProps{
Index: 5,
Placeholder: "•",
})
}
}
}
With Label
package showcase
import "github.com/templui/templui/components/inputotp"
import "github.com/templui/templui/components/label"
templ InputOTPWithLabel() {
<div class="w-full max-w-sm flex flex-col gap-2">
@label.Label(label.Props{
For: "otp-with-label",
}) {
Verification Code
}
@inputotp.InputOTP(inputotp.Props{
ID: "otp-with-label",
HasError: true,
}) {
@inputotp.Group() {
@inputotp.Slot(inputotp.SlotProps{
Index: 0,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 1,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 2,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 3,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 4,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 5,
})
}
}
</div>
}
Custom Length
package showcase
import "github.com/templui/templui/components/inputotp"
templ InputOTPCustomLength() {
@inputotp.InputOTP(inputotp.Props{
ID: "otp-custom-length",
}) {
@inputotp.Group() {
@inputotp.Slot(inputotp.SlotProps{
Index: 0,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 1,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 2,
})
}
}
}
Password Type
package showcase
import "github.com/templui/templui/components/inputotp"
templ InputOTPPasswordType() {
@inputotp.InputOTP(inputotp.Props{
ID: "otp-password",
}) {
@inputotp.Group() {
@inputotp.Slot(inputotp.SlotProps{
Index: 0,
Type: "password",
})
@inputotp.Slot(inputotp.SlotProps{
Index: 1,
Type: "password",
})
@inputotp.Slot(inputotp.SlotProps{
Index: 2,
Type: "password",
})
@inputotp.Separator()
@inputotp.Slot(inputotp.SlotProps{
Index: 3,
Type: "password",
})
@inputotp.Slot(inputotp.SlotProps{
Index: 4,
Type: "password",
})
@inputotp.Slot(inputotp.SlotProps{
Index: 5,
Type: "password",
})
}
}
}
Custom Styling
package showcase
import "github.com/templui/templui/components/inputotp"
templ InputOTPCustomStyling() {
@inputotp.InputOTP(inputotp.Props{
ID: "otp-styled",
}) {
@inputotp.Group(inputotp.GroupProps{
Class: "gap-3",
}) {
@inputotp.Slot(inputotp.SlotProps{
Index: 0,
Class: "w-12 h-14 bg-primary/10 border-primary text-lg font-bold",
})
@inputotp.Slot(inputotp.SlotProps{
Index: 1,
Class: "w-12 h-14 bg-primary/10 border-primary text-lg font-bold",
})
@inputotp.Slot(inputotp.SlotProps{
Index: 2,
Class: "w-12 h-14 bg-primary/10 border-primary text-lg font-bold",
})
@inputotp.Separator(inputotp.SeparatorProps{
Class: "text-2xl font-bold text-primary",
}) {
<span>:</span>
}
@inputotp.Slot(inputotp.SlotProps{
Index: 3,
Class: "w-12 h-14 bg-primary/10 border-primary text-lg font-bold",
})
@inputotp.Slot(inputotp.SlotProps{
Index: 4,
Class: "w-12 h-14 bg-primary/10 border-primary text-lg font-bold",
})
@inputotp.Slot(inputotp.SlotProps{
Index: 5,
Class: "w-12 h-14 bg-primary/10 border-primary text-lg font-bold",
})
}
}
}
Form
Enter the 6-digit code sent to your phone
Invalid verification code.
package showcase
import (
"github.com/templui/templui/components/form"
"github.com/templui/templui/components/inputotp"
)
templ InputOTPForm() {
@form.Item() {
@form.Label(form.LabelProps{
For: "otp-form",
}) {
Verification Code
}
@inputotp.InputOTP(inputotp.Props{
ID: "otp-form",
HasError: true,
}) {
@inputotp.Group() {
@inputotp.Slot(inputotp.SlotProps{
Index: 0,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 1,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 2,
})
@inputotp.Separator()
@inputotp.Slot(inputotp.SlotProps{
Index: 3,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 4,
})
@inputotp.Slot(inputotp.SlotProps{
Index: 5,
})
}
}
@form.Description() {
Enter the 6-digit code sent to your phone
}
@form.Message(form.MessageProps{
Variant: form.MessageVariantError,
}) {
Invalid verification code.
}
}
}
API Reference
InputOTP
Main container for the OTP input component.
| Name | Type | Default |
|---|---|---|
Unique identifier for the OTP input component | | |
Additional CSS classes to apply to the container | | |
Additional HTML attributes to apply to the container | | |
Current value of the OTP input | | |
Name attribute for the hidden input field | | |
Whether the OTP input should display error styling | | |
Group
Container for grouping OTP slots together.
| Name | Type | Default |
|---|---|---|
Unique identifier for the group element | | |
Additional CSS classes to apply to the group | | |
Additional HTML attributes to apply to the group | | |
Slot
Individual input slot for a single character.
| Name | Type | Default |
|---|---|---|
Unique identifier for the slot element | | |
Additional CSS classes to apply to the slot | | |
Additional HTML attributes to apply to the slot | | |
Index position of this slot in the OTP sequence | | |
Input type for the slot (text or password) | | |
Placeholder text for the slot | | |
Whether the slot is disabled | | |
Separator
Visual separator between groups of slots.
| Name | Type | Default |
|---|---|---|
Unique identifier for the separator element | | |
Additional CSS classes to apply to the separator | | |
Additional HTML attributes to apply to the separator | | |