Categories
React Answers

How to Add Custom HTML Attributes in React?

Spread the love

Sometimes, we want to add custom HTML attributes in React.

In this article, we’ll look at how to add custom HTML attributes in React.

Add Custom HTML Attributes in React

To add custom HTML attributes in React, we can just add them as we do with regular HTML element attributes.

For instance, we can write:

import React from "react";

export default function App() {
  return <div custom-attribute="some-value" />;
}

We just add the custom-attribute custom attribute and it’ll be rendered in the HTML.

This works since React 16.

Conclusion

To add custom HTML attributes in React, we can just add them as we do with regular HTML element attributes.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *