# Password

> A Password widget to allow user to enter secure string chains

Password widgets are [Input Fields](https://golemui.com/dx/widgets-reference/input-fields/overview.md) that allow the user to enter hidden string chains, commonly used for sensitive information.


```ts title="password.ts"

export default [
  gui.inputs.password('password', {
    label: 'Password',
  }),
];
```

_Live demo on the docs page. Form definition: [password.ts](https://golemui.com/template/widgets-dx/password/password.ts)._

## Props

Use these `props` to customize your Password widget.

| prop                | type   | description                                                          |
| ------------------- | ------ | -------------------------------------------------------------------- |
| `autocomplete`      | string | `'on'`, `'off'`, or a space-separated list of W3C autofill tokens    |
| `hidePasswordIcon`  | string | Icon indicating the state to hide the password (e.g. eye-slash icon) |
| `hidePasswordLabel` | string | Label text for the hide password toggle, visible if no icon is set   |
| `hint`              | string | A description to display below the password input                    |
| `icon`              | string | A css class to display an icon inside the input                      |
| `placeholder`       | string | A placeholder text to display when the password input has no value   |
| `showPasswordIcon`  | string | Icon indicating the state to show the password (e.g. eye icon)       |
| `showPasswordLabel` | string | Label text for the show password toggle, visible if no icon is set   |

The visibility toggle is a real button in the tab order, and `showPasswordLabel` / `hidePasswordLabel` double as its accessible name: screen readers announce them even when an icon replaces the visible text, so keep them meaningful when you customize the icons.

### Placeholder

Use the property `placeholder` to add a placeholder.


```ts title="password.ts"

export default [
  gui.inputs.password('password', {
    placeholder: 'Enter your secure password',
    label: 'Password',
  }),
];
```

_Live demo on the docs page. Form definition: [password-placeholder.ts](https://golemui.com/template/widgets-dx/password/password-placeholder.ts)._

### Hint

<Aside>A `label` is required for the `hint` to be displayed.</Aside>

Use the property `hint` to add a description.


```ts title="password.ts"

export default [
  gui.inputs.password('password', {
    hint: 'Must be at least 8 characters long.',
    label: 'Password',
  }),
];
```

_Live demo on the docs page. Form definition: [password-hint.ts](https://golemui.com/template/widgets-dx/password/password-hint.ts)._

### Icon

Use the property `icon` to add an icon to the `password`. The value of `icon` represents a set of CSS classes separated by spaces. The icon is displayed on the left by default. The widget also has built-in icons and labels to toggle password visibility.


```ts title="password.ts"

export default [
  gui.inputs.password('password', {
    icon: 'lock',
    label: 'Password',
  }),
];
```

_Live demo on the docs page. Form definition: [password-icon.ts](https://golemui.com/template/widgets-dx/password/password-icon.ts)._

### Show / Hide Password Icon

Use `showPasswordIcon` and `hidePasswordIcon` to customize the visibility toggle on the right of the input. Each value is a set of CSS classes (here, Material Icons) applied to the toggle button. When either icon is set, the textual label is suppressed.


```ts title="password.ts"

export default [
  gui.inputs.password('password', {
    showPasswordIcon: 'visibility',
    hidePasswordIcon: 'visibility_off',
    label: 'Password',
  }),
];
```

_Live demo on the docs page. Form definition: [password-toggle-icon.ts](https://golemui.com/template/widgets-dx/password/password-toggle-icon.ts)._

### Show / Hide Password Label

When no icon is set, the toggle renders as a text button. Use `showPasswordLabel` and `hidePasswordLabel` to override the default `Show` / `Hide` strings — useful for translations or different copy.


```ts title="password.ts"

export default [
  gui.inputs.password('password', {
    showPasswordLabel: 'Reveal',
    hidePasswordLabel: 'Mask',
    label: 'Password',
  }),
];
```

_Live demo on the docs page. Form definition: [password-toggle-label.ts](https://golemui.com/template/widgets-dx/password/password-toggle-label.ts)._

## Styling

Passwords can be styled as explained in the [Styling Guide](https://golemui.com/dx/styling/overview.md).

### CSS Variables

Following you will find a list with the CSS Variables and a quick description of what you will style.

| CSS Variable                | Description                             |
| --------------------------- | --------------------------------------- |
| `--gui-space-gap--inner`    | Label gap and margin bottom             |
| `--gui-padding`             | Input padding                           |
| `--gui-color-border`        | Input border color                      |
| `--gui-radius`              | Input radius                            |
| `--gui-color-bg`            | Input background color                  |
| `--gui-color-fg`            | Input text color                        |
| `--gui-color-primary`       | Input border color and outline on focus |
| `--gui-color-error`         | Input border color when invalid         |
| `--gui-space-gap`           | Icon left padding                       |
| `--gui-icon-space-gap`      | Icon right padding                      |
| `--gui-font-size--small`    | Hint font size                          |
| `--gui-color-fg--secondary` | Hint font color                         |
| `--gui-text-default`        | Eye icon toggle color                   |

### Anatomy

This is the anatomy of the Password Widget in case you want to use your CSS styles.


```html title="password-anatomy.html"
<gui-password-input class="gui-password gui-field">
  <gui-password class="gui-field">
    <label class="gui-label" for="fieldUid" id="fieldUid_label">
      <span class="gui-label__text">Label</span>
      <div class="gui-widget-hint" id="fieldUid_hint" aria-hidden="true">Hint</div>
    </label>

    <div class="gui-widget">
      <input
        type="password"
        id="fieldUid"
        class="gui-widget-input gui-password--icon"
        placeholder="Custom placeholder"
        aria-describedby="fieldUid_hint"
      />
      <span aria-hidden="true" class="gui-widget-icon lock" data-icon="lock"></span>
      <button type="button" class="gui-password__toggle gui-widget-icon" aria-label="Show password">
        <span aria-hidden="true">Show</span>
      </button>
    </div>

    <div class="gui-validator gui-validator--empty" id="fieldUid_errors" role="alert"></div>
  </gui-password>
</gui-password-input>
```
