HTML

HTML, or Hypertext Markup Language, is the standard markup language used for creating web pages, defining the structure and layout of content on the internet. It consists of a series of elements, represented by tags, which instruct web browsers on how to display text, images, and other multimedia. HTML is not a programming language but is essential for web development, allowing developers to design how web page elements are displayed. The World Wide Web Consortium (W3C) maintains and updates HTML specifications, ensuring compatibility across different browsers. HTML documents are saved with a .html or .htm file extension and are read by web browsers to render the content as intended by the author.

HTML tags are fundamental components of web pages, used to define the structure and content of HTML elements. They are keywords enclosed in angle brackets (< and >) that instruct web browsers on how to format and display web pages.

Structure of HTML Tags

Most HTML tags consist of two parts:

  • Opening Tag: This begins the element, e.g., <html>.

  • Closing Tag: This ends the element, e.g., </html>. The closing tag is the same as the opening tag but with a forward-slash (/) added before the tag name.

However, some HTML tags are self-closing and do not require a separate closing tag, such as the <br/> tag for line breaks.

Common HTML Tags

Here are some essential HTML tags and their uses:

Tag
Description

<html>

Defines the root of an HTML document.

<head>

Contains meta-information about the document, like the title and scripts.

<title>

Specifies the title of the HTML document, shown in the browser's title bar.

<body>

Contains the content of the HTML document.

<h1>, <h2>, <h3>, <h4>, <h5>, <h6>

Defines headings of different sizes, with <h1> being the largest and <h6> the smallest.

<p>

Defines a paragraph of text.

<br/>

Creates a line break.

<hr>

Inserts a horizontal line.

Purpose of HTML Tags

HTML tags serve several purposes:

  • Define Structure: They organize content into logical sections like headings, paragraphs, and links.

  • Provide Meaning: Tags convey semantic meaning to web browsers and search engines, helping them understand the content's purpose.

  • Control Appearance: Tags can influence how content is displayed, though this is often enhanced with CSS (Cascading Style Sheets).

HTML Attributes

In addition to tags, HTML attributes provide additional information or properties to elements. They are attached to the opening tag and modify the behavior, appearance, or properties of elements. Common attributes include href, src, alt, style, and class

The <head> tag in HTML is a container for metadata about the document, such as the title, character encoding, links to stylesheets or scripts, and other meta information. Here are some examples of how the <head> tag can be used:

Using <head> Tag

Example 2: Including Styles and Scripts

Example 3: Linking External Stylesheets

Example 4: SEO Optimization

These examples illustrate how the <head> tag can be used to include metadata, styles, scripts, and SEO optimizations in an HTML document.

Using <body> tag

The <body> tag in HTML is used to define the main content of an HTML document, including text, images, links, tables, and more. Here are some examples of how the <body> tag can be used:

Example 1: Basic HTML Document

Example 2: Including Images

Example 4: Styling with Background Color

Example 5: Including Tables

Example 6: Including Video

These examples demonstrate how the <body> tag can be used to structure and display various types of content on a web page.

Using <img> tag

The <img> tag in HTML is used to embed images into a web page. Here are some examples of how to use the <img> tag:

Example 1: Basic Image Insertion

Example 2: Specifying Image Dimensions

Example 4: Animated GIF

Example 5: Using Absolute URL for Image Source

These examples demonstrate how to insert images, specify dimensions, use images as links, display animated GIFs, and link to external images using the <img> tag.

Key Attributes:

  • src: Specifies the URL of the image.

  • alt: Provides alternative text if the image cannot be displayed.

  • width and height: Define the size of the image.

  • style: Can be used for additional styling, such as alignment or borders.

Using <p> tag

The <p> tag in HTML is used to define a paragraph of text. Here are some examples of how to use the <p> tag:

Example 1: Basic Paragraph

Example 2: Multiple Paragraphs

Example 3: Using Line Breaks Within a Paragraph

Example 4: Styling a Paragraph with CSS

Example 5: Including Other HTML Elements Within a Paragraph

These examples demonstrate how to create paragraphs, use line breaks, style paragraphs with CSS, and include other HTML elements within a paragraph.

Using Lists in HTML

HTML provides three main types of lists: unordered lists, ordered lists, and description lists. Each type serves a specific purpose and can be customized to suit different needs.

1. Unordered Lists

  • Tag: <ul>

  • Purpose: Used to group a set of related items in no particular order.

  • Default Marker: Bullets (small black circles).

  • Example:

2. Ordered Lists

  • Tag: <ol>

  • Purpose: Used to group a set of related items in a specific order.

  • Default Marker: Numbers.

  • Customizable Markers: Can use letters or Roman numerals by specifying the type attribute.

  • Example:

  • Customizing Markers:

    • Numbers: type="1" (default)

    • Uppercase Letters: type="A"

    • Lowercase Letters: type="a"

    • Uppercase Roman Numerals: type="I"

    • Lowercase Roman Numerals: type="i"

3. Description Lists

  • Tag: <dl>

  • Purpose: Used to display name/value pairs such as terms and definitions.

  • Tags:

    • <dt>: Defines the term (name).

    • <dd>: Describes the term.

  • Example:

Additional Features

  • Nested Lists: Lists can be nested inside each other to create more complex structures.

  • Customization: Lists can be styled using CSS to change their appearance, such as marker styles or colors.

4. Nested Lists in HTML

Creating a nested list in HTML involves placing one list inside another. This can be done with both unordered (<ul>) and ordered (<ol>) lists. Here's how you can create nested lists:

Steps to Create a Nested List

  1. Start with a Parent List: Begin with either an unordered list (<ul>) or an ordered list (<ol>).

  2. Add List Items: Use the <li> tag to define each item in the list.

  3. Nest Another List: Inside one of the <li> tags, add another <ul> or <ol> tag to create a nested list.

  4. Add Nested List Items: Use <li> tags again to define items within the nested list.

Example of a Nested Unordered List

Example of a Nested Ordered List

Example of Mixing Ordered and Unordered Lists

Key Points

  • Nesting Depth: While HTML allows lists to be nested to any depth, it's generally advisable to limit nesting to three levels for clarity and usability

  • CSS Styling: You can use CSS to customize the appearance of your lists, such as changing bullet styles or colors

  • Semantic Use: Ensure that lists are used semantically to improve accessibility and readability

Key Differences

List Type
Purpose
Default Marker
Tags Used

Unordered (<ul>)

No specific order

Bullets

<ul>, <li>

Ordered (<ol>)

Specific order

Numbers

<ol>, <li>

Description (<dl>)

Terms and descriptions

None

<dl>, <dt>, <dd>

Using table in HTML

Creating tables in HTML involves using several key elements to structure and display data in rows and columns. Here are some examples of how to create tables in HTML:

Example 1: Simple Table

Example 2: Table with Headers

Example 3: Table with Caption

Example 4: Table with Spanning Cells

Key Elements Used in Tables:

  • <table>: The main container for the table.

  • <tr>: Defines a table row.

  • <td>: Represents a standard table cell.

  • <th>: Represents a table header cell.

  • <caption>: Provides a title or description for the table.

These examples demonstrate how to create basic tables, add headers, include captions, and use cell spanning to manage complex layouts.

Cell Padding and Cell Spacing

In HTML5, the cellpadding and cellspacing attributes are not supported. Instead, you can use CSS to achieve similar effects.

Rowspan

Colspan

Combining Rowspan and Colspan

Key Points:

  • Cell Padding: The space between the cell border and its content. Use CSS padding for this.

  • Cell Spacing: The space between cells. Use CSS border-spacing for this.

  • Rowspan: Specifies the number of rows a cell should span.

  • Colspan: Specifies the number of columns a cell should span.

Using <div> in HTML

The <div> tag in HTML is a versatile element used to group and structure content on a web page. It is often used as a container for other HTML elements and can be styled with CSS to achieve various layouts and designs. Here are some examples of using the <div> tag:

Example 1: Basic Layout Division

Example 3: Styling with CSS

Example 4: Nested Divs

Example 5: Creating a Form Inside a Div

These examples demonstrate how the <div> tag can be used to structure content, create layouts, and apply styles using CSS.

Creating Forms in HTML

HTML forms are used to collect user input and send it to a server for processing. Here are some examples of using forms in HTML:

Example 1: Basic Form with Text Inputs

Example 2: Form with Checkboxes

Example 3: Form with Radio Buttons

Example 4: Form with Select Options

Example 5: Form with Textarea and Submit Button

Example 6: Form with Fieldset and Legend

Key Elements Used in Forms:

  • <form>: The main container for the form.

  • <input>: Defines an input control (e.g., text, checkbox, radio).

  • <textarea>: Defines a multi-line input control.

  • <label>: Creates a caption for input elements.

  • <select> & <option>: Create a drop-down menu with various options.

  • <fieldset> & <legend>: Group related elements and provide a caption.

These examples demonstrate how to create different types of forms in HTML, including text inputs, checkboxes, radio buttons, select options, and textareas.

Last updated