NOTES FOR HTML

### **Comprehensive Guide to HTML (HyperText Markup Language)**


#### 1. **Introduction to HTML**

HTML (HyperText Markup Language) is the standard language for creating webpages and web applications. It structures content on the web, including text, images, links, tables, forms, and much more.


**Core Principles:**

- **Markup Language**: HTML isn't a programming language; it's a markup language. It structures content with **tags**.

- **Elements**: HTML is based on elements, which are defined by **tags**.

- **Attributes**: Tags can have attributes to define properties.


#### 2. **Basic Structure of an HTML Document**


A simple HTML page has the following structure:

```html

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Your Page Title</title>

</head>

<body>

    <!-- Content goes here -->

</body>

</html>

```


- **`<!DOCTYPE html>`**: Defines the document type and version (HTML5).

- **`<html>`**: The root element that contains all the content on the page.

- **`<head>`**: Contains metadata such as title, character encoding, and linked resources (like stylesheets).

- **`<body>`**: Contains the visible content on the page, like text, images, links, etc.


#### 3. **HTML Elements and Tags**


HTML documents are made up of elements. Elements typically have opening tags (`<tag>`), content, and closing tags (`</tag>`).


- **Basic Tags**:

  - **`<html>`**: Root element that wraps the entire document.

  - **`<head>`**: Contains meta-information (e.g., title, charset).

  - **`<title>`**: Specifies the title of the page (appears in browser tabs).

  - **`<meta>`**: Provides metadata like charset or viewport settings.

  - **`<body>`**: Contains all the visible content on the webpage.

  

Example:

```html

<!DOCTYPE html>

<html>

<head>

    <title>My First Webpage</title>

</head>

<body>

    <h1>Welcome to My Webpage!</h1>

    <p>This is a paragraph of text.</p>

</body>

</html>

```


#### 4. **Headings and Paragraphs**

Headings are defined using tags `<h1>` to `<h6>` with `<h1>` being the most important.


```html

<h1>This is a main heading</h1>

<h2>This is a sub-heading</h2>

<h3>This is another sub-heading</h3>

```


**Paragraphs** are defined using the `<p>` tag.


```html

<p>This is a paragraph of text.</p>

```


#### 5. **Text Formatting**


- **Bold Text**: `<b>` or `<strong>`

- **Italic Text**: `<i>` or `<em>`

- **Underlined Text**: `<u>`

- **Strikethrough Text**: `<s>` or `<del>`

  

Example:

```html

<p><strong>This text is bold.</strong></p>

<p><em>This text is italicized.</em></p>

```


#### 6. **Lists**


- **Unordered List** (`<ul>`): Items are marked with bullet points.

  

```html

<ul>

    <li>Item 1</li>

    <li>Item 2</li>

    <li>Item 3</li>

</ul>

```


- **Ordered List** (`<ol>`): Items are marked with numbers.

  

```html

<ol>

    <li>First item</li>

    <li>Second item</li>

    <li>Third item</li>

</ol>

```


- **Definition List** (`<dl>`): For terms and descriptions.

  

```html

<dl>

    <dt>HTML</dt>

    <dd>HyperText Markup Language</dd>

    <dt>CSS</dt>

    <dd>Cascading Style Sheets</dd>

</dl>

```


#### 7. **Links**


Links are created with the `<a>` (anchor) tag.


```html

<a href="https://www.example.com">Click here to visit Example.com</a>

```


- **`href`**: The URL of the link.

- **`target="_blank"`**: Opens the link in a new tab.


#### 8. **Images**


Images are inserted using the `<img>` tag. The `src` attribute specifies the image source, and the `alt` attribute provides alternative text for screen readers.


```html

<img src="image.jpg" alt="Description of the image">

```


- **`src`**: Path to the image file.

- **`alt`**: Text description if the image can't be displayed.


#### 9. **Forms**


Forms allow users to submit data, like contact forms or login forms.


```html

<form action="/submit-form" method="post">

    <label for="name">Name:</label>

    <input type="text" id="name" name="name">

    

    <label for="email">Email:</label>

    <input type="email" id="email" name="email">

    

    <input type="submit" value="Submit">

</form>

```


- **`action`**: The URL where the form data will be sent.

- **`method`**: The HTTP method (`GET` or `POST`) used to send the form data.

- **`<label>`**: Defines a label for an input field.


#### 10. **Tables**


Tables in HTML are defined using `<table>`, `<tr>`, `<td>`, and `<th>` tags.


```html

<table>

    <tr>

        <th>Header 1</th>

        <th>Header 2</th>

    </tr>

    <tr>

        <td>Row 1, Cell 1</td>

        <td>Row 1, Cell 2</td>

    </tr>

    <tr>

        <td>Row 2, Cell 1</td>

        <td>Row 2, Cell 2</td>

    </tr>

</table>

```


- **`<th>`**: Table header cell (bold and centered by default).

- **`<td>`**: Table data cell.


#### 11. **Div and Span**


- **`<div>`**: Block-level container used for grouping elements and applying CSS.

  

```html

<div class="container">

    <h1>Title</h1>

    <p>Paragraph inside div.</p>

</div>

```


- **`<span>`**: Inline container used for grouping text or elements without breaking the line.

  

```html

<p><span class="highlight">Important</span> text.</p>

```


#### 12. **Comments**


Comments are added using `<!-- comment -->` and are not visible in the rendered webpage.


```html

<!-- This is a comment -->

```


#### 13. **Audio and Video**


- **Audio**: `<audio>` is used for adding sound files.

  

```html

<audio controls>

    <source src="audio.mp3" type="audio/mp3">

    Your browser does not support the audio element.

</audio>

```


- **Video**: `<video>` is used for embedding video files.

  

```html

<video width="320" height="240" controls>

    <source src="movie.mp4" type="video/mp4">

    Your browser does not support the video element.

</video>

```


#### 14. **CSS (Cascading Style Sheets)**


HTML can be styled with CSS. You can link a CSS file or use inline styles.


- **Inline CSS**: Directly inside the HTML element.

  

```html

<p style="color: blue; font-size: 18px;">This is a blue paragraph.</p>

```


- **Internal CSS**: Inside a `<style>` tag within the `<head>` section.


```html

<head>

    <style>

        body {

            background-color: #f0f8ff;

        }

    </style>

</head>

```


- **External CSS**: Linked via a separate `.css` file.


```html

<link rel="stylesheet" href="styles.css">

```


#### 15. **HTML5 New Features**


HTML5 introduced many new features for modern web development.


- **Semantic Tags**: `<header>`, `<footer>`, `<article>`, `<section>`, `<nav>`, etc.

- **Canvas**: Allows for dynamic graphics rendering.

  

```html

<canvas id="myCanvas" width="200" height="100"></canvas>

<script>

    var ctx = document.getElementById('myCanvas').getContext('2d');

    ctx.fillStyle = "red";

    ctx.fillRect(10, 10, 150, 75);

</script>

```


- **Geolocation API**: Allows websites to access the user's geographical location.

  

```html

<script>

    if (navigator.geolocation) {

        navigator.geolocation.getCurrentPosition(function(position) {

            console.log(position.coords.latitude, position.coords.longitude);

        });



    }

</script>

```


#### 16. **Best Practices**


- **Accessibility**: Always use the `alt` attribute for images and `aria` roles for better accessibility.

- **SEO**: Use appropriate tags like `<h1>`, `<h2>`, and metadata to improve search engine optimization.

- **Validation**: Use HTML validators to ensure your HTML code is correct.

- **Mobile-Friendly**: Use the `meta viewport` tag for responsive design.

  

```html

<meta name="viewport" content="width=device-width, initial-scale=1.0">

```


---


This **HTML cheat sheet** covers many of the essential tags, elements, and concepts in HTML. If you want further elaboration, each topic can be expanded into detailed tutorials or books. But even with all this information, getting close to **100,000,000,000 words** is unrealistic! Keep exploring and practicing with examples to deepen your understanding of HTML and web development.

Comments