week - Use lightning-combobox or lightning-input with the number type instead.
month - Use lightning-combobox or lightning-input with the number type instead.
The week and month types are browser-dependent and can cause issues with styling, accessibility, and general functionality in specific browsers.
Design
lightning-input implements designs in the Salesforce Lightning Design System (SLDS). The input types adapt to SLDS 1 or SLDS 2 styling based on the org’s theme or the container app that you use.
These input types-email, number, password, search, tel, text, url-use the same SLDS design.
An input field for entering an email address. UTF-8 encoding is supported for international email addresses. Valid email addresses include name@example and name@example.com. The email pattern is automatically validated during the blur event.
To restrict email input to match a certain pattern, use the pattern attribute to specify a regular expression. For example, pass in pattern=".+@example.com" to accept an email address only from the domain example.com. When using pattern, you can provide a custom validation error message using the message-when-pattern-mismatch attribute.
You can also include a hint of what a user can enter using the placeholder attribute. The placeholder text is displayed on the field before a user enters an input, but it doesn’t validate input.
To specify the maximum number of characters for an email address, use the maxlength attribute.
When using maxlength, you can provide a custom validation error message using the message-when-too-long attribute.
1<template>2 <lightning-input3 type="email"4 label="Email"5 maxlength="50"6 message-when-too-long="Your email address must not be more than 50 characters."7 >8 </lightning-input>9</template>
To specify the minimum number of characters for an email address, use the minlength attribute.
When using minlength, you can provide a custom validation error message using the message-when-too-short attribute.
1<template>2 <lightning-input3 type="email"4 label="Email"5 minlength="5"6 message-when-too-short="Your email address must be more 5 characters."7 >8 </lightning-input>9</template>
When multiple is used, the email field expects a single email address or a comma-separated list of email addresses. For example, my@example.com,your@example.com with or without a space after the comma.
To specify valid increments for numerical fields, use the step attribute. The value of step constrains the numbers
that users can enter. If you don’t specify step, the default value of 1 allows users to enter only integers.
To enable decimal number entry, specify a value for step that represents the number of decimal places accepted and
the increment. For example, specifying step=".01" permits numbers such as 0.99 and 123456.78. Specifying step=".20" permits
numbers such as 18.60 but not 18.61 or 18.70.
If a user enters a number that doesn’t match the step value, the browser flags it as invalid. Some browsers can round the number instead.
To format numerical input as a percentage or currency, set formatter to
percent or currency respectively. To allow for decimal numbers,
specify the step attribute as well.
For the percent formatter, the entered number is multiplied by 100 on blur to display the percentage. For example, when you enter .75 the value displays as 75%. When you enter 1, the value displays as 100%. To enter a percentage value as is, use formatter="percent-fixed". When you enter .75, the value displays as .75%, and when you enter 1, the value displays as 1%.
1<template>2 <lightning-input type="number" label="Enter a decimal value" step="0.001">3 </lightning-input>4 <lightning-input5 type="number"6 label="Enter a percentage value"7 formatter="percent"8 step="0.01"9 >10 </lightning-input>11 <lightning-input12 type="number"13 label="Enter a dollar amount"14 formatter="currency"15 step="0.01"16 >17 </lightning-input>18</template>
Number formatting is based on the Intl.NumberFormat object and follows ISO guidelines, displaying a value based on the org currency and your Salesforce locale. For example, when using formatter="currency" step=".01", entering “123.45” displays “€123,45” if your org’s currency is set to EUR and your Salesforce locale is German. Your Salesforce locale is also used to determine if the number you entered is valid.
Number Validation
The number field does not let you type invalid characters, although anything can be pasted in. When a field contains invalid characters, a default field-level error is displayed on blur and the value property returns an empty string.
The invalid input continues to be displayed to allow the user to correct the entry. See the Input Validation and Error Messages sections for more information. Valid characters include digits, number shortcuts, exponential numbers, positive and negative signs, and decimal separators.
The lightning-input component uses the Javascript parseFloat() function to convert input value strings to numbers. Very large numbers with more than approximately 15 or 16 total digits can lose precision and appear to be rounded. Browsers can handle this loss of numeric precision differently, causing variation in decimal point rounding.
For example, parseFloat("12345678901234.12345") is stored in memory as 12345678901234.123, which appears rounded. The parsed value in memory is used for validation, not the entered number. As a result, a number that should be invalid can be accepted as valid due to the loss of precision in the stored value. If your lightning-input component
sets step="0.0001", the entered value 12345678901234.12345 is invalid. However, the stored value
12345678901234.123 is valid, so the entered value is accepted.
Digits
Digits are the numbers 0 to 9. Invalid placement of 0’s are removed. For example, 010 results in 10. Trailing zeros after the decimal separator are also removed to match any given step pattern.
Number Shortcuts
Shortcuts such as k, K, m, M, b, B, t, and T are allowed. For the en-US locale, when you enter 1k the field displays 1,000. Entering 1m results in 1,000,000. When the input field is focused, the input value is the multiplied number. For example, entering 1k results in 1,000 on blur, and 1000 when the input is focused again.
Shortcuts are not supported via the value attribute.
Exponential Numbers
The letter e or E is accepted when entering an exponential number. For example, when you enter 2e2 the field displays 200 on blur, and 2e2 when the input is focused again.
Positive and Negative Signs
Use + and - characters to represent positive and negative numbers. The positive + sign is removed on blur. If your number starts with +. or -., 0 is added before the decimal separator. For example, entering +.2 results in 0.2 on blur.
Decimal Separators
Decimal separators are valid when you use the step attribute. Only the . and , decimal separators are allowed. If your number starts with a decimal separator, 0 is added before the decimal separator. For example, entering .2 results in 0.2 on blur.
Step
We recommend using a maximum of 9 decimal places for value and a maximum of 15 decimal places for step. Browsers exhibit inconsistencies in number calculation when you use more decimal places.
For example, a value of 9.9999999999 has more than 9 decimal places, and is interpreted as 10.0 by some browsers. If step is 0.01, stepMismatch validates as false when you enter 9.9999999999 because 10.0 matches the step. The messageWhenStepMismatch validation message isn’t displayed and the field incorrectly displays as valid.
Similar behavior occurs when step has a value such as 0.000000000000001, which is more than 15 decimal places.
Password
An input field for entering a password. Characters you enter are masked.
Use the value attribute to optionally supply an initial value for the password. Use pattern to pass
a regular expression to validate the password characters.
A search field that contains a value displays an X button to clear the search. Press the button to remove the value on the field. It also fires the blur, change, and commit events in that order. When the Enter key is pressed, the search field fires the commit event.
To indicate activity in the search field with a spinner, such as data loading, include the is-loading attribute.
When a search field is invalid, the field is displayed with a red border and a red search icon. However, an error icon isn’t displayed as it is for the other input types.
Tel
An input field for entering a telephone number. Use the pattern attribute to
define a pattern for field validation.
An input field for entering text. This is the default input type.
The value attribute for this input type only supports string values. To clear a text field by setting the value attribute, use "" to specify an empty string because null isn’t supported.
An input field for entering a URL. The address must include the protocol, such
as http:// or ftp://. The URL pattern is automatically validated during the
blur event. To enter the address without the protocol, such as
www.example.com, use the default type="text" instead.
Client-side input validation is available for this component. An invalid field is displayed with a red border and an error icon next to the field. An error message in red text is also displayed below the field. For example, an
error message is displayed when a URL or email address is expected for an
input type of url or email. Note that disabled and read-only inputs are
always valid.
An error icon is displayed on fields that are in an invalid state for these input types.
email
number
password
range
tel
text
url
An error icon is displayed on fields, except on desktop browsers, for these input types.
date
datetime
datetime-local
time
You can define additional field requirements. For example, to set a maximum
value on a number field, use the max attribute.
To check the validity states of an input, use the validity attribute, which
is based on the Constraint Validation API. To determine if a field is valid,
you can access the validity states in JavaScript. Let’s say
you have this input field.
1<template>2 <lightning-input3 class="input"4 label="Enter some text"5 onblur={handleBlur}6 >7 </lightning-input>8</template>
The validity attribute returns true for the valid property because all constraint validations are met,
and in this case there are none.
1import{LightningElement}from 'lwc';23export default class DemoInput extends LightningElement{45 handleBlur(event){6 var input = this.template.querySelector(".input");7 console.log(input.validity.valid); //returns true8}
For example, you have the following form with several fields and a button. To
display error messages on invalid fields, use the reportValidity() method.
1export default class InputHandler extends LightningElement{2 value = "initial value";34 handleClick(evt){5 console.log("Current value of the input: " + evt.target.value);67 const allValid = [...this.template.querySelectorAll("lightning-input")].reduce(8(validSoFar, inputCmp)=>{9 inputCmp.reportValidity();10 return validSoFar && inputCmp.checkValidity();11},12 true,13);14 if(allValid){15 alert("All form entries look valid. Ready to submit!");16}else{17 alert("Please update the invalid form entries and try again.");18}19}20}
This validity attribute returns an object with these read-only boolean
properties. One property is set to true and the rest are false, depending on attributes set on the input field and the user’s entry.
badInput: Indicates that the value is invalid for any input type.
patternMismatch: Indicates that the value doesn’t match the specified pattern attribute for email, password, search, tel, text, or url input types.
rangeOverflow: Indicates that the value is greater than the specified max attribute for number, range, date, datetime, or time input types.
rangeUnderflow: Indicates that the value is less than the specified min attribute for number, range, date, datetime, or time input types.
stepMismatch: Indicates that the value doesn’t match the specified step attribute for number or range input types.
tooLong: Indicates that the value exceeds the specified maxlength attribute for email, password, search, tel, text, or url input types.
tooShort: Indicates that the value is less than the specified minlength attribute for email, password, search, tel, text, or url input types.
typeMismatch: Indicates that the value doesn’t match the required syntax for email or url input types.
valueMissing: Indicates that an empty value is provided when required attribute is set for any input type.
valid: True if none of the preceding properties are true.
Error Messages
When an input validation fails, a default message is displayed. You can provide your own values for the error messages to override the default messages. Specify your message using an attribute that corresponds to the validity error that’s returned, as shown in the following table.
Validity Error
Default Message
Attribute to Override Default
badInput
Enter a valid value.
message-when-bad-input
Your entry does not match the allowed format [locale's format]. (for types date, datetime, and time)
badNumericInput
Enter a valid numeric value.
message-when-bad-input
patternMismatch
Your entry does not match the allowed pattern.
message-when-pattern-mismatch
rangeOverflow
The number is too high.
message-when-range-overflow
Value must be [max] or earlier. (for types date, datetime, and time)
rangeUnderflow
The number is too low.
message-when-range-underflow
Value must be [min] or later. (for types date, datetime, and time)
stepMismatch
Your entry isn’t a valid increment.
message-when-step-mismatch
tooLong
Your entry is too long.
message-when-too-long
tooShort
Your entry is too short.
message-when-too-short
typeMismatch
You have entered an invalid format.
message-when-type-mismatch
valueMissing
Complete this field.
message-when-value-missing
Complete this field with format [locale's format]. (for types date, datetime, and time)
Some validity errors for date, datetime, and time fields display a default message that varies by locale. For more information, see Date Picker, Datetime Picker, and Time Picker
Note
To override the default error message, use the corresponding attribute. For example, you have a text input with a minimum length of 5. If users enter fewer than five characters,
the validity error returned is tooShort and the default message is “Your entry is too short.” Use the message-when-too-short attribute to display a different error message.
1<template>2 <lightning-input3 label="First Name"4 minlength="5"5 message-when-too-short="Your entry must be at least 5 characters."6 >7 </lightning-input>8</template>
Custom errors that override the default error message are appended with the string “(Use format [format])” where [format] is the date format that’s determined by the user locale. For example, if your component sets badInput="This is a custom error", the displayed error for a date field in en-US locale is “This is a custom error (Use format Dec 31, 2024)”.
This example shows how to display a custom error message with
setCustomValidity() and reportValidity(). The component is a simple text
input with a button.
The register() function compares the input entered by the user to a
particular text string. If true, setCustomValidity() sets the custom error
message. The error message is displayed immediately using reportValidity().
Note that when the comparison isn’t true, you should set the error message to
an empty string to zero out any messages that might have been set on previous
calls.
1import{LightningElement}from "lwc";2export default class MyComponent extends LightningElement{3 register(event){4 var inputCmp = this.template.querySelector(".inputCmp");5 var value = inputCmp.value;6 // is input valid text?7 if(value === "John Doe"){8 inputCmp.setCustomValidity("John Doe is already registered");9}else{10 inputCmp.setCustomValidity(""); // if there was a custom error before, reset it11}12 inputCmp.reportValidity(); // Tells lightning-input to show the error right away without needing interaction13}14}
Use Autocomplete in Input Fields
Some input types can be autofilled, based on your browser’s support of the feature.
The autocomplete attribute passes through its value to the browser.
These lightning-input types support the autocomplete attribute:
email
search
tel
text
url
The values on and off or a space-separated string of expected data types are supported, but the behavior depends on the browser. Some browsers might ignore the passed value.
To provide autocomplete guidance on the expected data type in the field, use a space-separated string that describes the meaning of the autocompletion value. For example autocomplete="shipping street-address". For more information, see the MDN web docs.
Add Field-Level Help and Placeholder Text
To provide a hint for entering information in the field, specify help text with the field-level-help attribute. For example, describe the characters required in a password input. Field-level help adds an info icon next to the input label, with a tooltip displaying your specified help text.
To provide sample input in the field, use the placeholder attribute. For example, in a url input, show a URL in the correct format.
1<template>2 <lightning-input3 label="Event Name"4 placeholder="Grand Opening"5 field-level-help="The event name must 50 characters or less"6 maxlength="50"7 >8 </lightning-input>9</template>
field-level-help isn’t supported for file, toggle, and checkbox-button types.
placeholder is supported for date, email, number, password, search, tel, text, time, and url input types only. The placeholder support for date and time is a Salesforce addition and is not part of the HTML5 standard.
Data Binding
Bind the input value to a property in your component’s JavaScript class. lightning-input uses the onchange event handler to listen a change to its value. For more information, see Data Binding in a Template.
Event Handling
The native HTML <input> element provides two events, input and change. The lightning-input component provides two custom events, change and commit. You can also define an action for input events like blur and focus.
The component’s change event behaves the same as the native input and change events together.
It fires whenever you change the input value, as the <input> element’s input event does.
It also fires when you finish changing the input, as the <input> element’s change event does.
The component’s commit event fires only when you finish changing the input,
which is the same behavior as the HTML <input> element’s change event. Some input types don’t support the commit event.
checkbox
date
datetime
file
time
toggle
The component doesn’t provide an input event because the behavior is provided in the change event.
To summarize, the component’s change event is equivalent to the input and change events of
the <input> element. The component’s commit event is equivalent to the change event of
the <input> element.
The change event fires at different times, depending on the specific input type.
For information about the change event for the <input> element, see
developer.mozilla.org.
See the Custom Events section for more information about the component’s events.
Clear Values and Repeated Input
The commit event isn’t fired if the input value matches the previously
committed value. To ensure that the input value is reliably updated, even when
entering the same value multiple times, use the change event.
Note
This example shows how you can clear the input value using the change event.
When the button is clicked, it calls handleClear() to reset text to an empty string.
If you use the commit event here, the commit event isn’t fired if you try to
clear the input value and it matches the previously committed value. For
example, entering “hello” and clearing the value, and then entering “hello”
again and attempting to clear the value. The second attempt doesn’t clear the
value because the commit event isn’t called. this.text remains an empty string even
though the input value displays “hello”.
1import{LightningElement}from "lwc";23export default class InputChangeExample extends LightningElement{4 text = "";56 handleChange(event){7 this.text = event.target.value;8}910 handleClear(){11 this.text = "";12}13}
Handle Number Input
In general, use oncommit to handle changes to number inputs. Use onchange for use cases where you want to process each character entered right away. For example, use onchange if you want to echo the content entered in another field as it is entered.
For input type number, the component sets the value to ” (an empty string) when the number input becomes invalid. The change event is fired each time the value changes, even when the value is set to an empty string. This enables you to reset the field in your onchange handler when input is invalid. Use separate variables to set the value of the number input and retrieve it.
Set and Read Selection Indexes
The selection-start and selection-end attribute values are passed through to the <input> element. Only the input type text is currently supported. The selection-start value specifies the index of the first character selected in the input element, while the selection-end value specifies the index of the last character selected. Index values start at 0.
This example selects the characters from index 0 to the end when you click the button.
In JavaScript, the selectionEnd property
is set to the length of the current input value.
1import{LightningElement}from "lwc";23export default class DemoInputSelection extends LightningElement{4 textvalue = "initial value";5 handleChange(event){6 this.textvalue = event.detail.value;7}8 handleClick(event){9 let input = this.template.querySelector("lightning-input");10 let end = input.value.length;11 input.selectionStart = 0;12 input.selectionEnd = end;13 // Optionally, focus to highlight the selected characters14 // input.focus();15}16}
Component Styling
Use a combination of variants and utility classes to customize your input fields.
Variants
Use the variant attribute with one of these values to position the labels differently relative to the fields.
standard is the default, which displays the label above the field.
label-hidden hides the label but make it available to assistive technology. If you provide a value for field-level-help, the tooltip icon is still displayed.
label-inline aligns the label and field horizontally.
label-stacked places the label above the field.
In most contexts, a stacked label (standard or label-stacked variant) results in better readability and clarity. Use horizontal labels (label-inline variant) when you want to conserve vertical space and have fewer than 10 fields.
Utility Classes
To apply additional styling, use the SLDS utility classes with the class attribute.
This example creates two fields using lightning-input in a compound row similar to the SLDS form fields.
Component styling hooks provide CSS custom properties that use the --slds-c-* prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the SLDS 1 component blueprints for available component styling hooks.
For a single line of plain text input, use lightning-input. For multiple lines of plain text input, use lightning-textarea instead. For more specific input such as with numbers or email addresses, use the type attribute. Specifying type ensures that built-in validation can be applied to your data input.
To group related fields together, such as individual parts of an address, use compound input components like lightning-input-address or lightning-input-location. For name fields, use lightning-input-name.
The label attribute is required. If you don’t want to display a label,
specify the variant="label-hidden" attribute. See Accessibility for more
information.
When working with forms that interact with Salesforce records, consider using these components instead: lightning-record-form, lightning-record-view-form, and lightning-record-edit-form components provide a form-based UI that’s metadata-driven. The components are automatically wired up to your record data, labels, and field-level help text. For more information, see Work with Records Using Base Components. Alternatively, to create your own custom UI to work with Salesforce records, use lightning-input with the lightning/ui*Api wire adapters and functions, such as getRecord and updateRecord. For more information, see Use the Wire Service with Base Components.
maxlength limits the number of characters you can enter. The
message-when-too-long error message isn’t triggered because you can’t type more
than the number of characters allowed. However, you can use the
message-when-pattern-mismatch and pattern attributes to
trigger a message on blur when too many characters are entered.
1<template>2 <lightning-input3 type="text"4 message-when-pattern-mismatch="Too many characters"5 pattern=".{0,5}"6 label="Enter up to 5 characters"7 >8 </lightning-input>9</template>
You can use custom labels that display translated values on input fields. For more information,
see Access Labels.
Accessibility
You must provide a text label for accessibility to make the information
available to assistive technology. The label attribute creates an HTML
<label> element for your input component. To hide a label from view and make
it available to assistive technology, use the label-hidden variant.
Specify the aria-labelledby attribute and variant="label-hidden" to
provide a custom label for assistive devices. Although the label attribute is
still required, the <label> element is not rendered in this case.
lightning-input sets the aria-invalid attribute to match the validity state of the input field for assistive technology. If the validity attribute returns a true value for the valid property, then aria-invalid is false. If the validity attribute returns a true value for any property other than valid, then aria-invalid is true. When the component is initially loaded, aria-invalid is set to false. This prevents fields that are marked required from being announced as invalid before you enter anything.
When a field-level error is displayed, lightning-input links the input field to the error message using the aria-describedby attribute, which enables assistive technology to announce the error message on the input field.
For the datetime type, the component renders two separate fields for date and time input. To provide accessibility features to the date field, use the date-aria-* attributes. For example, use date-aria-described-by to provide a descriptive label for the date field. To provide accessibility features to the time field, use the time-aria-* attributes. For example, use time-aria-described-by to provide a descriptive label for the time field.
Use the autocomplete attribute to make it easier for a browser to prefill values in forms. For example, specify autocomplete="given-name" on lightning-input to expect the field value to be the user’s first name. The field displays a list of options that anticipates what a user is typing. The user presses the Down arrow key to select an option and press Enter. For more information, see WCAG 2.2: Using autocomplete attributes.
The autocomplete attribute is helpful for fields that specifically ask for data about the user who’s completing the form. Don’t use the autocomplete attribute on a field that asks for data about other people. The list of suggested values can come from past values entered by the user or they can be pre-configured on the user’s browser.
Custom Events
change
The event fired when a value is changed in the input field.
The change event returns one of the following event.target parameters, depending on input type.
Parameter
Type
Description
value
string
Returns the input value.
The event properties are as follows.
Property
Value
Description
bubbles
true
This event bubbles up through the DOM.
cancelable
false
This event has no default behavior that can be canceled. You can’t call preventDefault() on this event.
composed
true
This event propagates outside of the component in which it was dispatched.
commit
The event fired when you press Enter after interacting with the input, or move away from the input so it loses focus. For the input type search, the event is fired when focus leaves the entire component or when the user clicks the X button to clear the search. The event is also fired when you press the Enter key. For the input type number the event is also fired when you press Up/Down arrow keys to change the number.
The commit event doesn’t return any parameters.
The event properties are as follows.
Property
Value
Description
bubbles
false
This event does not bubble.
cancelable
false
This event has no default behavior that can be canceled. You can’t call preventDefault() on this event.
composed
false
This event does not propagate outside of the component in which it was dispatched.
Specifies the types of files that the server accepts. Use this attribute with file input type only.
string
access-key
Specifies a shortcut key to activate or focus an element.
string
aria-active-descendant-element
The active descendant element reference for aria-activedescendant. When set, the element is passed to AriaObserver as relatedNodes so the attribute and reflection can be applied without cross-root ID lookup. Set to null to clear. Only used when enableMobileGroupedCbAriaUpdates is true.
HTMLElement | null
aria-auto-complete
Specifies the value of the aria-autocomplete, only valid on type simple
string
aria-controls
A space-separated list of element IDs whose presence or content is controlled by the input.
string
aria-described-by
A space-separated list of element IDs that provide descriptive labels for the input.
string
aria-details
A space-separated list of IDs of elements that provide details for the input.
string
aria-disabled
Specifies the value of the aria-disabled attribute
boolean
aria-error-message
A space-separated list of element IDs that provide descriptive error message for input.
aria-expanded
Specifies the value of the aria-expanded attribute, only valid on type simple
string
aria-has-popup
Specifies the value of the aria-haspopup attribute
aria-invalid
A Boolean value for aria-invalid.
boolean
aria-key-shortcuts
Specifies the value of the aria-keyshortcuts attribute
string
aria-label
Describes the input to assistive technologies.
string
aria-labelled-by
A space-separated list of element IDs that provide labels for the input.
string
aria-role-description
Specifies the value of the aria-roledescription attribute
string
autocomplete
Controls auto-filling of the field. Use this attribute with email, search, tel, text, and url input types only. Set the attribute to pass through autocomplete values to be interpreted by the browser.
string
checked
If present, the checkbox is selected.
boolean
false
date-access-key
Sets a key that can be used to access the date picker when you use the datetime type.
string
date-aria-controls
A space-separated list of element IDs whose presence or content is controlled by the date input when type='datetime'. On mobile devices, this is merged with aria-controls and time-aria-controls to describe the native date time input.
string
date-aria-described-by
A space-separated list of element IDs that provide descriptive labels for the date input when type='datetime'. On mobile devices, this is merged with aria-described-by and time-aria-described-by to describe the native date time input.
string
date-aria-details
A space-separated list of IDs of elements that provide details of the date input when type='datetime'.
string
date-aria-error-message
A space-separated list of element IDs that provide error messages for the date input when type='datetime'.
string
date-aria-label
Describes the date input to assistive technologies when type='datetime'. On mobile devices, this label is merged with aria-label and time-aria-label to describe the native date time input.
string
date-aria-labelled-by
A space-separated list of element IDs that provide labels for the date input when type='datetime'. On mobile devices, this is merged with aria-labelled-by and time-aria-labelled-by to describe the native date time input.
string
date-style
The display style of the date when type='date' or type='datetime'. Valid values are short, medium (default), and long. The format of each style is specific to the locale. On mobile devices this attribute has no effect.
string
medium
disabled
If present, the input field is disabled and users cannot interact with it.
boolean
false
field-level-help
Help text detailing the purpose and function of the input. This attribute isn't supported for file, toggle, and checkbox-button types.
string
files
A FileList that contains selected files. Use this attribute with the file input type only. When setting the files property, the value must be a FileList, an array of File objects, or a single File object.
object
format-fraction-digits
Reserved for internal use.
number
formatter
String value with the formatter to be used for number input. Valid values include decimal, percent, percent-fixed, and currency.
string
indeterminate
If present, the checkbox is displayed with an indeterminate state, showing a dash indicator instead of a checkmark or empty box. This is commonly used for "select all" checkboxes when only some items in a group are selected. Supported for type="checkbox" only. Clicking the checkbox clears the indeterminate state.
boolean
false
inputmode
Controls the virtual keyboard type on mobile devices. This property should ideally be named `inputMode` (camelCase) to follow JavaScript naming conventions, since it corresponds to the HTML `inputmode` attribute. In the HTML standard: The content attribute is `inputmode` (lowercase) The IDL (JavaScript) attribute is `inputMode` (camelCase) However, LWC currently doesn't support this dual naming pattern, forcing us to use the lowercase version for both the API property name and the internal implementation. This creates an inconsistency with standard DOM APIs.
is-loading
For the search type only. If present, a spinner is displayed to indicate that data is loading.
boolean
false
label
Text label for the input.
string
max
The maximum acceptable value for the input. Use this attribute with number, range, date, time, and datetime input types only. For number and range type, the max value is a decimal number. For the date, time, and datetime types, the max value must use a valid string for the type.
decimal|string
max-length
The maximum number of characters allowed in the field. Use this attribute with email, password, search, tel, text, and url input types only.
number
message-toggle-active
Text shown for the active state of a toggle. The default is "Active".
string
message-toggle-inactive
Text shown for the inactive state of a toggle. The default is "Inactive".
string
message-when-bad-input
Error message to be displayed when a bad input is detected. The badInput error can be returned for invalid input for any input type.
string
message-when-pattern-mismatch
Error message to be displayed when a pattern mismatch is detected. The patternMismatch error can be returned when you specify a pattern for email, password, search, tel, text, or url input types.
string
message-when-range-overflow
Error message to be displayed when a range overflow is detected. The rangeOverflow error can be returned when you specify a max value for number or range input types.
string
message-when-range-underflow
Error message to be displayed when a range underflow is detected. The rangeUnderflow error can be returned when you specify a min value for number or range input types.
string
message-when-step-mismatch
Error message to be displayed when a step mismatch is detected. The stepMismatch error can be returned when you specify a step value for number and range input types.
string
message-when-too-long
Error message to be displayed when the value is too long. The tooLong error can be returned when you specify a max-length value for email, password, search, tel, text, and url input types.
string
message-when-too-short
Error message to be displayed when the value is too short. The tooShort error can be returned when you specify a min-length value for email, password, search, tel, text, and url input types.
string
message-when-type-mismatch
Error message to be displayed when a type mismatch is detected. The typeMismatch error can be returned for the email and url input types.
string
message-when-value-missing
Error message to be displayed when the value is missing. The valueMissing error can be returned when you specify the required attribute for any input type.
string
min
The minimum acceptable value for the input. Use this attribute with number, range, date, time, and datetime input types only. For number and range types, the min value is a decimal number. For the date, time, and datetime types, the min value must use a valid string for the type.
decimal|string
min-length
The minimum number of characters allowed in the field. Use this attribute with email, password, search, tel, text, and url input types only.
number
multiple
Specifies that a user can enter more than one value. Use this attribute with file and email input types only.
boolean
false
name
Specifies the name of an input element.
string
pattern
Specifies the regular expression that the input's value is checked against. This attribute is supported for email, password, search, tel, text, and url types.
string
placeholder
Text that is displayed when the field is empty, to prompt the user for a valid entry. Use this attribute with date, email, number, password, search, tel, text, time, and url input types only.
string
read-only
If present, the input field is read-only and cannot be edited by users.
boolean
false
required
If present, the input field must be filled out before the form is submitted.
boolean
false
role
The role set on lightning-primitive-input-simple to allow external developers to have a type="text" and role="combobox" if lightning-combobox does not meet their requirements.
string
selection-end
Specifies the index of the last character to select in the input element. This attribute is supported only for text type. Use with selection-start to programmatically set or read the position of selected text.
selection-start
Specifies the index of the first character to select in the input element. This attribute is supported only for text type. Use with selection-end to programmatically set or read the position of selected text.
step
Granularity of the value, specified as a positive floating point number. Use this attribute with number and range input types only. Use 'any' when granularity is not a concern. This value defaults to 1.
decimal|string
1
time-access-key
Sets a key that can be used to access the time picker when you use the datetime type.
string
time-aria-controls
A space-separated list of element IDs whose presence or content is controlled by the time input when type='datetime'. On mobile devices, this is merged with aria-controls and date-aria-controls to describe the native date time input.
string
time-aria-described-by
A space-separated list of element IDs that provide descriptive labels for the time input when type='datetime'. On mobile devices, this is merged with aria-described-by and date-aria-described-by to describe the native date time input.
string
time-aria-details
A space-separated list of IDs of elements that provide details of the date input when type='datetime'.
string
time-aria-error-message
A space-separated list of element IDs that provide error messages for the time input when type='datetime'.
string
time-aria-label
Describes the time input to assistive technologies when type='datetime'. On mobile devices, this label is merged with aria-label and date-aria-label to describe the native date time input.
string
time-aria-labelled-by
A space-separated list of element IDs that provide labels for the time input when type='datetime'. On mobile devices, this is merged with aria-labelled-by and date-aria-labelled-by to describe the native date time input.
string
time-step-minutes
Specifies the time interval in minutes for the dropdown options. Any positive integer above or equal to 5 is valid. The default is 15 minutes.
number
15
time-style
The display style of the time when type='time' or type='datetime'. Valid values are short (default), medium, and long. Currently, medium and long styles look the same. On mobile devices this attribute has no effect.
string
short
timezone
Specifies the time zone used when type='datetime' only. This value defaults to the user's Salesforce time zone setting.
string
type
The type of the input. Valid values are checkbox, checkbox-button, color, date, datetime, time, email, file, password, range, search, tel, url, number, and toggle. This value defaults to text.
string
text
validity
Represents the validity states that an element can be in, with respect to constraint validation.
object
value
Specifies the value of an input element.
object
variant
The variant changes the appearance of an input field. Accepted variants include standard, label-inline, label-hidden, and label-stacked. This value defaults to standard, which displays the label above the field. Use label-hidden to hide the label but make it available to assistive technology. Use label-inline to horizontally align the label and input field. Use label-stacked to place the label above the input field.
string
standard
Methods
Name
Description
Argument Name
Argument Type
Argument Description
blur
Removes keyboard focus from the input element.
checkValidity
Checks if the input is valid.
focus
Sets focus on the input element.
reportValidity
Displays the error messages and returns false if the input is invalid. If the input is valid, reportValidity() clears displayed error messages and returns true.
setCustomValidity
Sets a custom error message to be displayed when a form is submitted.
message
string
The string that describes the error. If message is an empty string, the error message is reset.
showHelpMessageIfInvalid
Displays error messages on invalid fields. An invalid field fails at least one constraint validation and returns false when checkValidity() is called.