Skip to main content
Practice

ID Selector

In HTML, an id is a selector used to uniquely identify a specific HTML element.

It is primarily used to give a particular element a unique id so that it can be selected and manipulated through CSS or JavaScript.

Because of this uniqueness, multiple HTML elements cannot share the same id.

An id selector is defined by preceding it with a # as shown below:

Example of using HTML id
<style>
#intro {
font-size: 24px;
font-weight: bold;
color: green;
}
</style>

<p id="intro">Welcome</p>

The code above selects the HTML element with the id intro using #intro, applying the styles specifically to that element.

Note that ids are case-sensitive. Thus, Intro and intro are considered different ids.

However, by convention, lowercase is typically used for ids.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.