HTML ID Attribute

The id attribute uniquely identifies an HTML element within a page. Each ID must be unique, making it useful for linking, styling, and scripting specific elements.

Tutorials dojo strip

HTML ID Attribute Syntax

Explanation of Syntax:

  • tagname: The name of the HTML element (e.g., <div>, <h2>).
  • id="unique_id": The id attribute provides a unique identifier for the element.
HTML




HTML ID Attribute Example Code

Explanation of Code:

  • The code starts with the <!DOCTYPE html> declaration and the opening <html> tag.
  • The <head> section includes metadata and a CSS style for the #main-content ID, which gives it a light blue background and padding.
  • The <body> section contains:
    • An <h1> tag with a welcome message.
    • A <div> tag assigned the unique ID “main-content,” allowing for specific styling and identification. Inside the <div>, a <p> tag describes the content area.
  • The id attribute is beneficial for referencing specific elements in CSS and JavaScript, ensuring that each element can be individually styled or manipulated without affecting others.
HTML




HTML Labs

Tutorials dojo strip