2018-10-10 18:03:03 -04:00
---
id: 5a24c314108439a4d4036160
2021-02-06 04:42:36 +00:00
title: Define an HTML Class in JSX
2018-10-10 18:03:03 -04:00
challengeType: 6
2020-09-18 00:13:42 +08:00
forumTopicId: 301393
2021-01-13 03:31:00 +01:00
dashedName: define-an-html-class-in-jsx
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Now that you're getting comfortable writing JSX, you may be wondering how it differs from HTML.
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
So far, it may seem that HTML and JSX are exactly the same.
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
One key difference in JSX is that you can no longer use the word `class` to define HTML classes. This is because `class` is a reserved word in JavaScript. Instead, JSX uses `className` .
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
In fact, the naming convention for all HTML attributes and event references in JSX become camelCase. For example, a click event in JSX is `onClick` , instead of `onclick` . Likewise, `onchange` becomes `onChange` . While this is a subtle difference, it is an important one to keep in mind moving forward.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Apply a class of `myDiv` to the `div` provided in the JSX code.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
The constant `JSX` should return a `div` element.
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert.strictEqual(JSX.type, 'div');
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
The `div` should have a class of `myDiv` .
2020-09-18 00:13:42 +08:00
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert.strictEqual(JSX.props.className, 'myDiv');
2018-10-10 18:03:03 -04:00
```
2020-08-13 17:24:35 +02:00
2021-01-13 03:31:00 +01:00
# --seed--
## --after-user-code--
```jsx
ReactDOM.render(JSX, document.getElementById('root'))
```
## --seed-contents--
```jsx
const JSX = (
< div >
< h1 > Add a class to this div< / h1 >
< / div >
);
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```jsx
const JSX = (
< div className = 'myDiv' >
< h1 > Add a class to this div< / h1 >
< / div > );
```