Lesson: HTML5 and CSS
Set the ID of an Element
In addition to classes, each HTML element can also have an id
attribute.
There are several benefits to using id
attributes, and you'll learn more about them once you start using jQuery.
id
attributes should be unique. Browsers won't enforce this, but it is a widely agreed upon best practice. So please don't give more than one element the same id
attribute.
Here's an example of how you give your h2
element the id of cat-photo-app
:
<h2 id="cat-photo-app">
Give your form
element the id cat-photo-form
.
The content on this page is licensed under Attribution-ShareAlike 4.0 International. Original authors: freeCodeCamp, the content was modified.