Complete Guide to HTML Tags, Elements, and Attributes

VISHNU M K
By -
0



Introduction

HTML (Hypertext Markup Language) is the backbone of web development, allowing developers to structure and present content on the web. This guide covers essential HTML tags, elements, and attributes to help you build well-structured and interactive web pages.


Understanding HTML Elements and Tags

HTML elements define the structure of a webpage. Each element consists of an opening tag, content, and a closing tag (except for self-closing elements).


Basic HTML Document Structure


<!DOCTYPE html>

<html>

<head>

    <title>Sample Web Page</title>

</head>

<body>

    <h1>Welcome to HTML</h1>

    <p>This is an example paragraph.</p>

</body>

</html>


Common HTML Tags


Structural Elements

  • <html>: The root element of an HTML document.
  • <head>: Contains metadata, links, and scripts.
  • <body>: Holds the visible content of the page.
  • <title>: Sets the page title.
  • <meta>: Provides metadata like character encoding and viewport settings.

Text Formatting Tags

  • <h1> to <h6>: Headings of different levels.
  • <p>: Defines a paragraph.
  • <b> / <strong>: Makes text bold.
  • <i> / <em>: Italicizes text.
  • <u>: Underlines text.
  • <mark>: Highlights text.
  • <sub>: Displays subscript text.
  • <sup>: Displays superscript text.
  • <blockquote>: Indicates a block quotation.

List Elements

  • <ul>: Creates an unordered list.
  • <ol>: Creates an ordered list.
  • <li>: Represents a list item.
  • <dl>: Defines a description list.
  • <dt>: Represents a term in a description list.
  • <dd>: Provides the definition of a term.

Links and Navigation

  • <a href="URL">: Creates a hyperlink.
  • <nav>: Defines a navigation section.
  • <button>: Creates a clickable button.

Multimedia Elements

  • <img src="image.jpg" alt="Image Description">: Displays an image.
  • <audio>: Embeds an audio file.
  • <video>: Embeds a video file.
  • <source>: Specifies multiple media sources.
  • <iframe>: Embeds another webpage.

Table Elements

  • <table>: Defines a table.
  • <tr>: Represents a table row.
  • <th>: Defines a table header.
  • <td>: Defines a table data cell.
  • <caption>: Provides a table caption.

Forms and Input Elements

  • <form>: Defines an interactive form.
  • <input type="text">: Creates a text input field.
  • <textarea>: Defines a multi-line text input.
  • <select> and <option>: Creates a dropdown menu.
  • <button>: Adds a clickable button.
  • <label>: Labels form elements.
  • <fieldset> and <legend>: Groups form controls.

Interactive and Advanced Elements

  • <details> & <summary>: Adds expandable/collapsible content.
  • <dialog>: Defines a modal dialog box.
  • <progress>: Displays a progress bar.
  • <meter>: Represents a measurement.

HTML Attributes

Attributes provide additional information about an element and are placed within the opening tag.

Global Attributes (Applicable to Most Elements)

  • id: Provides a unique identifier.
  • class: Assigns a CSS class.
  • title: Displays tooltip text on hover.
  • lang: Specifies the language of the content.

Key Attributes

  • href: Specifies a link’s destination (used in <a>).
  • src: Defines the source of media elements like <img>, <audio>, and <video>.
  • alt: Provides alternative text for images.
  • target: Controls how a hyperlink opens (_blank, _self).
  • type: Defines the type of input field (text, password, email, etc.).
  • placeholder: Provides a hint for input fields.
  • required: Marks an input field as mandatory.
  • disabled: Disables an input field or button.
  • readonly: Makes an input field uneditable.
  • checked: Pre-selects checkboxes and radio buttons.
  • maxlength: Limits the number of characters in an input field.

HTML5-Specific Attributes

  • autofocus: Focuses an element when the page loads.
  • download: Enables file download links.
  • draggable: Allows an element to be dragged.
  • contenteditable: Makes an element editable.
  • spellcheck: Enables spellchecking in input fields.

Conclusion

HTML provides a rich set of elements, attributes, and APIs to create structured and interactive web pages. Mastering these components is crucial for web development. Keep exploring and implementing these elements to build functional and engaging websites!


Tags:

Post a Comment

0Comments

Post a Comment (0)