Common Props 🚧
Props¶
These special React props are supported for all built-in components:
-
children
: A React node (an element, a string, a number, a portal, an empty node likenull
,undefined
and booleans, or an array of other React nodes). Specifies the content inside the component. When you use JSX, you will usually specify thechildren
prop implicitly by nesting tags like<div><span /></div>
. -
dangerouslySetInnerHTML
: An object of the form{ __html: '<p>some html</p>' }
with a raw HTML string inside. Overrides theinnerHTML
property of the DOM node and displays the passed HTML inside. This should be used with extreme caution! If the HTML inside isn't trusted (for example, if it's based on user data), you risk introducing an XSS vulnerability. Read more about usingdangerouslySetInnerHTML
. -
ref
: A ref object fromuseRef
orcreateRef
, or aref
callback function, or a string for legacy refs. Your ref will be filled with the DOM element for this node. Read more about manipulating the DOM with refs. -
suppressContentEditableWarning
: A boolean. Iftrue
, suppresses the warning that React shows for elements that both havechildren
andcontentEditable={true}
(which normally do not work together). Use this if you're building a text input library that manages thecontentEditable
content manually. -
suppressHydrationWarning
: A boolean. If you use server rendering, normally there is a warning when the server and the client render different content. In some rare cases (like timestamps), it is very hard or impossible to guarantee an exact match. If you setsuppressHydrationWarning
totrue
, React will not warn you about mismatches in the attributes and the content of that element. It only works one level deep, and is intended to be used as an escape hatch. Don't overuse it. Read about suppressing hydration errors. -
style
: An object with CSS styles, for example{ fontWeight: 'bold', margin: 20 }
. Similarly to the DOMstyle
property, the CSS property names need to be written ascamelCase
, for examplefontWeight
instead offont-weight
. You can pass strings or numbers as values. If you pass a number, likewidth: 100
, React will automatically appendpx
("pixels") to the value unless it's a unitless property. We recommend usingstyle
only for dynamic styles where you don't know the style values ahead of time. In other cases, applying plain CSS classes withclassName
is more efficient. Read more aboutclassName
andstyle
.
These standard DOM props are also supported for all built-in components:
accessKey
: A string. Specifies a keyboard shortcut for the element. Not generally recommended.aria-*
: ARIA attributes let you specify the accessibility tree information for this element. See ARIA attributes for a complete reference. In React, all ARIA attribute names are exactly the same as in HTML.autoCapitalize
: A string. Specifies whether and how the user input should be capitalized.className
: A string. Specifies the element's CSS class name. Read more about applying CSS styles.contentEditable
: A boolean. Iftrue
, the browser lets the user edit the rendered element directly. This is used to implement rich text input libraries like Lexical. React warns if you try to pass React children to an element withcontentEditable={true}
because React will not be able to update its content after user edits.data-*
: Data attributes let you attach some string data to the element, for exampledata-fruit="banana"
. In React, they are not commonly used because you would usually read data from props or state instead.dir
: Either'ltr'
or'rtl'
. Specifies the text direction of the element.draggable
: A boolean. Specifies whether the element is draggable. Part of HTML Drag and Drop API.enterKeyHint
: A string. Specifies which action to present for the enter key on virtual keyboards.htmlFor
: A string. For<label>
and<output>
, lets you associate the label with some control. Same asfor
HTML attribute. React uses the standard DOM property names (htmlFor
) instead of HTML attribute names.hidden
: A boolean or a string. Specifies whether the element should be hidden.id
: A string. Specifies a unique identifier for this element, which can be used to find it later or connect it with other elements. Generate it withuseId
to avoid clashes between multiple instances of the same component.is
: A string. If specified, the component will behave like a custom element.inputMode
: A string. Specifies what kind of keyboard to display (for example, text, number or telephone).itemProp
: A string. Specifies which property the element represents for structured data crawlers.lang
: A string. Specifies the language of the element.onAnimationEnd
: AnAnimationEvent
handler function. Fires when a CSS animation completes.onAnimationEndCapture
: A version ofonAnimationEnd
that fires in the capture phase.onAnimationIteration
: AnAnimationEvent
handler function. Fires when an iteration of a CSS animation ends, and another one begins.onAnimationIterationCapture
: A version ofonAnimationIteration
that fires in the capture phase.onAnimationStart
: AnAnimationEvent
handler function. Fires when a CSS animation starts.onAnimationStartCapture
:onAnimationStart
, but fires in the capture phase.onAuxClick
: AMouseEvent
handler function. Fires when a non-primary pointer button was clicked.onAuxClickCapture
: A version ofonAuxClick
that fires in the capture phase.onBeforeInput
: AnInputEvent
handler function. Fires before the value of an editable element is modified. React does not yet use the nativebeforeinput
event, and instead attempts to polyfill it using other events.onBeforeInputCapture
: A version ofonBeforeInput
that fires in the capture phase.onBlur
: AFocusEvent
handler function. Fires when an element lost focus. Unlike the built-in browserblur
event, in React theonBlur
event bubbles.onBlurCapture
: A version ofonBlur
that fires in the capture phase.onClick
: AMouseEvent
handler function. Fires when the primary button was clicked on the pointing device.onClickCapture
: A version ofonClick
that fires in the capture phase.onCompositionStart
: ACompositionEvent
handler function. Fires when an input method editor starts a new composition session.onCompositionStartCapture
: A version ofonCompositionStart
that fires in the capture phase.onCompositionEnd
: ACompositionEvent
handler function. Fires when an input method editor completes or cancels a composition session.onCompositionEndCapture
: A version ofonCompositionEnd
that fires in the capture phase.onCompositionUpdate
: ACompositionEvent
handler function. Fires when an input method editor receives a new character.onCompositionUpdateCapture
: A version ofonCompositionUpdate
that fires in the capture phase.onContextMenu
: AMouseEvent
handler function. Fires when the user tries to open a context menu.onContextMenuCapture
: A version ofonContextMenu
that fires in the capture phase.onCopy
: AClipboardEvent
handler function. Fires when the user tries to copy something into the clipboard.onCopyCapture
: A version ofonCopy
that fires in the capture phase.onCut
: AClipboardEvent
handler function. Fires when the user tries to cut something into the clipboard.onCutCapture
: A version ofonCut
that fires in the capture phase.onDoubleClick
: AMouseEvent
handler function. Fires when the user clicks twice. Corresponds to the browserdblclick
event.onDoubleClickCapture
: A version ofonDoubleClick
that fires in the capture phase.onDrag
: ADragEvent
handler function. Fires while the user is dragging something.onDragCapture
: A version ofonDrag
that fires in the capture phase.onDragEnd
: ADragEvent
handler function. Fires when the user stops dragging something.onDragEndCapture
: A version ofonDragEnd
that fires in the capture phase.onDragEnter
: ADragEvent
handler function. Fires when the dragged content enters a valid drop target.onDragEnterCapture
: A version ofonDragEnter
that fires in the capture phase.onDragOver
: ADragEvent
handler function. Fires on a valid drop target while the dragged content is dragged over it. You must calle.preventDefault()
here to allow dropping.onDragOverCapture
: A version ofonDragOver
that fires in the capture phase.onDragStart
: ADragEvent
handler function. Fires when the user starts dragging an element.onDragStartCapture
: A version ofonDragStart
that fires in the capture phase.onDrop
: ADragEvent
handler function. Fires when something is dropped on a valid drop target.onDropCapture
: A version ofonDrop
that fires in the capture phase.onFocus
: AFocusEvent
handler function. Fires when an element lost focus. Unlike the built-in browserfocus
event, in React theonFocus
event bubbles.onFocusCapture
: A version ofonFocus
that fires in the capture phase.onGotPointerCapture
: APointerEvent
handler function. Fires when an element programmatically captures a pointer.onGotPointerCaptureCapture
: A version ofonGotPointerCapture
that fires in the capture phase.onKeyDown
: AKeyboardEvent
handler function. Fires when a key is pressed.onKeyDownCapture
: A version ofonKeyDown
that fires in the capture phase.onKeyPress
: AKeyboardEvent
handler function. Deprecated. UseonKeyDown
oronBeforeInput
instead.onKeyPressCapture
: A version ofonKeyPress
that fires in the capture phase.onKeyUp
: AKeyboardEvent
handler function. Fires when a key is released.onKeyUpCapture
: A version ofonKeyUp
that fires in the capture phase.onLostPointerCapture
: APointerEvent
handler function. Fires when an element stops capturing a pointer.onLostPointerCaptureCapture
: A version ofonLostPointerCapture
that fires in the capture phase.onMouseDown
: AMouseEvent
handler function. Fires when the pointer is pressed down.onMouseDownCapture
: A version ofonMouseDown
that fires in the capture phase.onMouseEnter
: AMouseEvent
handler function. Fires when the pointer moves inside an element. Does not have a capture phase. Instead,onMouseLeave
andonMouseEnter
propagate from the element being left to the one being entered.onMouseLeave
: AMouseEvent
handler function. Fires when the pointer moves outside an element. Does not have a capture phase. Instead,onMouseLeave
andonMouseEnter
propagate from the element being left to the one being entered.onMouseMove
: AMouseEvent
handler function. Fires when the pointer changes coordinates.onMouseMoveCapture
: A version ofonMouseMove
that fires in the capture phase.onMouseOut
: AMouseEvent
handler function. Fires when the pointer moves outside an element, or if it moves into a child element.onMouseOutCapture
: A version ofonMouseOut
that fires in the capture phase.onMouseUp
: AMouseEvent
handler function. Fires when the pointer is released.onMouseUpCapture
: A version ofonMouseUp
that fires in the capture phase.onPointerCancel
: APointerEvent
handler function. Fires when the browser cancels a pointer interaction.onPointerCancelCapture
: A version ofonPointerCancel
that fires in the capture phase.onPointerDown
: APointerEvent
handler function. Fires when a pointer becomes active.onPointerDownCapture
: A version ofonPointerDown
that fires in the capture phase.onPointerEnter
: APointerEvent
handler function. Fires when a pointer moves inside an element. Does not have a capture phase. Instead,onPointerLeave
andonPointerEnter
propagate from the element being left to the one being entered.onPointerLeave
: APointerEvent
handler function. Fires when a pointer moves outside an element. Does not have a capture phase. Instead,onPointerLeave
andonPointerEnter
propagate from the element being left to the one being entered.onPointerMove
: APointerEvent
handler function. Fires when a pointer changes coordinates.onPointerMoveCapture
: A version ofonPointerMove
that fires in the capture phase.onPointerOut
: APointerEvent
handler function. Fires when a pointer moves outside an element, if the pointer interaction is cancelled, and a few other reasons.onPointerOutCapture
: A version ofonPointerOut
that fires in the capture phase.onPointerUp
: APointerEvent
handler function. Fires when a pointer is no longer active.onPointerUpCapture
: A version ofonPointerUp
that fires in the capture phase.onPaste
: AClipboardEvent
handler function. Fires when the user tries to paste something from the clipboard.onPasteCapture
: A version ofonPaste
that fires in the capture phase.onScroll
: AnEvent
handler function. Fires when an element has been scrolled. This event does not bubble.onScrollCapture
: A version ofonScroll
that fires in the capture phase.onSelect
: AnEvent
handler function. Fires after the selection inside an editable element like an input changes. React extends theonSelect
event to work forcontentEditable={true}
elements as well. In addition, React extends it to fire for empty selection and on edits (which may affect the selection).onSelectCapture
: A version ofonSelect
that fires in the capture phase.onTouchCancel
: ATouchEvent
handler function. Fires when the browser cancels a touch interaction.onTouchCancelCapture
: A version ofonTouchCancel
that fires in the capture phase.onTouchEnd
: ATouchEvent
handler function. Fires when one or more touch points are removed.onTouchEndCapture
: A version ofonTouchEnd
that fires in the capture phase.onTouchMove
: ATouchEvent
handler function. Fires one or more touch points are moved.onTouchMoveCapture
: A version ofonTouchMove
that fires in the capture phase.onTouchStart
: ATouchEvent
handler function. Fires when one or more touch points are placed.onTouchStartCapture
: A version ofonTouchStart
that fires in the capture phase.onTransitionEnd
: ATransitionEvent
handler function. Fires when a CSS transition completes.onTransitionEndCapture
: A version ofonTransitionEnd
that fires in the capture phase.onWheel
: AWheelEvent
handler function. Fires when the user rotates a wheel button.onWheelCapture
: A version ofonWheel
that fires in the capture phase.role
: A string. Specifies the element role explicitly for assistive technologies. nt.slot
: A string. Specifies the slot name when using shadow DOM. In React, an equivalent pattern is typically achieved by passing JSX as props, for example<Layout left={<Sidebar />} right={<Content />} />
.spellCheck
: A boolean or null. If explicitly set totrue
orfalse
, enables or disables spellchecking.tabIndex
: A number. Overrides the default Tab button behavior. Avoid using values other than-1
and0
.title
: A string. Specifies the tooltip text for the element.translate
: Either'yes'
or'no'
. Passing'no'
excludes the element content from being translated.
You can also pass custom attributes as props, for example mycustomprop="someValue"
. This can be useful when integrating with third-party libraries. The custom attribute name must be lowercase and must not start with on
. The value will be converted to a string. If you pass null
or undefined
, the custom attribute will be removed.
These events fire only for the <form>
elements:
onReset
: AnEvent
handler function. Fires when a form gets reset.onResetCapture
: A version ofonReset
that fires in the capture phase.onSubmit
: AnEvent
handler function. Fires when a form gets submitted.onSubmitCapture
: A version ofonSubmit
that fires in the capture phase.
These events fire only for the <dialog>
elements. Unlike browser events, they bubble in React:
onCancel
: AnEvent
handler function. Fires when the user tries to dismiss the dialog.onCancelCapture
: A version ofonCancel
that fires in the capture phase. capture-phase-events)onClose
: AnEvent
handler function. Fires when a dialog has been closed.onCloseCapture
: A version ofonClose
that fires in the capture phase.
These events fire only for the <details>
elements. Unlike browser events, they bubble in React:
onToggle
: AnEvent
handler function. Fires when the user toggles the details.onToggleCapture
: A version ofonToggle
that fires in the capture phase. capture-phase-events)
These events fire for <img>
, <iframe>
, <object>
, <embed>
, <link>
, and SVG <image>
elements. Unlike browser events, they bubble in React:
onLoad
: AnEvent
handler function. Fires when the resource has loaded.onLoadCapture
: A version ofonLoad
that fires in the capture phase.onError
: AnEvent
handler function. Fires when the resource could not be loaded.onErrorCapture
: A version ofonError
that fires in the capture phase.
These events fire for resources like <audio>
and <video>
. Unlike browser events, they bubble in React:
onAbort
: AnEvent
handler function. Fires when the resource has not fully loaded, but not due to an error.onAbortCapture
: A version ofonAbort
that fires in the capture phase.onCanPlay
: AnEvent
handler function. Fires when there's enough data to start playing, but not enough to play to the end without buffering.onCanPlayCapture
: A version ofonCanPlay
that fires in the capture phase.onCanPlayThrough
: AnEvent
handler function. Fires when there's enough data that it's likely possible to start playing without buffering until the end.onCanPlayThroughCapture
: A version ofonCanPlayThrough
that fires in the capture phase.onDurationChange
: AnEvent
handler function. Fires when the media duration has updated.onDurationChangeCapture
: A version ofonDurationChange
that fires in the capture phase.onEmptied
: AnEvent
handler function. Fires when the media has become empty.onEmptiedCapture
: A version ofonEmptied
that fires in the capture phase.onEncrypted
: AnEvent
handler function. Fires when the browser encounters encrypted media.onEncryptedCapture
: A version ofonEncrypted
that fires in the capture phase.onEnded
: AnEvent
handler function. Fires when the playback stops because there's nothing left to play.onEndedCapture
: A version ofonEnded
that fires in the capture phase.onError
: AnEvent
handler function. Fires when the resource could not be loaded.onErrorCapture
: A version ofonError
that fires in the capture phase.onLoadedData
: AnEvent
handler function. Fires when the current playback frame has loaded.onLoadedDataCapture
: A version ofonLoadedData
that fires in the capture phase.onLoadedMetadata
: AnEvent
handler function. Fires when metadata has loaded.onLoadedMetadataCapture
: A version ofonLoadedMetadata
that fires in the capture phase.onLoadStart
: AnEvent
handler function. Fires when the browser started loading the resource.onLoadStartCapture
: A version ofonLoadStart
that fires in the capture phase.onPause
: AnEvent
handler function. Fires when the media was paused.onPauseCapture
: A version ofonPause
that fires in the capture phase.onPlay
: AnEvent
handler function. Fires when the media is no longer paused.onPlayCapture
: A version ofonPlay
that fires in the capture phase.onPlaying
: AnEvent
handler function. Fires when the media starts or restarts playing.onPlayingCapture
: A version ofonPlaying
that fires in the capture phase.onProgress
: AnEvent
handler function. Fires periodically while the resource is loading.onProgressCapture
: A version ofonProgress
that fires in the capture phase.onRateChange
: AnEvent
handler function. Fires when playback rate changes.onRateChangeCapture
: A version ofonRateChange
that fires in the capture phase.onResize
: AnEvent
handler function. Fires when video changes size.onResizeCapture
: A version ofonResize
that fires in the capture phase.onSeeked
: AnEvent
handler function. Fires when a seek operation completes.onSeekedCapture
: A version ofonSeeked
that fires in the capture phase.onSeeking
: AnEvent
handler function. Fires when a seek operation starts.onSeekingCapture
: A version ofonSeeking
that fires in the capture phase.onStalled
: AnEvent
handler function. Fires when the browser is waiting for data but it keeps not loading.onStalledCapture
: A version ofonStalled
that fires in the capture phase.onSuspend
: AnEvent
handler function. Fires when loading the resource was suspended.onSuspendCapture
: A version ofonSuspend
that fires in the capture phase.onTimeUpdate
: AnEvent
handler function. Fires when the current playback time updates.onTimeUpdateCapture
: A version ofonTimeUpdate
that fires in the capture phase.onVolumeChange
: AnEvent
handler function. Fires when the volume has changed.onVolumeChangeCapture
: A version ofonVolumeChange
that fires in the capture phase.onWaiting
: AnEvent
handler function. Fires when the playback stopped due to temporary lack of data.onWaitingCapture
: A version ofonWaiting
that fires in the capture phase.
Caveats¶
- You cannot pass both
children
anddangerouslySetInnerHTML
at the same time. - Some events (like
onAbort
andonLoad
) don't bubble in the browser, but bubble in React.