HTML Attributes in HTML

Attributes provide additional information about HTML elements. They are placed inside the opening tag and typically come in name/value pairs, enabling customization and control over elements’ behavior and appearance.

Tutorials dojo strip

HTML Attributes Syntax

Explanation of Syntax:

  • tagname: The name of the HTML element (e.g., <a>, <img>, <div>).
  • attribute_name="value": The attribute name (e.g., href, src, class) followed by its corresponding value in quotes.
HTML




HTML Attributes Example Code

Explanation of Code:

  • The code starts with the <!DOCTYPE html> declaration, followed by the opening <html> tag.
  • The <head> section contains metadata, including the character set and viewport settings, along with the title of the page.The <body> section includes visible content:
    • An <h1> tag with a class attribute, which can be used in CSS for styling. The value “main-title” helps identify this particular heading for styling or scripting purposes.
    • A <p> tag with an id attribute named “intro.” The id is unique within the page and can be used for styling or linking to this specific paragraph.
    • An <a> tag linking to https://example.com. The target="_blank" attribute specifies that the link will open in a new tab when clicked.
    • An <img> tag embeds an image from https://via.placeholder.com/150, with an alt attribute describing the image and a title attribute providing additional information that appears as a tooltip when users hover over the image.
HTML




HTML Labs

Tutorials dojo strip