Chapter 1 - Basics of HTML
Chapter 1 - Basics of HTML
❖ Introduction :
1. Structure :
HTML uses tags to structure content. Tags are enclosed in angle brackets `<
>`, and most tags come in pairs: an opening tag and a closing tag. The
content is placed between the opening and closing tags.
➔ Example:
```html
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
```
2. Elements :
HTML documents are made up of elements, which are defined by tags that
define the structure and content of web pages. Common elements include
headings, paragraphs, images, links, lists, tables, forms, etc.
3. Attributes :
Tags can have attributes that provide additional information about an element.
Attributes are always included in the opening tag and are usually in
name/value pairs like `name="value"`.
➔ Example:
```html
<a href="https://www.example.com">Visit our website</a>
4. Headings :
HTML includes six levels of headings, `<h1>` to `<h6>`, where `<h1>` is the
highest (most important) and `<h6>` is the lowest.
5. Paragraphs :
6. Links :
`<a>` tags are used to create hyperlinks. The `href` attribute specifies the
URL to link to.
7. **Images**: `<img>` tags are used to embed images. The `src` attribute
specifies the path to the image file.
8. Lists :
HTML supports ordered lists (`<ol>`), unordered lists (`<ul>`), and definition
lists (`<dl>`).
9. Tables :
Tables are created using `<table>`, `<tr>` for rows, `<td>` for data cells, and
`<th>` for header cells.
10. Forms :
HTML provides `<form>` tags to create forms for user input. Form elements
include `<input>`, `<textarea>`, `<select>`, etc.
11. Comments :
You can add comments in HTML using `<!-- comment here -->`. Comments
are not displayed in the browser and are used for notes or reminders.
HTML is the foundation for creating web pages and is often used in
conjunction with CSS (Cascading Style Sheets) for styling and JavaScript for
dynamic behaviour. Mastering HTML basics is essential for anyone interested
in web development.
- Tags usually come in pairs: an opening tag `<tag>` and a closing tag `</tag>`.
The closing tag includes a forward slash `/` before the tag name.
2. Attributes :
- HTML elements can have attributes that provide additional information about the
element.
- Attributes are placed within the opening tag and are usually in name/value pairs
like `name="value"`.
3. DOCTYPE Declaration :
- It specifies the version of HTML being used and helps browsers to render content
correctly.
- An HTML document starts with an `<html>` tag and includes `<head>` and
`<body>` sections.
- Example:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document Title</title>
</head>
<body>
<h1>Main Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
```
5. Whitespace :
- HTML ignores extra whitespace (spaces, tabs, newlines) between tags and within
tags.
6. Comments :
- HTML allows comments that are not displayed in the browser and are used for
adding notes or explanations within the code.
7. Self-Closing Tags :
- Some tags in HTML do not have a closing tag and are self-closed with a trailing
slash `/`.
- HTML tags and attribute names are case insensitive in practice, although
lowercase is recommended for consistency.
- Attribute values can be quoted with double quotes (`"`) or single quotes (`'`).
Double quotes are commonly used.
```html
<a href="https://www.example.com">Link</a>
<img src="image.jpg" alt="Description">
```
❖ Properties of HTML :
1. Id :
Specifies a unique identifier for an element. Used for styling with CSS or for
JavaScript manipulation.
```html
<div id="header">...</div>
```
2. Class :
Specifies one or more class names for an element, which can be used to
apply styles with CSS or select elements with JavaScript.
```html
<p class="intro">...</p>
```
3. Style :
Allows inline CSS styling for an element. This property directly applies CSS
rules to the element.
```html
4. Src :
```html
<img src="image.jpg" alt="Description">
```
5. Href :
```html
<a href="https://www.example.com">Visit Example</a>
```
6. Alt :
Provides alternative text for images, which is displayed if the image cannot be
loaded or read by screen readers.
```html
<img src="image.jpg" alt="Alternative text">
```
7. Title :
Adds a title or tooltip text to an element, typically displayed when the user
hovers over the element.
```html
<abbr title="World Health Organization">WHO</abbr>
```
8. Type :
Specifies the type of an `<input>` element, such as text, checkbox, radio, etc.
```html
<input type="text" name="username">
9. Value :
```html
<input type="text" value="Initial Value">
```
10. Disabled :
```html
<input type="text" disabled>
```
```html
<input type="text" value="Read Only" readonly>
```
These properties are essential for defining the structure, behavior, and
appearance of HTML elements within web pages. They provide flexibility and
control over how elements are displayed and interacted with by users.
❖ Role of HTML :
1. Defining Structure
2. Creating Content
3. Enabling Accessibility
4. Supporting SEO
5. Integrating with CSS and JavaScript
6. Facilitating Responsive Design
7. Adhering to Web Standards
1. Document Structure :
2. Headings :
4. Links :
5. Lists :
7. Tables :
10. Miscellaneous :
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Simple HTML Example</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a simple example of HTML.</p>
<img src="https://via.placeholder.com/400"
alt="Placeholder Image">
<p>HTML (HyperText Markup Language) is the standard
markup language for creating web pages.</p>
</body>
Output: