HTML Academy · Lesson

id class style and title

Apply core global attributes to any HTML element.

Lesson 1 of 413 steps

id class style and title is a free HTML Academy lesson on CoddyKit. This is lesson 1 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the HTML Academy learning path, and your progress syncs across the web and the CoddyKit app. The HTML Academy course includes 4 lessons in total.

Global Attributes

Global attributes can be applied to any HTML element:

  • id — unique identifier
  • class — one or more CSS classes
  • style — inline CSS
  • title — tooltip text
  • And many more: lang, hidden, tabindex, data-*...

The id Attribute

The id attribute assigns a unique identifier to an element:

<h2 id="installation">Installation Guide</h2>
<form id="signup-form">...</form>
<div id="hero-banner">...</div>

<!-- Rules:
  - Must be unique per page
  - No spaces
  - Use hyphens: user-profile
  - Case-sensitive: #hero ≠ #Hero
-->

Uses of id

The id attribute serves multiple purposes:

  • CSS targeting: #hero-banner { ... }
  • JavaScript selection: document.getElementById('signup-form')
  • Fragment navigation: <a href="#installation">
  • ARIA labelling: aria-labelledby="modal-title"

The class Attribute

The class attribute assigns one or more CSS classes:

<p class="text-large">Large text paragraph.</p>
<button class="btn btn-primary">Submit</button>
<div class="card card-featured highlighted">...</div>

<!-- Multiple classes separated by spaces -->
<!-- Elements can share classes (unlike id) -->
<!-- JavaScript: element.classList.add('active') -->

id vs class

When to use each:

  • id — one specific element on the page
  • class — a style pattern applied to multiple elements
<!-- id: unique element -->
<main id="main-content">...</main>

<!-- class: reusable style -->
<div class="card">Card 1</div>
<div class="card">Card 2</div>
<div class="card card-featured">Featured</div>

The style Attribute

The style attribute adds inline CSS:

<p style="color: red; font-weight: bold;">Warning message</p>
<div style="background: #f0f4f8; padding: 1rem; border-radius: 0.5rem;">
  Info box
</div>

<!-- Inline styles have the highest specificity
     They are hard to override and hard to maintain
     Prefer external CSS classes whenever possible -->

When to Use Inline style

Inline style is acceptable in these cases:

  • Dynamic values set by JavaScript
  • Values that cannot be known at CSS-write time (user-set colors, widths)
  • Email HTML (email clients strip external CSS)

Do not use style for static presentational choices — that belongs in CSS.

The title Attribute

The title attribute provides tooltip text on hover:

<abbr title="HyperText Markup Language">HTML</abbr>
<button title="Submit the registration form">Submit</button>
<a href="/docs" title="Full documentation (opens in new tab)" target="_blank" rel="noopener">Docs</a>

title Accessibility Limitations

The title attribute has significant accessibility problems:

  • Not accessible via keyboard navigation
  • Not shown on touch screens
  • Screen reader behavior is inconsistent
  • Never put critical information only in title

Use aria-label or visible text for important information.

Specificity: id vs class vs inline

CSS specificity from lowest to highest:

/* Element selector: 0-0-1 */
p { color: gray; }

/* Class selector: 0-1-0 */
.text { color: blue; }

/* ID selector: 1-0-0 */
#unique { color: green; }

/* Inline style: 1-0-0-0 (highest) */
<p style="color: red;">Red wins</p>

class Naming Conventions

Popular class naming conventions:

<!-- BEM (Block Element Modifier) -->
<div class="card">
  <div class="card__header">
    <h2 class="card__title card__title--featured">Title</h2>
  </div>
</div>

<!-- Utility classes (Tailwind style) -->
<div class="flex items-center gap-4 p-4 bg-white rounded-lg shadow">

Quick Check

What is the key rule about the id attribute?

Recap: id class style title

Core global attributes:

  • id — unique per page; used for CSS, JavaScript, fragments, ARIA
  • class — reusable; multiple classes separated by spaces
  • style — inline CSS (use sparingly; prefer external CSS)
  • title — tooltip; not accessible for keyboard/touch users
  • id specificity > class specificity in CSS
Free to start

Learn HTML with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
40
Lessons
159

Frequently Asked Questions

Is the “id class style and title” lesson free?

Yes — any 3 lessons of the HTML Academy learning path, including “id class style and title”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The HTML Academy course includes 4 lessons in total.

What will I learn in “id class style and title”?

Apply core global attributes to any HTML element. You practise HTML Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start HTML Academy?

No prior experience is required. HTML Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.

How long does the “id class style and title” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this HTML Academy lesson?

Yes. Every HTML Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. id class style and title
  2. The hidden Attribute
  3. tabindex and accesskey
  4. Custom Data Attributes data-*
← Back to HTML Academy