logoAnt Design

⌘ K
  • Design
  • Development
  • Components
  • Blog
  • Resources
YouMindTRACTIANLobeHubCodeRabbit
6.5.0
  • Components Overview
  • Changelog
    v6.5.0
  • General
    • Button
    • FloatButton
    • Icon
    • Typography
  • Layout
    • Divider
    • Flex
    • Grid
    • Layout
    • Masonry
      6.0.0
    • Space
    • Splitter
  • Navigation
    • Anchor
    • Breadcrumb
    • Dropdown
    • Menu
    • Pagination
    • Steps
    • Tabs
  • Data Entry
    • AutoComplete
    • Cascader
    • Checkbox
    • ColorPicker
    • DatePicker
    • Form
    • Input
    • InputNumber
    • Mentions
    • Radio
    • Rate
    • Select
    • Slider
    • Switch
    • TimePicker
    • Transfer
    • TreeSelect
    • Upload
  • Data Display
    • Avatar
    • Badge
    • Calendar
    • Card
    • Carousel
    • Collapse
    • Descriptions
    • Empty
    • Image
    • List
      DEPRECATED
    • Popover
    • QRCode
    • Segmented
    • Statistic
    • Table
    • Tag
    • Timeline
    • Tooltip
    • Tour
    • Tree
  • Feedback
    • Alert
    • Drawer
    • Message
    • Modal
    • Notification
    • Popconfirm
    • Progress
    • Result
    • Skeleton
    • Spin
    • Watermark
  • Other
    • Affix
    • App
    • BorderBeam
      6.4.0
    • ConfigProvider
    • Util
When To Use
Examples
Basic usage
Three sizes of Input
Variants
Compact Style
Search box
Search box with loading
TextArea
Autosizing the height to fit the content
OTP
Format Tooltip Input
prefix and suffix
Password box
With clear icon
With character counting
Custom count logic
Status
Focus
Custom semantic dom styling
API
Input
Input.TextArea
Input.Search
Input.Password
Input.OTP
Semantic DOM
Input
Input.TextArea
Input.Search
Input.Password
Input.OTP
Design Token
FAQ
Why Input loses focus when change prefix/suffix/showCount
Why TextArea in control can make value exceed maxLength?

Input

Through mouse or keyboard input content, it is the most basic form field wrapper.
Importimport { Input } from 'antd';
GitHub
components/inputIssueOpen issues
Docs
Edit this pageLLMs.md
FormInputNumber

Resources

Ant Design X
Ant Design Charts
Ant Design Pro
Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Web3
Ant Design Landing-Landing Templates
Scaffolds-Scaffold Market
Umi-React Application Framework
dumi-Component doc generator
qiankun-Micro-Frontends Framework
Ant Motion-Motion Solution
China Mirror 🇨🇳

Community

Awesome Ant Design
Medium
X
yuque logoAnt Design in YuQue
Ant Design in Zhihu
Experience Cloud Blog
seeconf logoSEE Conf-Experience Tech Conference

Help

GitHub
Change Log
FAQ
For Agents
Bug Report
Issues
Discussions
StackOverflow
SegmentFault

Ant XTech logoMore Products

yuque logoYuQue-Document Collaboration Platform
AntV logoAntV-Data Visualization
Egg logoEgg-Enterprise Node.js Framework
Kitchen logoKitchen-Sketch Toolkit
Galacean logoGalacean-Interactive Graphics Solution
WeaveFox logoWeaveFox-AI Development with WeaveFox 🦊
xtech logoAnt Financial Experience Tech
Theme Editor
Made with ❤ by
Ant Group and Ant Design Community
loading

When To Use

  • A user input in a form field is needed.
  • A search input is required.

Examples

API

Common props ref:Common props

Input

PropertyDescriptionTypeDefaultVersionGlobal Config
addonAfterThe label text displayed after (on the right side of) the input field, please use Space.Compact insteadReactNode-×
addonBeforeThe label text displayed before (on the left side of) the input field, please use Space.Compact insteadReactNode-×
allowClearWhether to show a clear icon to remove input contentboolean | { clearIcon: ReactNode, disabled?: boolean }-disabled: 6.4.05.15.0
borderedWhether has border style, please use variant insteadbooleantrue4.5.0×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-5.4.05.7.0
countCharacter count configCountConfig-5.10.0×
defaultValueThe initial input contentstring-×
disabledWhether the input is disabledbooleanfalse-×
idThe ID for inputstring-×
maxLengthThe maximum number of characters in Inputnumber-×
prefixThe prefix icon for the InputReactNode-×
showCountWhether to show character countboolean | { formatter: (info: { value: string, count: number, maxLength?: number }) => ReactNode }false4.18.0 info.value: 4.23.0×
statusSet validation status'error' | 'warning'-4.19.0×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-5.4.05.7.0
sizeThe size of the input box. Note: in the context of a form, the medium size is usedlarge | medium | small-×
suffixThe suffix icon for the InputReactNode-×
typeThe type of input, see: MDN( use Input.TextArea instead of type="textarea")stringtext×
valueThe input content valuestring-×
variantVariants of Inputoutlined | borderless | filled | underlinedoutlined5.13.0 | underlined: 5.24.05.19.0
onChangeCallback when user inputfunction(e)-×
onPressEnterThe callback function that is triggered when Enter key is pressedfunction(e)-×
onClearCallback when click the clear button() => void-5.20.0×

When Input is used in a Form.Item context, if the Form.Item has the id props defined then value, defaultValue, and id props of Input are automatically set.

The rest of the props of Input are exactly the same as the original input.

CountConfig

tsx
interface CountConfig {
// Max character count. Different from the native `maxLength`, it will be marked warning but not truncated
max?: number;
// Custom character count, for example, the standard emoji length is greater than 1, you can customize the counting strategy to change it to 1
strategy?: (value: string) => number;
// Same as `showCount`
show?: boolean | ((args: { value: string; count: number; maxLength?: number }) => ReactNode);
// Custom clipping logic when the number of characters exceeds `count.max`, no clipping when not configured
exceedFormatter?: (value: string, config: { max: number }) => string;
}

Input.TextArea

Same as Input, and more:

PropertyDescriptionTypeDefaultVersionGlobal Config
autoSizeHeight auto size feature, can be set to true | false or an object { minRows: 2, maxRows: 6 }boolean | objectfalse×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string>-5.4.05.15.0
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties>-5.4.05.15.0

The rest of the props of Input.TextArea are the same as the original textarea.

Input.Search

PropertyDescriptionTypeDefaultVersionGlobal Config
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string>-6.0.06.0.0
enterButtonfalse displays the default button color, true uses the primary color, or you can provide a custom button. Conflicts with addonAfter.ReactNodefalse×
loadingSearch box with loadingbooleanfalse×
onSearchThe callback function triggered when you click on the search-icon, the clear-icon or press the Enter keyfunction(value, event, { source: "input" | "clear" })-×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties>-6.0.06.0.0
searchIconCustomize the search iconReactNode-6.4.06.4.0

Supports all props of Input.

Input.Password

PropertyDescriptionTypeDefaultVersionGlobal Config
classNamesSemantic DOM classRecord<SemanticDOM, string>-5.4.06.4.0
iconRenderCustom toggle button(visible) => ReactNode(visible) => (visible ? <EyeOutlined /> : <EyeInvisibleOutlined />)4.3.06.4.0
stylesSemantic DOM styleRecord<SemanticDOM, CSSProperties>-5.4.06.4.0
visibilityToggleWhether show toggle button or control password visibleboolean | VisibilityToggletrue×

Input.OTP

Added in 5.16.0.

Notes for developers

When the mask prop is string, we recommend receiving a single character or a single emoji. If multiple characters or multiple emoji are passed, a warning will be thrown.

PropertyDescriptionTypeDefaultVersionGlobal Config
autoCompleteThe autocomplete attribute for input elements, e.g. one-time-code for OTP autofillstring-6.3.0×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string>-6.0.06.0.0
defaultValueDefault valuestring-×
disabledWhether the input is disabledbooleanfalse×
formatterFormat display, blank fields will be filled with (value: string) => string-×
separatorrender the separator after the input box of the specified indexReactNode |((i: number) => ReactNode)-5.24.0×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties>-6.0.06.0.0
maskCustom display, the original value will not be modifiedboolean | stringfalse5.17.0×
lengthThe number of input elementsnumber6×
statusSet validation status'error' | 'warning'-×
sizeThe size of the input boxsmall | medium | largemedium×
variantVariants of Inputoutlined | borderless | filled | underlinedoutlinedunderlined: 5.24.0×
valueThe input content valuestring-×
onChangeTrigger when all the fields are filled(value: string) => void-×
onInputTrigger when the input value changes(value: string[]) => void-5.22.0×

VisibilityToggle

PropertyDescriptionTypeDefaultVersion
tabIndexSet the tabIndex of the toggle buttonnumber06.5.0
visibleWhether the password is show or hidebooleanfalse4.24.0
onVisibleChangeCallback executed when visibility of the password is changed(visible) => void-4.24.0

Input Methods

NameDescriptionParametersVersion
blurRemove focus-
focusGet focus(option?: { preventScroll?: boolean, cursor?: 'start' | 'end' | 'all' })option - 4.10.0

Semantic DOM

Input

Input.TextArea

Input.Search

Input.Password

Input.OTP

Design Token

Component TokenHow to use?
Token NameDescriptionTypeDefault Value
activeBgBackground color when the input box is activatedstring#ffffff
activeBorderColorActive border colorstring#1677ff
activeShadowBox-shadow when activestring0 0 0 2px rgba(5,145,255,0.1)
addonBgBackground color of addonstringrgba(0,0,0,0.02)
errorActiveShadowBox-shadow when active in error statusstring0 0 0 2px rgba(255,38,5,0.06)
hoverBgBackground color when the input box hoversstring#ffffff
hoverBorderColorHover border colorstring#4096ff
inputFontSizeFont sizenumber14
inputFontSizeLGFont size of largenumber16
inputFontSizeSMFont size of smallnumber14
paddingBlockVertical padding of inputnumber4
paddingBlockLGVertical padding of large inputnumber7
paddingBlockSMVertical padding of small inputnumber0
paddingInlineHorizontal padding of inputnumber11
paddingInlineLGHorizontal padding of large inputnumber11
paddingInlineSMHorizontal padding of small inputnumber7
warningActiveShadowBox-shadow when active in warning statusstring0 0 0 2px rgba(255,215,5,0.1)
Global TokenHow to use?
Token NameDescriptionTypeDefault Value
colorBgContainerDisabledControl the background color of container in disabled state.stringrgba(0,0,0,0.04)
colorBorderDefault border color, used to separate different elements, such as: form separator, card separator, etc.string#d9d9d9
colorBorderDisabledControl the border color of the element in the disabled state.string#d9d9d9
colorErrorUsed to represent the visual elements of the operation failure, such as the error Button, error Result component, etc.string#ff4d4f
colorErrorBgThe background color of the error state.string#fff2f0
colorErrorTextThe default state of the text in the error color.string#ff4d4f
colorFillTertiaryThe third level of fill color is used to outline the shape of the element, such as Slider, Segmented, etc. If there is no emphasis requirement, it is recommended to use the third level of fill color as the default fill color.stringrgba(0,0,0,0.04)
colorTextDefault text color which comply with W3C standards, and this color is also the darkest neutral color.stringrgba(0,0,0,0.88)
colorTextDisabledControl the color of text in disabled state.stringrgba(0,0,0,0.25)
colorWarningUsed to represent the warning map token, such as Notification, Alert, etc. Alert or Control component(like Input) will use these map tokens.string#faad14
colorWarningBgThe background color of the warning state.string#fffbe6
colorWarningTextThe default state of the text in the warning color.string#faad14
borderRadiusBorder radius of base componentsnumber6
borderRadiusLGLG size border radius, used in some large border radius components, such as Card, Modal and other components.number8
borderRadiusSMSM size border radius, used in small size components, such as Button, Input, Select and other input components in small sizenumber4
controlHeightLGLG component heightnumber40
controlHeightSMSM component heightnumber24
fontFamilyThe font family of Ant Design prioritizes the default interface font of the system, and provides a set of alternative font libraries that are suitable for screen display to maintain the readability and readability of the font under different platforms and browsers, reflecting the friendly, stable and professional characteristics.string-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'
fontSizeThe most widely used font size in the design system, from which the text gradient will be derived.number14
lineHeightLine height of text.number1.5714285714285714
lineHeightLGLine height of large text.number1.5
lineTypeBorder style of base componentsstringsolid
lineWidthBorder width of base componentsnumber1
motionDurationSlowMotion speed, slow speed. Used for large element animation interaction.string0.3s
paddingXSControl the extra small padding of the element.number8
paddingXXSControl the extra extra small padding of the element.number4

FAQ

Why Input loses focus when change prefix/suffix/showCount

When Input dynamic add or remove prefix/suffix/showCount will make React recreate the dom structure and new input will be not focused. You can set an empty <span /> element to keep the dom structure:

jsx
const suffix = condition ? <Icon type="smile" /> : <span />;
<Input suffix={suffix} />;

Why TextArea in control can make value exceed maxLength?

When in control, component should show as what it set to avoid submit value not align with store value in Form.

Basic usage

Basic usage example.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Variants

Variants of Input, there are four variants: outlined filled borderless and underlined.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
5.13.0
Search box

Example of creating a search box by grouping a standard input with a search button.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
TextArea

For multi-line input.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
OTP

One time password input.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
5.16.0
prefix and suffix

Add a prefix or suffix icons inside input. Note: The suffix prop for Input.Password is supported starting from version 5.27.0.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
With clear icon

Input box with the remove icon, click the icon to delete everything.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Custom count logic

It is necessary to customize the counting ability in some scenarios (such as emoji length is counted as 1), which can be achieved through the count attribute. Use count.max attribute exceeds the limit of the native maxLength.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
>= 5.10.0
Focus

Focus with additional option.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Three sizes of Input

There are three sizes of an Input box: large (40px), medium (32px) and small (24px).

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Compact Style

Use Space.Compact create compact style, See the Space.Compact documentation for more.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Search box with loading

Search loading when onSearch.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Autosizing the height to fit the content

autoSize prop for a textarea type of Input makes the height to automatically adjust based on the content. An option object can be provided to autoSize to specify the minimum and maximum number of lines the textarea will automatically adjust.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Format Tooltip Input

You can use the Input in conjunction with Tooltip component to create a Numeric Input, which can provide a good experience for extra-long content display.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Password box

Input type of password.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
With character counting

Show character counting.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Status

Add status to Input with status, which could be error or warning.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
Custom semantic dom styling

You can customize the semantic dom style of Input by passing objects/functions through classNames and styles.

CodeSandbox Icon
Hitu Icon
codepen icon
External Link Icon
Expand Icon
6.0.0
https://


With formatter (Upcase)
With Disabled
With Length (8)
With variant
With custom display character
With custom ReactNode separator
/////
With custom function separator
—————


¥RMB

¥RMB



Exceed Max
12 / 10
Emoji count as length 1
3
Not exceed max
6 / 6

https://
Zhejiang




0 / 200 / 1000 / 100
8
*****
17
  • root
    Root element with relative positioning, inline-block display, width, min-width, padding, colors, fonts, line-height, border-radius, transitions and other input container basic styles
  • prefix
    Prefix wrapper element with layout and styling for prefix content
  • input
    Input element with core interactive styles and text input related styling
  • suffix
    Suffix wrapper element with layout and styling for suffix content
  • clear
    6.4.0
    Clear button element with layout, visibility, and interaction styles for clearing content
  • count
    Character count element with font and color styles for count display
17 / 100
  • root
    Root element with textarea wrapper styles, border, border radius, transition animation and state control
  • textarea
    Textarea element with font, line height, padding, color, background, border, text input and multi-line text display styles
  • clear
    6.4.0
    Clear button element with layout, visibility, and interaction styles for clearing content
  • count
    Count element with character count display position, font, color and numeric statistics styles
17
  • root
    root element
  • prefix
    prefix element
  • input
    input element
  • suffix
    suffix element
  • clear
    6.4.0
    clear button element
  • count
    count element
  • button.root
    button root element
  • button.icon
    button icon element
  • button.content
    button content element
17
  • root
    root element
  • prefix
    prefix element
  • input
    input element
  • suffix
    suffix element
  • clear
    6.4.0
    clear button element
  • count
    count element
-----
  • root
    Root element, set inline flex layout, alignment, column gap and wrapper styles
  • input
    Input element, set text center, padding and number input styles
  • separator
    Separator element, set separator display styles between OTP input boxes