How to add a custom attribute to an HTML tag?

Spread the love

Sometimes, we want to add a custom attribute to an HTML tag.

In this article, we’ll look at how to add a custom attribute to an HTML tag.

How to add a custom attribute to an HTML tag?

To add a custom attribute to an HTML tag, we can add data- attributes.

For instance, we write

<ul>
  <li data-animal-type="bird">Owl</li>
  <li data-animal-type="fish">Salmon</li>
  <li data-animal-type="spider">Tarantula</li>
</ul>

to add the data-animal-type attribute and set its value to what we want.

Conclusion

To add a custom attribute to an HTML tag, we can add data- attributes.

Leave a Reply

Your email address will not be published.