--- id: dom-elements title: DOM Elements layout: docs category: Reference permalink: docs/dom-elements.html redirect_from: - "docs/tags-and-attributes.html" - "docs/dom-differences.html" - "docs/special-non-dom-attributes.html" - "docs/class-name-manipulation.html" - "tips/inline-styles.html" - "tips/style-props-value-px.html" - "tips/dangerously-set-inner-html.html" --- React implements a browser-independent DOM system for performance and cross-browser compatibility. We took the opportunity to clean up a few rough edges in browser DOM implementations. In React, all DOM properties and attributes (including event handlers) should be camelCased. For example, the HTML attribute `tabindex` corresponds to the attribute `tabIndex` in React. The exception is `aria-*` and `data-*` attributes, which should be lowercased. For example, you can keep `aria-label` as `aria-label`. ## Differences In Attributes {#differences-in-attributes} There are a number of attributes that work differently between React and HTML: ### checked {#checked} The `checked` attribute is supported by `` components of type `checkbox` or `radio`. You can use it to set whether the component is checked. This is useful for building controlled components. `defaultChecked` is the uncontrolled equivalent, which sets whether the component is checked when it is first mounted. ### className {#classname} To specify a CSS class, use the `className` attribute. This applies to all regular DOM and SVG elements like `
`, ``, and others. If you use React with Web Components (which is uncommon), use the `class` attribute instead. ### dangerouslySetInnerHTML {#dangerouslysetinnerhtml} `dangerouslySetInnerHTML` is React's replacement for using `innerHTML` in the browser DOM. In general, setting HTML from code is risky because it's easy to inadvertently expose your users to a [cross-site scripting (XSS)](https://en.wikipedia.org/wiki/Cross-site_scripting) attack. So, you can set HTML directly from React, but you have to type out `dangerouslySetInnerHTML` and pass an object with a `__html` key, to remind yourself that it's dangerous. For example: ```js function createMarkup() { return {__html: 'First · Second'}; } function MyComponent() { return
; } ``` ### htmlFor {#htmlfor} Since `for` is a reserved word in JavaScript, React elements use `htmlFor` instead. ### onChange {#onchange} The `onChange` event behaves as you would expect it to: whenever a form field is changed, this event is fired. We intentionally do not use the existing browser behavior because `onChange` is a misnomer for its behavior and React relies on this event to handle user input in real time. ### selected {#selected} If you want to mark an `