OnlineCBT Logo OnlineCBT
HTML Tutorial
HTML · LESSON 48

HTML IDs and Classes

By Ratan Updated: 16 Oct 2026

Identify unique elements with id attribute and group reusable elements with class attribute.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

1. The id Attribute

The id attribute specifies a globally unique identifier for an HTML element. Within an entire HTML document, no two elements can share the same id value.

  • Targeted in CSS using the hash symbol: #exam-timer { color: red; }.
  • Targeted in JavaScript via: document.getElementById("exam-timer").
  • Used for URL fragment page bookmarks: .


2. The class Attribute

The class attribute defines a reusable styling or behavioral classification. Multiple elements can share the same class name, and a single element can have multiple classes separated by spaces.

  • Targeted in CSS using the dot symbol: .btn-primary { background: blue; }.
  • Targeted in JavaScript via: document.querySelectorAll(".question-card").



📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
पता संपर्क करें

+91 7877547686

ई-मेल

onlinecbtportal@gmail.com

हेल्पलाइन नंबर

+91 7877547686


डाउनलोड करने के लिए क्लिक करें
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat