HTML Tags
HTML tags are the building blocks of an HTML document. They are used to structure and define the content within a web page. HTML tags are enclosed in angle brackets ("<" and ">") and consist of an opening tag and a closing tag. The opening tag denotes the start of an element, while the closing tag denotes its end. Some tags, called self-closing tags, don't require a closing tag and end with a forward slash ("/") before the closing angle bracket.
Following is an example of a basic HTML tag structure:
Let's break down the components of an HTML tag:
- Opening tag: It consists of the tag name and is enclosed in angle brackets. It marks the beginning of an element. For example, <tagname>.
- Closing tag: It is similar to the opening tag, but with a forward slash before the tag name. It marks the end of an element. For example, </tagname>.
- Content: It is the text or other HTML elements that go between the opening and closing tags. For example, "Content goes here".
HTML Attributes
HTML tags can have attributes, which provide additional information or modify the behavior of the element. Attributes are placed within the opening tag and consist of a name-value pair separated by an equals sign ("="). The value is usually enclosed in double quotes (""), although single quotes ('') are also allowed.
Following is an example of an HTML tag with attributes:
Commonly used HTML Tags
HTML tags serve different purposes and define various elements on a web page. Some commonly used tags include:
- <html>: Denotes the root element of an HTML document.
- <head>: Contains meta-information about the HTML document, such as the title and links to external stylesheets or scripts.
- <body>: Encloses the visible content of the web page.
- <h1>, <h2>, <h3>, etc.: Headings of different levels, with <h1> being the highest and <h6> being the lowest.
- <p>: Represents a paragraph of text.
- <a>: Creates a hyperlink to another web page or resource.
- <img>: Inserts an image into the web page.
- <div>: Defines a division or a container that can be used for grouping and styling purposes.
- <table>: Creates a table with rows (<tr>), columns (<td>), and headers (<th>).
- <form>: Defines a form for user input, such as text fields, checkboxes, and buttons.
These are just a few examples, and there are many more HTML tags available for different purposes.
HTML tags, when used together and nested appropriately, allow web developers to structure the content and create rich and interactive web pages. They provide a standardized way to define elements, which can then be styled using CSS (Cascading Style Sheets) and enhanced with JavaScript.