|

HTML 2 💻 Elements

An element is the building block of an HTML page. It typically consists of an opening tag, attributes, content, and a closing tag.

Basic Structure of an Element

<h1>Hello World</h1>
  • <h1> — opening tag
  • Hello World — content
  • </h1> — closing tag

Important Rules to Remember

  • Always close your elements — forgetting the closing tag can break your page layout.
  <h2>This is correct</h2>
  • Elements can contain other elements — this is called nesting. For example, the <body> element contains all visible content:
  <body>
      <h1>Welcome</h1>
      <p>This is a paragraph.</p>
  </body>
  • Empty elements have no content — they are written with a self-closing tag or just an opening tag:
  <h1></h1>  <!-- Empty heading -->
  <br>       <!-- Line break (self-closing) -->
  • W3C recommends using lowercase for all HTML tags and attributes for better readability and consistency.

Element Attributes

Attributes provide additional information about an element. They are always written inside the opening tag and are optional.

An attribute consists of a name and a value:

<tagname attribute="value">Content</tagname>

Example:

<h1 id="main-title" class="header">Welcome to My Site</h1>

The 4 Categories of Attributes

CategoryDescriptionExample
Universal (Global) AttributesCan be used on almost all HTML elementsid, class, style, title
Specific AttributesOnly work on specific elementssrc (for <img>), href (for <a>)
Event AttributesTrigger actions when events occur (click, hover, etc.)onclick, onmouseover
Data AttributesStore custom information for use in scriptsdata-user="John"

Universal (Global) Attributes Explained

These attributes can be applied to nearly every HTML element:

AttributePurposeExample
idUniquely identifies an element (must be unique on the page)id="header"
classAssigns one or more class names to an element (used for styling or scripting)class="button primary"
styleDefines inline CSS styles directly on the elementstyle="color: blue; font-size: 2em"
titleDisplays a tooltip when the user hovers over the elementtitle="Click here for more info"
langSpecifies the language of the element’s content<html lang="en">
dirDefines the text direction — ltr (left-to-right) or rtl (right-to-left)dir="rtl"

Quick Example Using Multiple Attributes

<h1 id="main-heading" class="title large" style="color: navy;" title="This is the main title" lang="en" dir="ltr">
    Welcome to HTML
</h1>

This foundation in elements and attributes will help you build well-structured, interactive, and styled web pages. 🚀


Stop using slow, ad-bloated tool sites! 🤮

🔎 Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)

⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free

🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!