w1coding.comAll tutorials

HTML ID

HTML lessons
  1. Environment Setup
  2. Introduction
  3. Basics
  4. Editors
  5. Elements
  6. Attributes
  7. Heading
  8. Paragraphs
  9. Styles
  10. Formatting
  11. Quotations
  12. Comment
  13. Colors
  14. CSS
  15. Links
  16. Images
  17. Favicon
  18. Title
  19. Tables
  20. Block And Inline
  21. Lists
  22. Div
  23. Classes
  24. ID
  25. Iframes
  26. Responsive

How to Use id

You can define an id in your HTML by adding the id attribute to an element:

<div id="uniqueElement">This is a unique div.</div>

In your CSS, you can style the element using the hash (#) followed by the id name:

#uniqueElement { background-color: lightblue; }

Examples of id

Example 1: Basic Usage

This is a simple div with a unique id:

This div has an id of uniqueDiv.

Example 2: Targeting with CSS

The following example shows how to style an element with an id:

This text is styled using the #uniqueDiv id.

Example 3: Manipulating with JavaScript

This example demonstrates how you can manipulate an element with JavaScript:

Original content