2020-07-15 21:30:37 +00:00
# Input
[component-header:sl-input]
Inputs collect data from the user.
```html preview
< sl-input > < / sl-input >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlInput } from '@shoelace-style/shoelace/dist/react';
2022-03-02 15:10:41 +00:00
const App = () => < SlInput / > ;
2021-11-04 22:12:47 +00:00
```
2022-01-11 14:18:20 +00:00
?> This component works with standard `<form>` elements. Please refer to the section on [form controls ](/getting-started/form-controls ) to learn more about form submission and client-side validation.
2020-08-28 20:14:39 +00:00
2020-07-15 21:30:37 +00:00
## Examples
2020-08-25 20:23:33 +00:00
### Placeholders
2020-07-15 21:30:37 +00:00
2020-08-25 20:23:33 +00:00
Use the `placeholder` attribute to add a placeholder.
2020-07-15 21:30:37 +00:00
```html preview
2020-08-25 20:23:33 +00:00
< sl-input placeholder = "Type something" > < / sl-input >
2020-07-15 21:30:37 +00:00
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlInput } from '@shoelace-style/shoelace/dist/react';
2022-03-02 15:10:41 +00:00
const App = () => < SlInput placeholder = "Type something" / > ;
2021-11-04 22:12:47 +00:00
```
2020-08-25 20:23:33 +00:00
### Clearable
2020-07-15 21:30:37 +00:00
2021-07-08 21:41:10 +00:00
Add the `clearable` attribute to add a clear button when the input has content.
2020-07-15 21:30:37 +00:00
```html preview
2020-08-25 20:23:33 +00:00
< sl-input placeholder = "Clearable" clearable > < / sl-input >
2020-07-15 21:30:37 +00:00
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlInput } from '@shoelace-style/shoelace/dist/react';
2022-03-02 15:10:41 +00:00
const App = () => < SlInput placeholder = "Clearable" clearable / > ;
2021-11-04 22:12:47 +00:00
```
2020-08-25 20:23:33 +00:00
### Toggle Password
2020-07-15 21:30:37 +00:00
2021-07-08 21:41:10 +00:00
Add the `toggle-password` attribute to add a toggle button that will show the password when activated.
2020-07-15 21:30:37 +00:00
```html preview
2020-08-25 20:23:33 +00:00
< sl-input type = "password" placeholder = "Password Toggle" size = "small" toggle-password > < / sl-input >
2022-03-02 15:10:41 +00:00
< br / >
2020-08-25 20:23:33 +00:00
< sl-input type = "password" placeholder = "Password Toggle" size = "medium" toggle-password > < / sl-input >
2022-03-02 15:10:41 +00:00
< br / >
2020-08-25 20:23:33 +00:00
< sl-input type = "password" placeholder = "Password Toggle" size = "large" toggle-password > < / sl-input >
2020-07-15 21:30:37 +00:00
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlInput } from '@shoelace-style/shoelace/dist/react';
const App = () => (
< >
< SlInput type = "password" placeholder = "Password Toggle" size = "small" toggle-password / >
< br / >
< SlInput type = "password" placeholder = "Password Toggle" size = "medium" toggle-password / >
< br / >
2022-03-02 15:10:41 +00:00
< SlInput type = "password" placeholder = "Password Toggle" size = "large" toggle-password / >
2021-11-04 22:12:47 +00:00
< />
);
```
2021-09-25 02:28:14 +00:00
### Filled Inputs
Add the `filled` attribute to draw a filled input.
```html preview
< sl-input placeholder = "Type something" filled > < / sl-input >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlInput } from '@shoelace-style/shoelace/dist/react';
2022-03-02 15:10:41 +00:00
const App = () => < SlInput placeholder = "Type something" filled / > ;
2021-11-04 22:12:47 +00:00
```
2020-07-15 21:30:37 +00:00
### Pill
2021-07-08 21:41:10 +00:00
Use the `pill` attribute to give inputs rounded edges.
2020-07-15 21:30:37 +00:00
```html preview
< sl-input placeholder = "Small" size = "small" pill > < / sl-input >
2022-03-02 15:10:41 +00:00
< br / >
2020-07-15 21:30:37 +00:00
< sl-input placeholder = "Medium" size = "medium" pill > < / sl-input >
2022-03-02 15:10:41 +00:00
< br / >
2020-07-15 21:30:37 +00:00
< sl-input placeholder = "Large" size = "large" pill > < / sl-input >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlInput } from '@shoelace-style/shoelace/dist/react';
const App = () => (
< >
< SlInput placeholder = "Small" size = "small" pill / >
< br / >
< SlInput placeholder = "Medium" size = "medium" pill / >
< br / >
< SlInput placeholder = "Large" size = "large" pill / >
< />
);
```
2021-08-24 12:13:36 +00:00
### Input Types
The `type` attribute controls the type of input the browser renders.
```html preview
< sl-input type = "email" Placeholder = "Email" > < / sl-input >
2022-03-02 15:10:41 +00:00
< br / >
2021-08-24 12:13:36 +00:00
< sl-input type = "number" Placeholder = "Number" > < / sl-input >
2022-03-02 15:10:41 +00:00
< br / >
2021-08-24 12:13:36 +00:00
< sl-input type = "date" Placeholder = "Date" > < / sl-input >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlInput } from '@shoelace-style/shoelace/dist/react';
const App = () => (
< >
< SlInput type = "email" Placeholder = "Email" / >
< br / >
< SlInput type = "number" Placeholder = "Number" / >
< br / >
< SlInput type = "date" Placeholder = "Date" / >
< />
);
```
2020-08-25 20:23:33 +00:00
### Disabled
Use the `disabled` attribute to disable an input.
```html preview
< sl-input placeholder = "Disabled" size = "small" disabled > < / sl-input >
2022-03-02 15:10:41 +00:00
< br / >
2020-08-25 20:23:33 +00:00
< sl-input placeholder = "Disabled" size = "medium" disabled > < / sl-input >
2022-03-02 15:10:41 +00:00
< br / >
2020-08-25 20:23:33 +00:00
< sl-input placeholder = "Disabled" size = "large" disabled > < / sl-input >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlInput } from '@shoelace-style/shoelace/dist/react';
const App = () => (
< >
< SlInput placeholder = "Disabled" size = "small" disabled / >
< br / >
< SlInput placeholder = "Disabled" size = "medium" disabled / >
< br / >
< SlInput placeholder = "Disabled" size = "large" disabled / >
< />
);
```
2020-08-25 20:23:33 +00:00
### Sizes
Use the `size` attribute to change an input's size.
```html preview
< sl-input placeholder = "Small" size = "small" > < / sl-input >
2022-03-02 15:10:41 +00:00
< br / >
2020-08-25 20:23:33 +00:00
< sl-input placeholder = "Medium" size = "medium" > < / sl-input >
2022-03-02 15:10:41 +00:00
< br / >
2020-08-25 20:23:33 +00:00
< sl-input placeholder = "Large" size = "large" > < / sl-input >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlInput } from '@shoelace-style/shoelace/dist/react';
const App = () => (
< >
< SlInput placeholder = "Small" size = "small" / >
< br / >
< SlInput placeholder = "Medium" size = "medium" / >
< br / >
< SlInput placeholder = "Large" size = "large" / >
< />
);
```
2020-07-15 21:30:37 +00:00
### Prefix & Suffix Icons
Use the `prefix` and `suffix` slots to add icons.
```html preview
< sl-input placeholder = "Small" size = "small" >
2021-08-16 21:05:28 +00:00
< sl-icon name = "house" slot = "prefix" > < / sl-icon >
< sl-icon name = "chat" slot = "suffix" > < / sl-icon >
2020-07-15 21:30:37 +00:00
< / sl-input >
2022-03-02 15:10:41 +00:00
< br / >
2020-07-15 21:30:37 +00:00
< sl-input placeholder = "Medium" size = "medium" >
2021-08-16 21:05:28 +00:00
< sl-icon name = "house" slot = "prefix" > < / sl-icon >
< sl-icon name = "chat" slot = "suffix" > < / sl-icon >
2020-07-15 21:30:37 +00:00
< / sl-input >
2022-03-02 15:10:41 +00:00
< br / >
2020-07-15 21:30:37 +00:00
< sl-input placeholder = "Large" size = "large" >
2021-08-16 21:05:28 +00:00
< sl-icon name = "house" slot = "prefix" > < / sl-icon >
< sl-icon name = "chat" slot = "suffix" > < / sl-icon >
2020-07-15 21:30:37 +00:00
< / sl-input >
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlIcon, SlInput } from '@shoelace-style/shoelace/dist/react';
const App = () => (
< >
< SlInput placeholder = "Small" size = "small" >
< SlIcon name = "house" slot = "prefix" > < / SlIcon >
< SlIcon name = "chat" slot = "suffix" > < / SlIcon >
< / SlInput >
< br / >
< SlInput placeholder = "Medium" size = "medium" >
< SlIcon name = "house" slot = "prefix" > < / SlIcon >
< SlIcon name = "chat" slot = "suffix" > < / SlIcon >
< / SlInput >
< br / >
< SlInput placeholder = "Large" size = "large" >
< SlIcon name = "house" slot = "prefix" > < / SlIcon >
< SlIcon name = "chat" slot = "suffix" > < / SlIcon >
< / SlInput >
< />
);
```
2020-08-25 20:23:33 +00:00
### Labels
2020-07-15 21:30:37 +00:00
2020-12-23 20:47:13 +00:00
Use the `label` attribute to give the input an accessible label. For labels that contain HTML, use the `label` slot instead.
2020-07-15 21:30:37 +00:00
```html preview
2020-12-23 20:47:13 +00:00
< sl-input label = "What is your name?" > < / sl-input >
2020-07-15 21:30:37 +00:00
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlIcon, SlInput } from '@shoelace-style/shoelace/dist/react';
2022-03-02 15:10:41 +00:00
const App = () => < SlInput label = "What is your name?" / > ;
2021-11-04 22:12:47 +00:00
```
2020-08-25 20:23:33 +00:00
### Help Text
2020-07-15 21:30:37 +00:00
2020-12-23 20:47:13 +00:00
Add descriptive help text to an input with the `help-text` attribute. For help texts that contain HTML, use the `help-text` slot instead.
2020-09-24 12:58:27 +00:00
```html preview
2022-03-02 15:10:41 +00:00
< sl-input label = "Nickname" help-text = "What would you like people to call you?" > < / sl-input >
2020-09-24 12:58:27 +00:00
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlIcon, SlInput } from '@shoelace-style/shoelace/dist/react';
2022-03-02 15:10:41 +00:00
const App = () => < SlInput label = "Nickname" help-text = "What would you like people to call you?" / > ;
2021-11-04 22:12:47 +00:00
```
2020-07-15 21:30:37 +00:00
[component-metadata:sl-input]