Text Input

Tailwind CSS and Alpine JS Text Input

Text inputs allow users to enter text into a form field. They can be used to collect information such as names, email addresses, and more.

Default text input

A text input with a label and placeholder.

HTML
<div class="">
    <label for="textInputDefault" class="">Name</label>
    <input id="textInputDefault" type="text" class="" name="name" placeholder="Enter your name" autocomplete="name"/>
</div>

Text input states

Examples of text inputs in error and success states.

Error: Name field is required
HTML
<!-- Input with error -->
<div class="">
    <label for="inputError" class="">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" aria-hidden="true" fill="currentColor" class="w-4 h-4">
            <path d="M5.28 4.22a.75.75 0 0 0-1.06 1.06L6.94 8l-2.72 2.72a.75.75 0 1 0 1.06 1.06L8 9.06l2.72 2.72a.75.75 0 1 0 1.06-1.06L9.06 8l2.72-2.72a.75.75 0 0 0-1.06-1.06L8 6.94 5.28 4.22Z"/>
        </svg>
        Name
    </label>
    <input id="inputError" type="text" class="" name="inputStates"/>
    <small class="">Error: Name field is required</small>
</div>

<!-- Input with success -->
<div class="">
    <label for="inputSuccess" class="">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" aria-hidden="true" fill="currentColor" class="w-4 h-4">
            <path fill-rule="evenodd" d="M12.416 3.376a.75.75 0 0 1 .208 1.04l-5 7.5a.75.75 0 0 1-1.154.114l-3-3a.75.75 0 0 1 1.06-1.06l2.353 2.353 4.493-6.74a.75.75 0 0 1 1.04-.207Z" clip-rule="evenodd" />
        </svg>
        Name
    </label>
    <input id="inputSuccess" type="text" class="" value="John" name="inputStates"/>
</div>

Input with mask

Requires Alpine JS Mask Plugin

A text input with a phone number mask. This component uses Alpine JS mask plugin to create the mask. Please make sure to initiate Alpine when using this plugin.

HTML
<div class="">
    <label for="phoneInput" class="">Phone</label>
    <input id="phoneInput" type="text" class="" name="phone" autocomplete="tel-national" placeholder="(999) 999-9999"/>
</div>

Search input

A text input with type search and a magnifier icon.

HTML
<div class="">
    <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true" class=""> 
        <path stroke-linecap="round" stroke-linejoin="round" d="m21 21-5.197-5.197m0 0A7.5 7.5 0 1 0 5.196 5.196a7.5 7.5 0 0 0 10.607 10.607Z" />
    </svg>
    <input type="search" class="" name="search" placeholder="Search" aria-label="search"/>
</div>

Password input

Requires Alpine JS

A text input with type password and a show/hide toggle button.

HTML
<div class="">
    <label for="passwordInput" class="">Password</label>
    <div class="">
        <input id="passwordInput" class="" name="password" autocomplete="current-password" placeholder="Enter your password"/>
        <button type="button"  class="" aria-label="Show password">
            <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true" class=""> 
                <path stroke-linecap="round" stroke-linejoin="round" d="M2.036 12.322a1.012 1.012 0 0 1 0-.639C3.423 7.51 7.36 4.5 12 4.5c4.638 0 8.573 3.007 9.963 7.178.07.207.07.431 0 .639C20.577 16.49 16.64 19.5 12 19.5c-4.638 0-8.573-3.007-9.963-7.178Z" />
                <path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" />
            </svg>
            <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true" class=""> 
                <path stroke-linecap="round" stroke-linejoin="round" d="M3.98 8.223A10.477 10.477 0 0 0 1.934 12C3.226 16.338 7.244 19.5 12 19.5c.993 0 1.953-.138 2.863-.395M6.228 6.228A10.451 10.451 0 0 1 12 4.5c4.756 0 8.773 3.162 10.065 7.498a10.522 10.522 0 0 1-4.293 5.774M6.228 6.228 3 3m3.228 3.228 3.65 3.65m7.894 7.894L21 21m-3.228-3.228-3.65-3.65m0 0a3 3 0 1 0-4.243-4.243m4.242 4.242L9.88 9.88" />
            </svg>
        </button>
    </div>
</div>

Data

List of all Alpine JS data used in this component.

Property Description
showPassword Boolean - Shows/Hides password

Keyboard Navigation

Key Action
Tab Input field gets the focus
Esc Search input: Input gets cleared