Chapter 2 Using HTML

📚 Chapter 2(1)_ Using HTML.pptx

Brief overview

This document introduces HyperText Markup Language (HTML) and its fundamental role in building web pages. Understanding these core concepts is essential for creating and structuring content for the internet.

Key points

  • Introduction to HTML, its purpose, and basic page structure.
  • Formatting text with headings, paragraphs, and visual styles.
  • Incorporating images, links, and organizing content with tables and lists.
  • Understanding and creating HTML forms with various input types.

1. Introduction to HTML

1.1 What is HTML?

HTML stands for Hyper Text Markup Language. It is the standard language used to create web pages.

HTML defines the structure of a web page using elements. These elements label content, telling the browser how to display it.

For example, an element can indicate "this is a heading" or "this is a paragraph."

1.1.1 Basic HTML structure

A basic HTML document has a specific structure. It begins with a <!DOCTYPE html> declaration, identifying the document as HTML5.

The <html> element is the root of the entire page. Inside it, the <head> section contains meta-information, such as the page title.

The <title> element specifies text shown in the browser tab or title bar. The <body><body> element contains all visible content, including headings, paragraphs, and images.

Key structure elements:

ElementPurpose
<!DOCTYPE html>Declares the document type as HTML5.
<html>The root element of an HTML page.
<head>Contains meta-information about the page.
<title>Sets the title shown in the browser tab.
<body><body>Contains all the visible content of the page.

1.2 Loading static web pages

When you enter a website's URL, your browser requests files from the web server. This includes HTML, CSS, and JavaScript files.

The server returns these files. The browser then interprets the HTML to display the static content.

1.3 Formatting text

HTML provides tags to format text and structure content.

1.3.1 Headings

Headings are used to organize content hierarchically. HTML offers six levels of headings, from <h1> (largest) to <h6> (smallest).

Heading levels:

TagSize
<h1>Largest
<h2>
<h3>
<h4>
<h5>
<h6>Smallest

1.3.2 Paragraphs

The <p> tag defines a paragraph of text. It creates a block of text separated from other content.

1.3.3 Line breaks and horizontal rules

A <br /> tag inserts a line break, forcing content onto the next line without creating a new paragraph. The <hr /> tag creates a horizontal rule, a thematic break between sections of content.

1.3.4 Alignment

Text alignment can be controlled using the align attribute within tags like <h1> or <p>. Common values include center and right.

Text alignment options:

Attribute ValueEffect
centerCenters text.
rightAligns text to the right.
left (default)Aligns text to the left.

1.4 Page formatting and divisions

HTML allows for page-level formatting, such as background color. The bgcolor attribute on the <body><body> tag sets the page's background color.

1.4.1 Creating divisions

The <div> element is a generic container. It groups other elements to apply styles or structure.

You can use inline styles directly within a <div> tag to control font size, color, and other properties for the enclosed content.

📝 Example: A <div> with style="font-size:24px; color:red;" will make its contained text red and 24 pixels in size.

1.5 Comments

Comments in HTML are not displayed by the browser. They are used for notes within the code.

Comments start with <!-- and end with -->.

🔑 Important: Use comments to explain code sections or to temporarily disable code snippets without deleting them.

🔑 Important: Comments help you or others understand the code later. They are also useful for experimenting with new code.

1.6 HTML tags and elements

HTML uses tags to define elements. Tags are enclosed in angle brackets, like <p>.

Elements consist of a start tag, content, and an end tag (e.g., <p>This is a paragraph.</p>). Some elements, like <br />, are self-closing.

1.7 Links

Links, created with the <a> tag, allow navigation between pages.

Link types:

Link TypeTag ExampleDescription
External link<a href="http://www.example.com">Link Text</a>Links to another website.
Internal link<a href="#section-id">Link Text</a>Links to a section within the same document.
Email link<a href="mailto:email@example.com">Email Us</a>Opens an email client with a pre-filled address.

1.8 Tables

Tables represent tabular data. They consist of rows (<tr>) and columns (<td>).

Table structure:

TagPurpose
<table>Defines the table.
<tr>Defines a table row.
<th>Defines a table header.
<td>Defines a table data cell.

You can add borders to tables using CSS within a <style> tag.

1.9 Lists

HTML supports three types of lists: unordered, ordered, and description lists.

1.9.1 Unordered lists

Unordered lists use bullet points. They are defined with <ul> (unordered list) and <li> (list item) tags.

You can change the bullet style using list-style-type in CSS (e.g., square, circle).

1.9.2 Ordered lists

Ordered lists use numbering or lettering. They are defined with <ol> (ordered list) and <li> tags.

The type attribute in <ol> controls the numbering style (e.g., 1, A, i).

1.9.3 Description lists

Description lists display terms and their definitions. They use <dl> (description list), <dt> (description term), and <dd> (description description) tags.

1.10 HTML forms

HTML forms collect user input. The <form> element encloses input fields.

1.10.1 Input elements

The <input> element is versatile. Its type attribute determines its appearance and function.

Common input types:

TypeDescription
textA single-line text field.
radioA radio button (select one option).
checkboxA checkbox (select multiple options).
submitA button to submit the form data.

🔑 Important: The id attribute uniquely identifies an input for CSS/JavaScript. The name attribute is used when submitting data to a server.

1.10.2 Dropdown lists

The <select> element creates a dropdown list. Each option within the list is defined by an <option> tag.

1.10.3 Text areas

The <textarea> element creates a multi-line text input field for longer text entries.

1.10.4 Buttons

A <button> element can trigger actions, such as displaying an alert message using JavaScript's onclick event.

1.10.5 Grouping form data

The <fieldset> element groups related form controls. The <legend> tag provides a caption for the fieldset.

🔑 Important: Grouping related form elements with <fieldset> improves the form's organization and accessibility.

🔑 Important: Use HTML elements correctly to build the structure of web pages. Mastering these tags is crucial for front-end development.

2. HTML tags and elements

2.1 Images and links

  • <img src="path/to/image.jpg" alt="Description of image">: Embeds an image into the page. The src attribute is the image's file path. The alt attribute provides alternative text for screen readers or if the image fails to load.
  • <a href="url">Link text</a>: Creates a hyperlink.
    • href attribute: Specifies the destination URL for external links or internal document anchors.
    • Internal links use <a name="anchor-name"></a> to define a target and <a href="#anchor-name"></a> to link to it.
    • Email links use <a href="mailto:email@example.com">Email us</a>.

2.2 Tables

HTML tables organize data into rows and columns.

  • <table>: Defines the entire table.
  • <tr>: Creates a table row.
  • <td>: Defines a standard data cell within a row.
  • <th>: Defines a header cell within a row, typically bold and centered.

📝 Example: A table with sibling names, ages, and statuses.

<table>
  <tr>
    <th>Sibling Name</th>
    <th>Age</th>
    <th>Status</th>
  </tr>
  <tr>
    <td>Zurina</td>
    <td>48</td>
    <td>Married</td>
  </tr>
</table>

🔑 Important: Use CSS (e.g., border: 1px solid black;) to style table borders, as the <table> tag itself does not render them by default.

2.3 Lists

HTML supports three main types of lists for organizing content.

  • Unordered Lists (<ul>): Display items with bullet points (default). You can change the bullet style using CSS (e.g., list-style-type: square; or circle;).
  • Ordered Lists (<ol>): Display items with numerical or alphabetical markers. The type attribute controls the marker style (e.g., type="1", type="A", type="i").
  • Description Lists (<dl>): Used for presenting terms and their descriptions.
    • <dt>: Defines a description term.
    • <dd>: Defines the description for a term.

📝 Example: A description list for hobbies.

<dl>
  <dt>Travelling</dt>
  <dd>- Visited Singapore, Thailand, Japan, and Korea.</dd>
  <dt>Hiking</dt>
  <dd>- Reached Gunung Kinabalu and Bukit Broga.</dd>
</dl>

2.4 HTML forms

Forms allow users to input data, which can then be submitted to a server.

2.4.1 Core form elements

  • <form>: The container for all form elements.
    • action attribute: Specifies where to send form data when submitted.
    • method attribute: Sets the HTTP method (e.g., GET or POST) for sending data.
  • <input>: The most versatile form element. Its type attribute defines its behavior.
  • <label>: Provides a descriptive label for an input element. The for attribute links it to an input's id.

2.4.2 Input types

Input TypeDescriptionExample HTML Snippet
textA single-line text input field.<input type="text" id="name" name="name" value="Your Name">
radioA radio button. Allows selecting one option from a group (shared name).<input type="radio" id="male" name="gender" value="Male">
checkboxA checkbox. Allows selecting multiple options from a group.<input type="checkbox" id="food1" name="food1" value="Food1">
submitA button that submits the form data.<input type="submit" value="Submit">
buttonA clickable button, often used with JavaScript.<button type="button" onclick="alert('Hello!')">Click Me</button>

2.4.3 Other form elements

  • <select>: Creates a drop-down list.
    • <option>: Defines an option within the <select> list.
  • <textarea>: Creates a multi-line text input field for longer text.
    • rows and cols attributes: Control the visible size of the text area.
  • <fieldset>: Groups related form elements visually.
    • <legend>: Provides a caption for the <fieldset>.

🔑 Important: The id attribute on an input element is crucial for associating <label> elements and for JavaScript/CSS manipulation. The name attribute is essential for sending data to the server.

🔑 Important: Use **bold** only for callout labels like **Example:** or **Important:**. For key terms within content, use <span style="color: #ff9f29; font-weight: 700;">highlighted term</span>.

🔑 Important: Always use full currency names (e.g., "dollars", "euros") instead of symbols (e.g., "USD", "EUR").

🔑 Important: Mathematical expressions must be enclosed in USD for inline or USDUSD for display math. Replace all asterisks * within math with \ast.

© 2026 Maeve. All rights reserved. This content is protected by copyright.

See also