KTUIKTUI
KTUIKTUI
ComponentsDocsStudio

Getting Started

IntroductionInstallationApproachThemingJavaScriptDark modeRTLReferencesChangelog - v1.0.12Metronic TemplatePopular

Components

AccordionAvatarAlertBadgeBreadcrumbButtonCardCheckboxCollapseDatatableDatepickerSoonDismissDrawerDropdownImage InputInputUpdateKbdLinkModalPaginationProgressRadio GroupReparentScrollableScrollspyUpdateScrolltoSelectSeparatorSkeletonStepperStickySwitchTabsTextareaTheme SwitchToastNewTooltipToggleToggle GroupToggle PasswordTooltip
©2025 KtUI. All rights reserved.
A project by Keenthemes
Docs
Tailwind Toggle Password

Tailwind Toggle Password

The Tailwind Toggle Password component allows users to easily switch between displaying and hiding their password input. This enhances security and user experience by providing a clear and intuitive way to manage password visibility.

Examples

Basic Usage

A basic usage of Tailwind Toggle Password component.

<div class="relative max-w-72" data-kt-toggle-password="true">
  <input type="password" class="kt-input pe-10" placeholder="Password" /><button
    class="kt-btn kt-btn-icon kt-btn-ghost size-6 absolute end-2 top-1/2 -translate-y-1/2"
    data-kt-toggle-password-trigger="true"
  >
    <svg
      xmlns="http://www.w3.org/2000/svg"
      width="24"
      height="24"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2"
      stroke-linecap="round"
      stroke-linejoin="round"
      class="lucide lucide-eye kt-toggle-password-active:hidden"
      aria-hidden="true"
    >
      <path
        d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"
      ></path>
      <circle cx="12" cy="12" r="3"></circle></svg
    ><svg
      xmlns="http://www.w3.org/2000/svg"
      width="24"
      height="24"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2"
      stroke-linecap="round"
      stroke-linejoin="round"
      class="lucide lucide-eye-off hidden kt-toggle-password-active:block"
      aria-hidden="true"
    >
      <path
        d="M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"
      ></path>
      <path d="M14.084 14.158a3 3 0 0 1-4.242-4.242"></path>
      <path
        d="M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"
      ></path>
      <path d="m2 2 20 20"></path>
    </svg>
  </button>
</div>

Permanent

Use data-kt-toggle-password-permanent="true" attribute to set whether the password remains visible once unmasked, even after typing begins.

<div
  class="relative max-w-72"
  data-kt-toggle-password="true"
  data-kt-toggle-password-permanent="true"
>
  <input type="password" class="kt-input pe-10" placeholder="Password" /><button
    class="kt-btn kt-btn-icon kt-btn-ghost size-6 absolute end-2 top-1/2 -translate-y-1/2"
    data-kt-toggle-password-trigger="true"
  >
    <svg
      xmlns="http://www.w3.org/2000/svg"
      width="24"
      height="24"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2"
      stroke-linecap="round"
      stroke-linejoin="round"
      class="lucide lucide-eye kt-toggle-password-active:hidden"
      aria-hidden="true"
    >
      <path
        d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"
      ></path>
      <circle cx="12" cy="12" r="3"></circle></svg
    ><svg
      xmlns="http://www.w3.org/2000/svg"
      width="24"
      height="24"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2"
      stroke-linecap="round"
      stroke-linejoin="round"
      class="lucide lucide-eye-off hidden kt-toggle-password-active:block"
      aria-hidden="true"
    >
      <path
        d="M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"
      ></path>
      <path d="M14.084 14.158a3 3 0 0 1-4.242-4.242"></path>
      <path
        d="M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"
      ></path>
      <path d="m2 2 20 20"></path>
    </svg>
  </button>
</div>

Component API

Options

These data attributes allow you to set options for the toggle-password component during auto initialization.

| Name | Type | Default | Description | | ----------------------------------- | --------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --- | | data-kt-toggle-password-permanent | boolean | "false" | Determines whether the password remains visible once unmasked, even after typing begins. By default the password is automatically hidden again when typing starts if it was set to visible. | |

Selectors

This table details the custom classes and data attributes used by the toggle-password component.

NameDescription
Data Attributes
data-kt-toggle-password="true"Used to auto-initialize KTTogglePassword instances on page load.
data-kt-toggle-password-trigger="true"Identifies an element as the control for toggling the password visibility, allowing the user to switch between showing and hiding the password.

Tailwind Modifiers

Custom modifiers to control the toggle-password’s style and behavior with Tailwind classes.

NameDescription
kt-toggle-password-active:*A modifier that applies specific Tailwind classes when the section becomes active.

Methods

Use KTTogglePassword component's API methods to programmatically control its behavior.

MethodDescription
new KTTogglePassword(element, options)Creates an object instance of KTTogglePassword class for the given DOM element and configuration options .
toggle()Switches the password visibility state. If the password is currently hidden, it becomes visible, and vice versa.
setVisible(flag)Sets the password visibility explicitly based on the flag parameter. If flag is true , the password is made visible. if false , the password is masked.
isActive()Returns a boolean value indicating whether the password visibility is currently active (i.e., if the password is visible, it returns true ; otherwise, it returns false` ).
getOption(name)Retrieves the value of a configuration option by name parameter from a KTTogglePassword instance.
getElement()Retrieves the DOM element linked to a specific KTTogglePassword instance.
on(eventName, handler)Allows attaching event listeners to the KTTogglePassword custom events using the eventName and eventId string parameters. These events enable programmatic interaction based on user actions or internal state changes of KTTogglePassword. The function returns string as a unique identifier for the registered listener, allowing you to remove it later if needed.
off(eventName, eventId)Removes an event listener for the eventName and eventId parameters attached with the on method.
dispose()Removes the KTTogglePassword instance from an element, including any associated data stored on the DOM element.
const togglePasswordEl = document.querySelector('#my-toggle-password');
const togglePassword = KTTogglePassword.getInstance(togglePasswordEl);
 
togglePassword.toggle();

Utilities

Manage and interact with KTTogglePassword instances using these static methods of KTTogglePassword JavaScript class.

| Method | Description | | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | --- | | init() | Automatically initializes KTTogglePassword object for all elements with the data-kt-toggle="true" attribute on page load. | | createInstances() | Allows to create KTTogglePassword instances for all elements that have been dynamically added to the DOM but haven't been activated yet. | | | getInstance(element) | Returns the KTTogglePassword object associated with the given DOM element element . | | getOrCreateInstance(element) | Returns the existing KTTogglePassword object for the provided DOM element element , or creates a new instance if none exists, then returns the same. |

// Initialize all togglees
KTTogglePassword.init();
 
// Initialzie pending togglees
KTTogglePassword.createInstances();
 
// Get toggle object
const togglePasswordEl = document.querySelector('#my-toggle-password');
const togglePassword = KTTogglePassword.getInstance(togglePasswordEl);

Events

KTTogglePassword custom events allows you to register callback functions(event listeners) that will be invoked automatically whenever specific custom events are triggered within the component.

EventDescription
toggleTriggered immediately before an password visibility is changed.
toggledTriggered immediately after an password visibility is changed.
const togglePasswordEl = document.querySelector('#my-toggle-password');
const togglePassword = KTTogglePassword.getInstance(togglePasswordEl);
 
togglePassword.on('toggle', () => {
  detail.cancel = true;
  console.log('toggle action canceled');
});
 
togglePassword.on('toggled', () => {
  console.log('toggled event');
});
PreviouseToggle GroupNextTooltip

On This Page

  • Examples
    • Basic Usage
    • Permanent
  • Component API
    • Options
    • Selectors
    • Tailwind Modifiers
    • Methods
    • Utilities
    • Events