)"
+---
+
+
+
+All built-in browser components, such as [`
`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div), support some common props and events.
+
+
+
+
+
+---
+
+## Usage {/*usage*/}
+
+### Applying CSS styles {/*applying-css-styles*/}
+
+In React, you specify a CSS class with [`className`.](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) It works like the `class` attribute in HTML:
+
+```js
+
+```
+
+Then you write the CSS rules for it in a separate CSS file:
+
+```css
+/* In your CSS */
+.avatar {
+ border-radius: 50%;
+}
+```
+
+React does not prescribe how you add CSS files. In the simplest case, you'll add a [``](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link) tag to your HTML. If you use a build tool or a framework, consult its documentation to learn how to add a CSS file to your project.
+
+Sometimes, the style values depend on data. Use the `style` attribute to pass some styles dynamically:
+
+```js {3-6}
+
+```
+
+
+In the above example, `style={{}}` is not a special syntax, but a regular `{}` object inside the `style={ }` [JSX curly braces.](/learn/javascript-in-jsx-with-curly-braces) We recommend to only use the `style` attribute when your styles depend on JavaScript variables.
+
+
+
+```js App.js
+import Avatar from './Avatar.js';
+
+const user = {
+ name: 'Hedy Lamarr',
+ imageUrl: 'https://i.imgur.com/yXOvdOSs.jpg',
+ imageSize: 90,
+};
+
+export default function App() {
+ return ;
+}
+```
+
+```js Avatar.js active
+export default function Avatar({ user }) {
+ return (
+
+ );
+}
+```
+
+```css styles.css
+.avatar {
+ border-radius: 50%;
+}
+```
+
+
+
+
+
+#### How to apply multiple CSS classes conditionally? {/*how-to-apply-multiple-css-classes-conditionally*/}
+
+To apply CSS classes conditionally, you need to produce the `className` string yourself using JavaScript.
+
+For example, `className={'row ' + (isSelected ? 'selected': '')}` will produce either `className="row"` or `className="row selected"` depending on whether `isSelected` is `true`.
+
+To make this more readable, you can use a tiny helper library like [`classnames`:](https://github.com/JedWatson/classnames)
+
+```js
+import cn from 'classnames';
+
+function Row({ isSelected }) {
+ return (
+
+ ...
+
+ );
+}
+```
+
+It is especially convenient if you have multiple conditional classes:
+
+```js
+import cn from 'classnames';
+
+function Row({ isSelected, size }) {
+ return (
+
+ ...
+
+ );
+}
+```
+
+
+
+---
+
+### Manipulating a DOM node with a ref {/*manipulating-a-dom-node-with-a-ref*/}
+
+Sometimes, you'll need to get the browser DOM node associated with a tag in JSX. For example, if you want to focus an `` when a button is clicked, you need to call [`focus()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the browser `` DOM node.
+
+To obtain the browser DOM node for a tag, [declare a ref](/apis/react/useRef) and pass it as the `ref` attribute to that tag:
+
+```js {7}
+import { useRef } from 'react';
+
+export default function Form() {
+ const inputRef = useRef(null);
+ // ...
+ return (
+
+ // ...
+```
+
+React will put the DOM node into `inputRef.current` after it's been rendered to the screen.
+
+
+
+```js
+import { useRef } from 'react';
+
+export default function Form() {
+ const inputRef = useRef(null);
+
+ function handleClick() {
+ inputRef.current.focus();
+ }
+
+ return (
+ <>
+
+
+ >
+ );
+}
+```
+
+
+
+Read more about [manipulating DOM with refs](/learn/manipulating-the-dom-with-refs) and [check out more examples.](/apis/react/useRef#examples-dom)
+
+For more advanced use cases, the `ref` attribute also accepts a [callback function.](#ref-callback)
+
+---
+
+### Dangerously setting the inner HTML {/*dangerously-setting-the-inner-html*/}
+
+You can pass a raw HTML string to an element like so:
+
+```js
+const markup = { __html: '
some raw html
' };
+return ;
+```
+
+**This is dangerous. As with the underlying DOM [`innerHTML`](https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML) property, you must exercise extreme caution! Unless the markup is coming from a completely trusted source, it is trivial to introduce an [XSS](https://en.wikipedia.org/wiki/Cross-site_scripting) vulnerability this way.**
+
+For example, if you use a Markdown library that converts Markdown to HTML, you trust that its parser doesn't contain bugs, and the user only sees their own input, you can display the resulting HTML like this:
+
+
+
+```js
+import { useState } from 'react';
+import MarkdownPreview from './MarkdownPreview.js';
+
+export default function MarkdownEditor() {
+ const [postContent, setPostContent] = useState('_Hello,_ **Markdown**!');
+ return (
+ <>
+
+
+
+ >
+ );
+}
+```
+
+```js MarkdownPreview.js active
+import { Remarkable } from 'remarkable';
+
+const md = new Remarkable();
+
+function renderMarkdownToHTML(markdown) {
+ // This is ONLY safe because the output HTML
+ // is shown to the same user, and because you
+ // trust this Markdown parser to not have bugs.
+ const renderedHTML = md.render(markdown);
+ return {__html: renderedHTML};
+}
+
+export default function MarkdownPreview({ markdown }) {
+ const markup = renderMarkdownToHTML(markdown);
+ return ;
+}
+```
+
+```json package.json
+{
+ "dependencies": {
+ "react": "latest",
+ "react-dom": "latest",
+ "react-scripts": "latest",
+ "remarkable": "2.0.1"
+ },
+ "scripts": {
+ "start": "react-scripts start",
+ "build": "react-scripts build",
+ "test": "react-scripts test --env=jsdom",
+ "eject": "react-scripts eject"
+ }
+}
+```
+
+```css
+textarea { display: block; margin-top: 5px; margin-bottom: 10px; }
+```
+
+
+
+To see why rendering arbitrary HTML is dangerous, replace the code above with this:
+
+```js {1-4,7,8}
+const post = {
+ // Imagine this content is stored in the database.
+ content: ``
+};
+
+export default function MarkdownPreview() {
+ // 🔴 SECURITY HOLE: passing untrusted input to dangerouslySetInnerHTML
+ const markup = { __html: post.content };
+ return ;
+}
+```
+
+The code embedded in the HTML will run. A hacker could use this security hole to steal user information or to perform actions on their behalf. **Only use `dangerouslySetInnerHTML` with trusted and sanitized data.**
+
+---
+
+### Handling mouse events {/*handling-mouse-events*/}
+
+This example shows some common [mouse events](#mouseevent-handler) and when they fire.
+
+
+
+```js
+export default function MouseExample() {
+ return (
+
+ );
+}
+```
+
+```css
+label { display: block; }
+input { margin-left: 10px; }
+```
+
+
+
+---
+
+### Handling focus events {/*handling-focus-events*/}
+
+In React, [focus events](#focusevent-handler) bubble. You can use the `currentTarget` and `relatedTarget` to differentiate if the focusing or blurring events originated from outside of the parent element. The example shows how to detect focusing a child, focusing the parent element, and how to detect focus entering or leaving the whole subtree.
+
+
+
+```js
+export default function FocusExample() {
+ return (
+
{
+ if (e.currentTarget === e.target) {
+ console.log('focused parent');
+ } else {
+ console.log('focused child', e.target.name);
+ }
+ if (!e.currentTarget.contains(e.relatedTarget)) {
+ // Not triggered when swapping focus between children
+ console.log('focus entered parent');
+ }
+ }}
+ onBlur={(e) => {
+ if (e.currentTarget === e.target) {
+ console.log('unfocused parent');
+ } else {
+ console.log('unfocused child', e.target.name);
+ }
+ if (!e.currentTarget.contains(e.relatedTarget)) {
+ // Not triggered when swapping focus between children
+ console.log('focus left parent');
+ }
+ }}
+ >
+
+
+
`) {/*common*/}
+
+#### Props {/*common-props*/}
+
+These special React props are supported for all built-in components:
+
+* `children`: A React node (an element, a string, a number, [a portal,](/apis/react-dom/createPortal) an empty node like `null`, `undefined` and booleans, or an array of other React nodes). Specifies the content inside the component. When you use JSX, you will usually specify the `children` prop implicitly by nesting tags like `
`.
+
+* `dangerouslySetInnerHTML`: An object of the form `{ __html: '
some html
' }` with a raw HTML string inside. Overrides the [`innerHTML`](https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML) 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](https://en.wikipedia.org/wiki/Cross-site_scripting) vulnerability. [Read more about using `dangerouslySetInnerHTML`.](#dangerously-setting-the-inner-html)
+
+* `ref`: A ref object from [`useRef`](/apis/react/useRef) or [`createRef`](/apis/react/createRef), or a [`ref` callback function,](#ref-callback) or a string for [legacy refs.](https://reactjs.org/docs/refs-and-the-dom.html#legacy-api-string-refs) Your ref will be filled with the DOM element for this node. [Read more about manipulating the DOM with refs.](#manipulating-a-dom-node-with-a-ref)
+
+* `suppressContentEditableWarning`: A boolean. If `true`, suppresses the warning that React shows for elements that both have `children` and `contentEditable={true}` (which normally do not work together). Use this if you're building a text input library that manages the `contentEditable` content manually.
+
+* `suppressHydrationWarning`: A boolean. If you use [server rendering,](/apis/react-dom/server) 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 set `suppressHydrationWarning` to `true`, 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 more about suppressing hydration errors.](/apis/react-dom/client/hydrateRoot#suppressing-unavoidable-hydration-mismatch-errors)
+
+* `style`: An object with CSS styles, for example `{ fontWeight: 'bold', margin: 20 }`. Similarly to the DOM [`style`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) property, the CSS property names need to be written as `camelCase`, for example `fontWeight` instead of `font-weight`. You can pass strings or numbers as values. If you pass a number, like `width: 100`, React will automatically append `px` ("pixels") to the value unless it's a [unitless property.](https://github.com/facebook/react/blob/81d4ee9ca5c405dce62f64e61506b8e155f38d8d/packages/react-dom-bindings/src/shared/CSSProperty.js#L8-L57) We recommend using `style` only for dynamic styles where you don't know the style values ahead of time. In other cases, applying plain CSS classes with `className` is more efficient. [Read more about applying CSS with `className` and `styles`.](#applying-css-styles)
+
+These standard DOM props are also supported for all built-in components:
+
+* [`accessKey`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/accesskey): A string. Specifies a keyboard shortcut for the element. [Not generally recommended.](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/accesskey#accessibility_concerns)
+* [`aria-*`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes): ARIA attributes let you specify the accessibility tree information for this element. See [ARIA attributes](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes) for a complete reference. In React, all ARIA attribute names are exactly the same as in HTML.
+* [`autoCapitalize`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize): A string. Specifies whether and how the user input should be capitalized.
+* [`className`](https://developer.mozilla.org/en-US/docs/Web/API/Element/className): A string. Specifies the element's CSS class name. [Read more about applying CSS styles.](#applying-css-styles)
+* [`contentEditable`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contenteditable): A boolean. If `true`, the browser lets the user edit the rendered element directly. This is used to implement rich text input libraries like [Lexical.](https://lexical.dev/) React warns if you try to pass React children to an element with `contentEditable={true}` because React will not be able to update its content after user edits.
+* [`data-*`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/data-*): Data attributes let you attach some string data to the element, for example `data-fruit="banana"`. In React, they are not commonly used because you would usually read data from props or state instead.
+* [`dir`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir): Either `'ltr'` or `'rtl'`. Specifies the text direction of the element.
+* [`draggable`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/draggable): A boolean. Specifies whether the element is draggable. Part of [HTML Drag and Drop API.](https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API)
+* [`enterKeyHint`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/enterKeyHint): A string. Specifies which action to present for the enter key on virtual keyboards.
+* [`htmlFor`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/htmlFor): A string. For [`