logoAnt Design

⌘ K
  • Design
  • Development
  • Components
  • Blog
  • Resources
6.0.0-alpha.3
  • Components Overview
  • Changelog
    v6.0.0-alpha.3
  • General
    • Button
    • FloatButton
      5.0.0
    • Icon
    • Typography
  • Layout
    • Divider
    • Flex
      5.10.0
    • Grid
    • Layout
    • Masonry
      6.0.0
    • Space
    • Splitter
      5.21.0
  • Navigation
    • Anchor
    • Breadcrumb
    • Dropdown
    • Menu
    • Pagination
    • Steps
    • Tabs
  • Data Entry
    • AutoComplete
    • Cascader
    • Checkbox
    • ColorPicker
      5.5.0
    • 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
      5.1.0
    • Segmented
    • Statistic
    • Table
    • Tag
    • Timeline
    • Tooltip
    • Tour
      5.0.0
    • Tree
  • Feedback
    • Alert
    • Drawer
    • Message
    • Modal
    • Notification
    • Popconfirm
    • Progress
    • Result
    • Skeleton
    • Spin
    • Watermark
      5.1.0
  • Other
    • Affix
    • App
      5.1.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 lose 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 page
contributors
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
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

PropertyDescriptionTypeDefaultVersion
addonAfterThe label text displayed after (on the right side of) the input field, please use Space.Compat insteadReactNode-
addonBeforeThe label text displayed before (on the left side of) the input field, please use Space.Compat insteadReactNode-
allowClearIf allow to remove input content with clear iconboolean | { clearIcon: ReactNode }false
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>-
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>-
sizeThe size of the input box. Note: in the context of a form, the middle size is usedlarge | middle | 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.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:

PropertyDescriptionTypeDefaultVersion
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>-
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties>-

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

Input.Search

PropertyDescriptionTypeDefaultVersion
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string>-
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>-

Supports all props of Input.

Input.Password

PropertyDescriptionTypeDefaultVersion
classNamesSemantic DOM classRecord<SemanticDOM, string>-
iconRenderCustom toggle button(visible) => ReactNode(visible) => (visible ? <EyeOutlined /> : <EyeInvisibleOutlined />)4.3.0
stylesSemantic DOM styleRecord<SemanticDOM, CSSProperties>-
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.

PropertyDescriptionTypeDefaultVersion
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string>-
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>-
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 | middle | largemiddle
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
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?

FAQ

Why Input lose 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), default (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
  • 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
  • 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
  • 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
  • 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