Skip to main content
Practice

ID Selector

An HTML id is a unique selector used to identify a specific HTML element.

The id is primarily used to assign a unique id to a specific element, allowing it to be selected and manipulated with CSS or JavaScript.

Due to this uniqueness, multiple HTML elements cannot share the same id.

The id selector is defined 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 an HTML element with the id intro using #intro, applying styles that are only applicable to this HTML element.

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

However, ids are conventionally written in lowercase.

Want to learn more?

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