HTML Input attributes

An HTML input attribute is a property or setting applied to an <input> element in an HTML form that defines the behavior, appearance, or constraints of that input field. Attributes provide additional information about how the input should function, such as specifying the type of data the input should accept, setting a default value, or enforcing validation rules. Here are some commonly used attributes:

1. type: Specifies the type of input element.


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

2. name: Specifies the name of the input element, which is used to reference the form data after it is submitted.


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

3. value: Specifies the initial value of the input element.


<input type="text" name="firstName" value="John">

4. placeholder: Provides a short hint that describes the expected value of the input field.


<input type="text" name="firstName" placeholder="Enter your First Name">

5. required: Specifies that an input field must be filled out before submitting the form.


<input type="text" name="firstName" required>

6. readonly: Makes the input field read-only.


<input type="text" name="firstName" value="John" readonly>

7. disabled: Disables the input field, making it uneditable and non-submittable.


<input type="text" name="firstName" disabled>

8. maxlength: Specifies the maximum number of characters allowed in the input field.


<input type="text" name="firstName" maxlength="10">

9. minlength: Specifies the minimum number of characters required in the input field.


<input type="text" name="firstName" minlength="5">

10. min and max: Specifies the minimum and maximum values for numeric input fields.


<input type="number" name="age" min="18" max="90">

11. step: Specifies the legal number intervals for numeric input fields.


<input type="number" name="quantity" step="2">

12. pattern: Specifies a regular expression that the input field’s value must match


<input type="text" name="email" pattern="/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/">

13. autocomplete: Specifies whether the input field should have autocomplete enabled.


<input type="text" name="firstName" autocomplete="on">

14. autofocus: Specifies that the input field should automatically get focus when the page loads.


<input type="text" name="firstName" autofocus>

15. multiple: Allows multiple values to be entered in an input field.


<input type="file" name="files" multiple>

16. size: Specifies the visible width, in characters, of the input field.


<input type="text" name="firstName" size="10">

HTML Form elements

HTML form elements are used to collect user input. Here are some of the most commonly used form elements:

1. Form (<form>):

The container for all form elements.


<form action="/submit" method="post">
    <!-- form elements go here -->
</form>

2. Input (<input>): Used for various types of user input.


<!-- Text input -->
<input type="text" name="username">

<!-- Password input -->
<input type="password" name="password">

<!-- Checkbox input -->
<input type="checkbox" name="remember_me">

<!-- Radio button input -->
<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female"> Female

<!-- Submit button -->
<input type="submit" value="Submit">

3. Label (<label>): Used to define labels for input elements.


<label for="username">Username:</label>
<input type="text" id="username" name="username">

4. TextArea (<textarea>): Multi-line text input.


<textarea name="message" rows="4" cols="50"></textarea>

5. Select (<select>): Dropdown list.


<select name="options">
    <option value="option1">Option 1</option>
    <option value="option2">Option 2</option>
    <option value="option3">Option 3</option>
</select>

6. Button (<button>): Button element.


<button type="submit">Submit</button>

7. Fieldset (<fieldset>) and Legend (<legend>): Used to group related elements and provide a caption.


<fieldset>
    <legend>Personal Information</legend>
    <label for="firstname">First name:</label>
    <input type="text" id="firstname" name="firstname">
    <label for="lastname">Last name:</label>
    <input type="text" id="lastname" name="lastname">
</fieldset>

8. Datalist (<datalist>): Provides a list of predefined options for an input element.


<input list="browsers" name="browser">
<datalist id="browsers">
    <option value="Chrome">
    <option value="Firefox">
    <option value="Safari">
    <option value="Edge">
    <option value="Opera">
</datalist>

9. Output (<output>): Represents the result of a calculation or user action.


<output name="result" for="a b">0</output>

10. Input types: There are many other types of input elements, such as color, date, email, file, number, range, search, tel, time, url, etc.


<!-- Date input -->
<input type="date" name="birthday">

<!-- Email input -->
<input type="email" name="email">

<!-- Number input -->
<input type="number" name="quantity" min="1" max="10">

HTML form attributes

HTML form attributes control various aspects of how a form behaves and interacts with the user. Here’s a detailed look at some of the key HTML form attributes:

1. action

Specifies the URL where the form data should be sent when the form is submitted.


<form action="/submit-form">
2. method

Defines the HTTP method (either GET or POST) used to send form data.


<form method="post">

GET: Appends form data to the URL (not recommended for sensitive data).

POST: Sends form data as part of the HTTP request body (more secure for sensitive data).

3. target

Specifies where to open the response after form submission.


<form target="_blank">

_blank: Opens in a new tab or window.

_self: Opens in the same frame as the form.

_parent: Opens in the parent frame.

_top: Opens in the full window.

4. enctype

Specifies how the form data should be encoded when submitting it to the server. Used with POST method.


<form enctype="multipart/form-data">

application/x-www-form-urlencoded: Default encoding, suitable for most forms.

multipart/form-data: Used for forms that include file uploads.

text/plain: Submits data as plain text (rarely used).

5. autocomplete

Controls whether the browser should automatically complete fields based on previous entries.


<form autocomplete="on">

on: Enables auto-completion.

off: Disables auto-completion.

6. novalidate

Disables form validation when submitting the form.


<form novalidate>
7. name

Assigns a name to the form, which can be used for referencing it in scripts.


<form name="myForm">
8. accept-charset

Specifies the character encodings that the server can handle.


<form accept-charset="UTF-8">

Example Form Using Various Attributes


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Form with Attributes</title>
</head>
<body>
    <h2>Form with Various Attributes</h2>
    <form action="/submit-form" 
          method="post" 
          target="_blank" 
          enctype="multipart/form-data" 
          autocomplete="on" 
          novalidate 
          accept-charset="UTF-8">
        
        <!-- Text Input -->
        <label for="username">Username:</label><br>
        <input type="text" id="username" name="username" placeholder="Enter your username" required><br><br>

        <!-- Password Input -->
        <label for="password">Password:</label><br>
        <input type="password" id="password" name="password" minlength="6" required><br><br>

        <!-- Email Input -->
        <label for="email">Email:</label><br>
        <input type="email" id="email" name="email" required><br><br>

        <!-- File Upload -->
        <label for="resume">Upload Resume:</label><br>
        <input type="file" id="resume" name="resume" accept=".pdf,.doc,.docx"><br><br>

        <!-- Submit Button -->
        <input type="submit" value="Submit">
    </form>
</body>
</html>

HTML Form

HTML forms are used to collect user input. They are essential for tasks such as user registration, login, and submitting information. A form can include various input elements like text fields, radio buttons, checkboxes, and more.

HTML input element

The HTML <input> element is a versatile and essential part of web forms, allowing users to enter data in various formats. Different types of <input> elements can be used to capture a wide range of user input, from text and numbers to dates and files. Each type of input can have specific attributes to customize its behavior.

Text input


 <form>
	<!-- Text Input -->
	<label for="username">Username:</label><br>
	<input type="text" id="username" name="username" placeholder="Enter your username">
</form>

Password Input


 <form>
	 <label for="password">Password:</label><br>
     <input type="password" id="password" name="password" minlength="6">
</form>


Email Input


 <form>
	    <label for="email">Email:</label><br>
        <input type="email" id="email" name="email">
</form>

Radio Buttons


 <form>
  <label>Gender:</label><br>
        <input type="radio" id="male" name="gender" value="male" checked>
        <label for="male">Male</label><br>
        <input type="radio" id="female" name="gender" value="female">
        <label for="female">Female</label>
</form>


Checkboxes


<form>
<label>Hobbies:</label><br>
        <input type="checkbox" id="hobby1" name="hobbies" value="reading">
        <label for="hobby1">Reading</label><br>
        <input type="checkbox" id="hobby2" name="hobbies" value="traveling">
        <label for="hobby2">Traveling</label><br>
        <input type="checkbox" id="hobby3" name="hobbies" value="gaming">
        <label for="hobby3">Gaming</label>
</form>



Dropdown Select


<form>
 <label for="country">Country:</label><br>
        <select id="country" name="country">
            <option value="in">India</option>
            <option value="us">Unites States</option>
            <option value="uk">United Kingdom</option>
            <option value="au">Australia</option>
        </select>
</form>

File Upload


<form>
<label for="resume">Upload Resume:</label><br>
<input type="file" id="resume" name="resume" accept=".pdf,.doc,.docx">
</form>

Number Input


<form>
<label for="age">Age:</label><br>
<input type="number" id="age" name="age" min="18" max="100">
</form>

Date Input


<form>
<label for="dob">Date of Birth:</label><br>
<input type="date" id="dob" name="dob">
</form>

HTML Responsive

HTML responsive design refers to the practice of creating web pages that adapt and provide an optimal viewing experience across a wide range of devices, including desktops, tablets, and mobile phones. This involves using flexible layouts, images, and CSS media queries to ensure that the content is readable and accessible on any device.

Key Concepts in Responsive Design

1. Viewport Meta Tag: Controls the layout on mobile browsers.

2. Flexible Grid Layouts: Uses relative units like percentages instead of fixed units like pixels.

3. Flexible Images: Ensures images scale within their containing elements.

4. CSS Media Queries: Applies different styles for different screen sizes.

Viewport Meta Tag

The viewport meta tag is essential for responsive web design. It ensures that the web page is properly scaled on mobile devices.


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

Flexible Grid Layouts

Using relative units like percentages allows your layout to adapt to various screen sizes.


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Responsive Grid Layout</title>
    <style>
        .container {
            display: flex;
            flex-wrap: wrap;
        }
        .item {
            flex: 1 1 100%; /* Flex-grow, flex-shrink, and flex-basis */
            box-sizing: border-box;
            padding: 10px;
        }
        @media (min-width: 600px) {
            .item {
                flex: 1 1 50%; /* Two columns layout for screens 600px and up */
            }
        }
        @media (min-width: 900px) {
            .item {
                flex: 1 1 33.33%; /* Three columns layout for screens 900px and up */
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="item" style="background-color: lightcoral;">Item 1</div>
        <div class="item" style="background-color: lightblue;">Item 2</div>
        <div class="item" style="background-color: lightgreen;">Item 3</div>
    </div>
</body>
</html>

Flexible Images

Make images responsive by setting their maximum width to 100% of their containing element.


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Responsive Images</title>
    <style>
        img {
            max-width: 100%;
            height: auto;
        }
    </style>
</head>
<body>
    <img src="image.jpg" alt="Responsive Image">
</body>
</html>

CSS Media Queries

Media queries allow you to apply different styles based on the device’s characteristics, such as width, height, and orientation.


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Responsive Design with Media Queries</title>
    <style>
        body {
            font-family: Arial, sans-serif;
        }
        .container {
            padding: 20px;
        }
        .box {
            background-color: lightblue;
            padding: 20px;
            margin: 10px 0;
        }
        @media (min-width: 600px) {
            .box {
                background-color: lightgreen;
            }
        }
        @media (min-width: 900px) {
            .box {
                background-color: lightcoral;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="box">Resize the browser window to see the effect.</div>
    </div>
</body>
</html>

Frameworks for Responsive Design

Several CSS frameworks provide built-in responsiveness and can speed up the development process. Popular frameworks include:

Bootstrap: Uses a grid system and responsive utilities.

HTML Head

The <head> element in HTML is a container for metadata (data about data) and links to external resources that are related to the document. It is placed between the <html> and <body> tags and typically includes information such as the document title, character set, styles, scripts, and other meta-information.

Common Elements in the <head>

1. <title>: Specifies the title of the document, which is displayed in the browser’s title bar or tab.

2. <meta>: Provides metadata such as character set, author, description, keywords, and viewport settings.

3. <link>: Links to external resources like stylesheets, icons, and prefetching.

4. <style>: Embeds internal CSS styles.

5. <script>: Embeds or links to JavaScript code.

Example

Here’s a basic example of a <head> section:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="A brief description of the page">
    <meta name="keywords" content="HTML, CSS, JavaScript, tutorial">
    <meta name="author" content="Your Name">
    <title>Document Title</title>
    <link rel="stylesheet" href="styles.css">
    <link rel="icon" href="favicon.ico" type="image/x-icon">
    <style>
        /* Internal CSS */
        body {
            font-family: Arial, sans-serif;
        }
    </style>
    <script src="script.js" defer></script>
</head>
<body>
    <!-- Page content goes here -->
</body>
</html>

Explanation of the Example

1. <meta charset="UTF-8">: Sets the character encoding for the document to UTF-8.

2. <meta name="viewport" content="width=device-width, initial-scale=1.0">: Ensures proper rendering and touch zooming on mobile devices.

3. <meta name="description" content="A brief description of the page">: Provides a short description of the page, useful for search engines.

4. <meta name="keywords" content="HTML, CSS, JavaScript, tutorial">: Lists keywords relevant to the page content, aiding in SEO.

5. <meta name="author" content="Your Name">: Specifies the author of the document.

6. <title>Document Title</title>: Sets the title of the web page.

7. <link rel="stylesheet" href="styles.css">: Links to an external CSS stylesheet.

8. <link rel="icon" href="favicon.ico" type="image/x-icon">: Links to the favicon of the website.

9. <style>: Contains internal CSS styles.

10. <script src="script.js" defer></script>: Links to an external JavaScript file with the defer attribute, ensuring the script is executed after the document has been parsed.

Importance of the <head> Element

SEO: Meta tags like description and keywords help search engines understand the content and relevance of the page.

Accessibility: Proper metadata can improve the accessibility of the webpage.

Performance: External resources such as stylesheets and scripts linked in the <head> can be loaded efficiently to optimize page performance.

User Experience: The title and favicon enhance the user experience by providing meaningful information and visual cues.

By organizing these elements within the <head>, you can ensure that your webpage is well-optimized, accessible, and user-friendly.

HTML JavaScript

HTML and JavaScript are often used together to create interactive and dynamic web pages. JavaScript is a programming language that can manipulate the content, structure, and style of a web page in real-time. You can embed JavaScript directly within HTML documents or link to external JavaScript files.

Embedding JavaScript in HTML

There are several ways to include JavaScript in an HTML document:

1. Inline JavaScript: Using the script tag directly within the HTML.

2. Internal JavaScript: Including JavaScript in the head or body of the HTML document within script tags.

3. External JavaScript: Linking to a separate JavaScript file.

Inline JavaScript

You can write JavaScript directly within HTML tags using the onclick, onload, and other event attributes.


<!DOCTYPE html>
<html lang="en">
<head>
    <title>Inline JavaScript Example</title>
</head>
<body>
    <button onclick="alert('Button clicked!')">Click Me</button>
</body>
</html>

Internal JavaScript

You can include JavaScript code within script tags inside the head or body of the HTML document.


<!DOCTYPE html>
<html lang="en">
<head>
    <title>Internal JavaScript Example</title>
    <script>
        function showMessage() {
            alert('Hello, World!');
        }
    </script>
</head>
<body>
    <button onclick="showMessage()">Click Me</button>
</body>
</html>

External JavaScript

You can create a separate JavaScript file and link to it using the src attribute of the script tag.

app.js


function showMessage() {
    alert('Hello, World!');
}

index.html


<!DOCTYPE html>
<html lang="en">
<head>
    <title>External JavaScript Example</title>
    <script src="app.js"></script>
</head>
<body>
    <button onclick="showMessage()">Click Me</button>
</body>
</html>

HTML Iframe

An HTML <iframe> (Inline Frame) is used to embed another HTML document within the current document. This allows you to display a webpage within a webpage, making it a powerful tool for including external content such as videos, maps, or other web applications.

Syntax

The basic syntax for an <iframe> is:


<iframe src="URL" width="width" height="height"></iframe>

Iframe Attributes

src: Specifies the URL of the document to be embedded.

width: Sets the width of the iframe (in pixels or as a percentage).

height: Sets the height of the iframe (in pixels or as a percentage).

allow: Specifies a feature policy for the iframe.

allowfullscreen: Allows the iframe to be viewed in full-screen mode.

loading: Specifies the loading behavior of the iframe (lazy or eager).

Example: Here’s an example of how to use an <iframe> to embed a Google website:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Iframe Example</title>
</head>
<body>
    <h1>Embedding a Google Map</h1>
    <div class="iframe-container">
        <iframe src="https://www.google.com" allowfullscreen loading="lazy">
        </iframe>
    </div>
</body>
</html>

Explanation of the Example

1. HTML Structure: The document includes a heading and a div container for the iframe.

Iframe Source: The src attribute is set to the URL of a Google Map embed link.

Use Cases:

Embedding Videos: Commonly used to embed YouTube or Vimeo videos.

Displaying Maps: Embed maps from services like Google Maps.

Including External Web Pages: Display content from another website or application within your site.

HTML Id

HTML id attributes are used to uniquely identify an element within an HTML document. Unlike classes, which can be applied to multiple elements, an id should be unique within the document. This uniqueness makes id attributes particularly useful for styling specific elements and for selecting elements with JavaScript.

Syntax

To add an id to an HTML element, use the id attribute:


<tag id="unique-id">Content</tag>

Where tag is HTML element like <div>, <p>, etc.

Example

Here’s an example demonstrating how to use id in HTML:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Id Example</title>
    <style>
        #header {
            background-color: blue;
            color: white;
            padding: 10px;
            text-align: center;
        }
        #content {
            padding: 20px;
            background-color: lightgrey;
        }
        #footer {
            background-color: blue;
            color: white;
            padding: 10px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div id="header">
        <h1>Header Section</h1>
    </div>
    <div id="content">
        <p>This is the main content area.</p>
    </div>
    <div id="footer">
        <p>Footer Section</p>
    </div>
</body>
</html>

Explanation of the Example

1. HTML Structure: The HTML document includes three main sections: header, content, and footer.

2. Id Assignment: Each section is assigned an id (header, content, footer) using the id attribute.

3. CSS Styling: In the <style> block, each id is styled

  • #header: Blue background, white text, padding, and center-aligned text.
  • #content: Light grey background and padding.
  • #footer: Similar styling to the header.

Benefits of Using Ids

Uniqueness: Ensures that each id is unique within the document, providing a way to specifically target individual elements.

Specificity: Provides higher specificity in CSS, which can be useful for overriding other styles.

JavaScript Targeting: Easily select and manipulate elements with JavaScript using methods like getElementById.

JavaScript Example

Ids are commonly used in JavaScript to access and manipulate specific elements:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript Id Example</title>
    <style>
        #header {
            background-color: blue;
            color: white;
            padding: 10px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div id="header">
        <h1>Header Section</h1>
    </div>
    <button onclick="changeHeaderColor()">Change Header Color</button>

    <script>
        function changeHeaderColor() {
            document.getElementById('header').style.backgroundColor = 'green';
        }
    </script>
</body>
</html>

Explanation of the JavaScript Example

1. HTML Structure: The document includes a header and a button.

2. Id Assignment: The header div is assigned an id of header.

3. JavaScript Function: The changeHeaderColor function uses getElementById to select the header element and change its background color to green when the button is clicked.

By using id attributes effectively, you can create specific, targeted styles and behaviors for individual elements within your web pages.

HTML Classes

HTML classes are used to group elements for styling and scripting purposes. By assigning a class attribute to HTML elements, you can apply specific styles and behaviors to those elements using CSS and JavaScript.

Syntax

To add a class to an HTML element, use the class attribute:


<tag class="class-name">Content</tag>

Benefits of Using Classes

Reusability: Apply the same styles to multiple elements by using the same class name.

Maintainability: Easily update styles in one place by modifying the CSS for a class.

Organization: Helps to keep the HTML structure organized and readable.

JavaScript Targeting: Classes can be used to select and manipulate elements with JavaScript.

Example

Here’s an example demonstrating how to use classes in HTML:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Classes Example</title>
    <style>
        .header {
            background-color: blue;
            color: white;
            padding: 10px;
            text-align: center;
        }
        .content {
            padding: 20px;
            background-color: lightgrey;
        }
        .footer {
            background-color: blue;
            color: white;
            padding: 10px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>Header Section</h1>
    </div>
    <div class="content">
        <p>This is the main content area.</p>
    </div>
    <div class="footer">
        <p>Footer Section</p>
    </div>
</body>
</html>

Explanation of the Example

  1. HTML Structure: The HTML document includes three main sections: header, content, and footer.
  2. Class Assignment: Each section is assigned a class (header, content, footer) using the class attribute.
  3. CSS Styling: In the <style> block, each class is styled:
    • .header: Blue background, white text, padding, and center-aligned text.
    • .content: Light grey background and padding.
    • .footer: Similar styling to the header.

Multiple Classes

An element can have multiple classes, separated by spaces:


<div class="class1 class2">Content</div>

This allows for combining different styles and behaviors for a single element.

Example with Multiple Classes


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Multiple Classes Example</title>
    <style>
        .highlight {
            background-color: yellow;
        }
        .italic {
            font-style: italic;
        }
    </style>
</head>
<body>
    <p class="highlight italic">This paragraph is highlighted and italicized.</p>
</body>
</html>

In this example, the paragraph is both highlighted and italicized by combining the highlight and italic classes.

HTML Div

An HTML <div> is a block-level element used to group other HTML elements together. It’s often used for styling and layout purposes with CSS and can contain various other HTML elements such as text, images, links, and other nested <div> elements.

Basic Syntax


<div>
  <!-- Content goes here -->
</div>

Characteristics of <div>:

Block-Level Element: Occupies the full width available and starts on a new line.

Generic Container: Can contain various other HTML elements such as text, images, links, other nested <div> elements, etc.

No Default Styling: By itself, it doesn’t apply any styles or formatting, making it a flexible tool for layout and design.

Example:

Here’s an example of how a <div> can be used to structure a simple webpage:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Example Div</title>
    <style>
        .container {
            width: 100%;
            background-color: lightgrey;
        }
        .header {
            background-color: blue;
            color: white;
            padding: 10px;
        }
        .content {
            padding: 20px;
        }
        .footer {
            background-color: blue;
            color: white;
            padding: 10px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>Header</h1>
        </div>
        <div class="content">
            <p>This is the content area.</p>
        </div>
        <div class="footer">
            <p>Footer</p>
        </div>
    </div>
</body>
</html>

Explanation of the Example:

Container Div: The .container div wraps the entire content, creating a main container for the page.

Header Div: The .header div contains the header section, styled with a blue background and white text.

Content Div: The .content div holds the main content, with padding applied for spacing.

Footer Div: The .footer div contains the footer, styled similarly to the header.

HTML Block and Inline

In HTML, elements are classified as either block-level elements or inline elements. This classification determines how the elements are rendered on the web page.

Block-Level Elements

Always start on a new line.

Take up the full width available (stretches out to the left and right as far as it can).

Have top and bottom margins.

Can contain other block-level elements and inline elements.

Examples of block-level elements include:

  • <div>
  • <p>
  • <h1> to <h6>
  • <ul> and <ol>
  • <li>
  • <table>
  • <header>
  • <footer>
  • <section>
  • <article>

Example:


<div>
  <h1>Title</h1>
  <p>This is a paragraph inside a div.</p>
</div>
Inline Elements

Do not start on a new line.

Only take up as much width as necessary.

Do not force other content to move to a new line.

Can only contain other inline elements or text content.

Examples of inline elements include:

  • <span>
  • <a>
  • <img>
  • <strong> and <b>
  • <em> and <i>
  • <code>
  • <br>

Example:


<p>This is a paragraph with <strong>bold text</strong> and <em>italic text</em>.</p>

Key Differences

  1. Rendering: Block-level elements create larger blocks of content, whereas inline elements are contained within block-level elements and do not disrupt the flow of content.
  2. Containment: Block-level elements can contain both block-level and inline elements, while inline elements can only contain other inline elements or text.

HTML Lists

HTML lists are used to group related items together, and there are three main types of lists in HTML:

1. Ordered List (<ol>): Used to create a list of items where the order matters. Each list item is numbered.

2. Unordered List (<ul>): Used to create a list of items where the order doesn’t matter. Each list item is typically marked with a bullet point.

3. Definition List (<dl>): Used to create a list of terms and their definitions.

Ordered List (<ol>)

An ordered list is created using the <ol> tag, and each item within the list is wrapped in an <li> (list item) tag.

Example:


<ol>
  <li>First item</li>
  <li>Second item</li>
  <li>Third item</li>
</ol>

This would render as:

  1. First item
  2. Second item
  3. Third item

Unordered List (<ul>)

An unordered list is created using the <ul> tag, and like ordered lists, each item is wrapped in an <li> tag.

Example:


<ul>
  <li>Item one</li>
  <li>Item two</li>
  <li>Item three</li>
</ul>

This would render as:

  • Item one
  • Item two
  • Item three

Definition List (<dl>)

A definition list is created using the <dl> tag. Inside a definition list, each term is wrapped in a <dt> (definition term) tag, and each definition is wrapped in a <dd> (definition description) tag.

Example:


<dl>
  <dt>HTML</dt>
  <dd>A markup language for creating web pages</dd>
  <dt>CSS</dt>
  <dd>A style sheet language for describing the presentation of a document</dd>
</dl>

This would render as:

HTML: A markup language for creating web pages

CSS: A style sheet language for describing the presentation of a document

Nesting Lists

Lists can be nested within each other to create more complex structures.

Example:


<ul>
  <li>Item one
    <ul>
      <li>Subitem one</li>
      <li>Subitem two</li>
    </ul>
  </li>
  <li>Item two</li>
</ul>

This would render as:

  • Item one
    • Subitem one
    • Subitem two
  • Item two

HTML Tables

HTML tables are used to organize and display data in a tabular format on web pages. They are created using a combination of HTML tags to define the structure and content of the table. Here’s a brief overview of the main elements used to create HTML tables:

<table>: This tag defines the beginning and end of the table.

<tr>: This tag defines a table row.

<th>: This tag defines a table header cell, which is typically bold and centered.

<td>: This tag defines a table data cell.

Here is a simple example of an HTML table:


<table border="1">
  <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>John</td>
    <td>Taylor</td>
    <td>35</td>
  </tr>
  <tr>
    <td>Tom</td>
    <td>Taylor</td>
    <td>30</td>
  </tr>
</table>

In this example:

The <table border="1"> element creates a table with a border.

The <tr> elements define rows in the table.

The first row uses <th> elements for headers: “First Name,” “Last Name,” and “Age.”

Subsequent rows use <td> elements for data cells, such as “John,” “Taylor,” and “35.”

HTML Page Title

The HTML page title is the text displayed in the title bar or tab of a web browser. It is defined using the <title> tag within the <head> section of an HTML document. The title is important for several reasons, including usability, accessibility, and search engine optimization (SEO).

Basic Syntax


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My Web Page</title>
</head>
<body>
  <h1>Welcome to My Web Page</h1>
</body>
</html>

In this example, the content of the <title> tag is “My Web Page”. This text will appear in the browser tab and as the title of the page when bookmarked.

Importance of the HTML Page Title

1. Browser Tabs: The title helps users identify and switch between multiple open tabs.

2. Bookmarks/Favorites: When users bookmark a page, the title is used as the default name for the bookmark.

3. Search Engine Optimization (SEO): Search engines use the title to understand the content of the page. A well-crafted title can improve a page’s search ranking and click-through rate.

4. Accessibility: Screen readers announce the title of the page when it loads, helping users understand the page’s content.

HTML favicon

A favicon (short for “favorite icon”) is a small icon associated with a specific website or web page, typically displayed in the browser’s address bar, bookmarks, and tabs. It helps users quickly identify and navigate to their favorite sites.

Basic Syntax

To add a favicon to your website, you use the <link> tag inside the <head> section of your HTML document. Here’s a basic example:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Multiple Classes Example</title>
    <style>
        .highlight {
            background-color: yellow;
        }
        .italic {
            font-style: italic;
        }
    </style>
</head>
<body>
    <p class="highlight italic">This paragraph is highlighted and italicized.</p>
</body>
</html>

Steps to Add a Favicon

1. Create a Favicon Image:

Design a small image, typically 16×16 pixels or 32×32 pixels in size.

Save the image in a format like .ico, .png, .gif, or .svg.

2. Upload the Favicon to Your Website:

Place the favicon file in your website’s root directory or a specific directory for images.

3. Add the Favicon to Your HTML:

Add the <link> tag in the <head> section of your HTML document.

Example Using Different Image Formats


<head>
  <!-- ICO format (most commonly used) -->
  <link rel="icon" href="/favicon.ico" type="image/x-icon">

  <!-- PNG format -->
  <link rel="icon" href="/favicon.png" type="image/png">

  <!-- SVG format -->
  <link rel="icon" href="/favicon.svg" type="image/svg+xml">
</head>

HTML images

HTML images are elements used to embed pictures and other visual media into web pages. They are created using the <img> tag in HTML. Unlike most other tags, the <img> tag is self-closing and does not have a closing tag.

Basic Syntax

Here is a basic example of an HTML image:


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

In this example:

The <img> tag defines the image.

The src attribute specifies the path to the image file.

The alt attribute provides alternative text for the image, which is important for accessibility and is displayed if the image cannot be loaded.

Attributes of the <img> Tag

src: Specifies the URL or path to the image file.

alt: Provides alternative text for the image, which is used by screen readers and displayed if the image fails to load.

width: Specifies the width of the image (in pixels or as a percentage).

height: Specifies the height of the image (in pixels or as a percentage).

title: Provides additional information about the image, often shown as a tooltip when the mouse hovers over the image.

Example with More Attributes


<img src="https://www.example.com/image.jpg" alt="A beautiful scenery" width="600" height="400" title="Scenery">

Using Relative and Absolute URLs

Absolute URLs: Full web addresses (e.g., https://www.example.com/images/pic.jpg).

Relative URLs: Links relative to the current page (e.g., images/pic.jpg, ../images/pic.jpg).

Responsive Images

To make images responsive, you can use CSS or HTML attributes. A common method is to set the width to 100% and the height to auto:


<img src="image.jpg" alt="Responsive image" style="width:100%; height:auto;">

HTML links

HTML links, or hyperlinks, are elements in a web page that users can click on to navigate to another web page or resource. They are created using the <a> (anchor) tag in HTML. Here is a basic example:


<a href="https://www.abc.com">Visit Example</a>

In this example:

  1. The <a> tag defines the link.
  2. The href attribute specifies the URL of the page the link goes to.
  3. The text between the opening and closing <a> tags (“Visit Example”) is the clickable part of the link.

Attributes of the <a> Tag

  1. href: Specifies the URL of the page the link goes to.
  2. target: Specifies where to open the linked document (e.g., _blank for a new tab/window, _self for the same frame, _parent for the parent frame, _top for the full body of the window).
  3. title: Provides additional information about the link, often shown as a tooltip when the mouse hovers over the link.
  4. rel: Specifies the relationship between the current document and the linked document (e.g., nofollow, noopener, noreferrer).

Example with more Attributes


<a href="https://www.abc.com" target="_blank" title="Visit Example" rel="noopener noreferrer">Visit Example</a>

Types of Links

  1. Absolute URLs: Full web addresses (e.g., https://www.abc.com/page1.html).
  2. Relative URLs: Links relative to the current page (e.g., page2.html, ../images/pic.jpg).
  3. Email Links: mailto: followed by an email address (e.g., mailto:someone@example.com)

Linking to a Specific Part of a Page

You can also link to a specific part of the same or another page using an anchor. This is done by setting an id on the target element and linking to it with a # prefix:


<!-- Target element with an id -->
<h2 id="section1">Section 1</h2>

<!-- Link to the target element -->
<a href="#section1">Go to Section 1</a>

External Links vs. Internal Links

External Links: Point to a different website (e.g., https://www.google.com).

Internal Links: Point to a different page on the same website (e.g., about.html).

HTML CSS

CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation of a document written in HTML or XML. It controls the layout, design, and visual aspects of web pages, allowing developers to separate content from design for easier maintenance and more flexible presentation.

Key Features of CSS

1. Selectors: CSS uses selectors to target HTML elements that you want to style.


p {
    color: blue;
}

This rule applies to all <p> elements, setting their text color to blue.

2. Properties and Values: CSS rules consist of properties and values.


p {
    color: blue;     /* property: value */
    font-size: 20px; /* property: value */
}

3. Cascading: The term “cascading” refers to the way CSS rules are applied based on their order and specificity. Rules can be applied from:

  1. Browser default styles
  2. External stylesheets
  3. Internal stylesheets (within a <style> tag)
  4. Inline styles (within an element’s style attribute)

4. Specificity: Determines which CSS rule is applied when multiple rules match the same element. Specificity is calculated based on the types of selectors used.


/* ID selector - higher specificity */
#header {
    color: red;
}

/* Class selector - lower specificity than ID */
.header {
    color: blue;
}

/* Element selector - lowest specificity */
h1 {
    color: green;
}

Ways to Use CSS

1. Inline CSS: Applied directly within an HTML element using the style attribute.


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

2. Internal CSS: Defined within a <style> tag in the <head> section of the HTML document.


<!DOCTYPE html>
<html>
<head>
    <style>
        p {
            color: blue;
            font-size: 20px;
        }
    </style>
</head>
<body>
    <p>This is a blue paragraph with a font size of 20px.</p>
</body>
</html>

3. External CSS: Defined in an external stylesheet file (e.g., styles.css) and linked to the HTML document using the <link> tag.

in index.html file


<!-- HTML File -->
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
    <p>This is a styled paragraph.</p>
</body>
</html>

in styles.css file


/* styles.css */
p {
    color: blue;
    font-size: 20px;
}

CSS Syntax

A CSS rule set consists of a selector and a declaration block.


selector {
    property: value;
}

Example:


h1 {
    color: blue;
    font-size: 24px;
}
Common CSS Properties

Color: Sets the color of text.


p {
    color: red;
}

Font: Controls font properties like font-size, font-family, font-weight, etc.


p {
    font-size: 16px;
    font-family: Arial, sans-serif;
}

Background: Sets background properties like background-color, background-image, etc.


body {
    background-color: #f0f0f0;
}

Margin: Sets the space outside an element.


p {
    margin: 10px;
}

Padding: Sets the space inside an element, between the content and the border.


p {
    padding: 10px;
}

Border: Sets the border around an element.


p {
    border: 1px solid black;
}

Benefits of Using CSS

Separation of Content and Presentation: Keeps HTML clean and focused on content, while CSS handles design.

Reusability: Apply the same styles across multiple pages.

Consistency: Ensures a uniform look and feel across a website.

Maintainability: Easier to update and manage styles from a single location.

HTML colors

HTML colors are used to set the color of various elements on a webpage. Colors can be defined in several ways in HTML, including by name, hexadecimal values, RGB values, RGBA values (which include an alpha channel for opacity), HSL values, and HSLA values.

Here are the different ways to specify colors in HTML:

1. Color Names: There are 140 predefined color names in HTML.


<p style="color: red;">This is a red paragraph.</p>

2. Hexadecimal Values: Colors can be specified using a hex code, which starts with # followed by six hexadecimal digits.


<p style="color: #ff0000;">This is a red paragraph.</p>

3. RGB Values: Colors can be defined using the rgb() function, with values ranging from 0 to 255 for red, green, and blue.


<p style="color: rgb(255, 0, 0);">This is a red paragraph.</p>

4. RGBA Values: Similar to RGB, but includes an alpha channel for opacity, with values ranging from 0 (fully transparent) to 1 (fully opaque).


<p style="color: rgba(255, 0, 0, 0.5);">This is a semi-transparent red paragraph.</p>

5. HSL Values: Colors can be defined using the hsl() function, with values for hue (0-360 degrees), saturation (0%-100%), and lightness (0%-100%).


<p style="color: hsl(0, 100%, 50%);">This is a red paragraph.</p>

6. HSLA Values: Similar to HSL, but includes an alpha channel for opacity.


<p style="color: hsla(0, 100%, 50%, 0.5);">This is a semi-transparent red paragraph.</p>

By using these methods, you can apply colors to text, backgrounds, borders, and other elements on a webpage to enhance its visual appeal and usability.

HTML comments

HTML comments are used to add notes or explanations within the HTML code, which are not displayed in the web browser. They are useful for documenting the code, explaining the structure, or temporarily disabling parts of the code. HTML comments are enclosed within <!-- and --> tags.

Here is an example of an HTML comment:


<!-- This is a comment -->
<p>This is a paragraph.</p>
<!-- <p>This paragraph is commented out and will not be displayed.</p> -->

In this example, the first line is a comment that won’t be displayed on the web page, and the second comment surrounds a paragraph tag, making the browser ignore it. Comments can be very useful for developers to leave notes or explanations about the code.

HTML Text formatting

HTML text formatting involves using HTML tags to define the appearance and structure of text on a webpage. Here are some commonly used HTML tags for text formatting:

  1. Bold Text: <b> or <strong>

<b>This text is bold.</b>
<strong>This text is strong and bold.</strong>

2. Italic Text: <i> or <em>


<i>This text is italic.</i>
<em>This text is emphasized and italic.</em>

3. Underlined Text: <u>


<u>This text is underlined.</u>

4. del Text: <del>


<del>This text is deleted.</del>

5. Marked Text: <mark>


<mark>This text is highlighted.</mark>

6. Small Text: <small>


<small>This text is small.</small>

7. Subscript Text: <sub>


H<sub>2</sub>O

8. Superscript Text: <sup>


E = mc<sup>2</sup>

HTML styles

HTML styles refer to the way elements on a web page are presented and formatted. These styles are typically defined using CSS (Cascading Style Sheets), which allows you to control the appearance of HTML elements, such as text, images, and layouts. Here are some key concepts:

  1. Inline Styles: These are applied directly within an HTML element using the style attribute.

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

2. Internal Styles: These are defined within the <style> tag in the <head> section of an HTML document.


<head>
  <style>
    p {
      color: blue;
      font-size: 16px;
    }
  </style>
</head>
<body>
  <p>This is a blue paragraph.</p>
</body>

3. External Styles: These are defined in a separate CSS file, which is linked to the HTML document.


<head>
  <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
  <p>This is a blue paragraph.</p>
</body>

And in the styles.css file:


p {
  color: blue;
  font-size: 16px;
}

4. CSS Selectors: These are patterns used to select the elements you want to style.

Element Selector: Selects elements based on the element name.


p {
  color: blue;
}

Class Selector: Selects elements based on the class attribute.

in css file


.blue-text {
  color: blue;
}

in html file


<p class="blue-text">This is a blue paragraph.</p>

ID Selector: Selects a single element based on the id attribute.

in css file


#unique-text {
  color: blue;
}

in html file


<p id="unique-text">This is a blue paragraph.</p>

5. CSS Properties: These define the specific style characteristics of an element. Common properties include:

  1. color: Sets the text color.
  2. font-size: Sets the size of the text.
  3. background-color: Sets the background color of an element.
  4. margin: Sets the space around elements.
  5. padding: Sets the space inside elements.
  6. border: Sets the border around elements.

HTML Paragraph

In HTML, a paragraph is defined using the <p> tag. Paragraphs are blocks of text that are separated from adjacent blocks by a blank line in the rendered output. The <p> tag is a block-level element, meaning it creates a block of content that typically begins on a new line.

Syntax

The basic syntax for a paragraph in HTML is as follows:


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

Example

Here is a simple HTML document with a few paragraphs:


<!DOCTYPE html>
<html>
<head>
    <title>HTML Paragraph Example</title>
</head>
<body>
    <p>This is the first paragraph. It contains some text.</p>
    <p>This is the second paragraph. It contains some more text.</p>
    <p>This is the third paragraph. It also contains text.</p>
</body>
</html>

When rendered in a web browser, each paragraph will appear on its own line with some space between each one.

use Attributes in the paragraph

The <p> tag can use various global attributes to control its behavior and appearance. Here are some common attributes:

id: Specifies a unique id for the paragraph.


<p id="intro">This is an introductory paragraph.</p>

class: Specifies one or more class names for the paragraph (used for CSS styling).


<p class="highlight">This paragraph is highlighted.</p>

style: Specifies inline CSS styles for the paragraph.


<p style="color:blue;">This paragraph is blue.</p>

title: Provides additional information about the paragraph (displayed as a tooltip when hovering over the paragraph).


<p title="Tooltip text">Hover over this paragraph to see the tooltip.</p>

Best Practices

Use paragraphs to group related sentences: Paragraphs should be used to group sentences that belong together. Each paragraph should represent a single idea or topic.

Avoid nesting paragraphs: Paragraphs should not be nested within other block-level elements like <div> or within each other.

Keep paragraphs concise: Shorter paragraphs are easier to read, especially on screens. Break up long blocks of text into multiple paragraphs.

HTML Headings

HTML headings are used to define the headings of a web page. Headings are important for both organizing content and improving accessibility and SEO (Search Engine Optimization). HTML provides six levels of headings, from <h1> to <h6>, with <h1> being the highest level (most important) and <h6> being the lowest level (least important).

Syntax and Usage

<h1> to <h6> Tags

each heading level is defined with a specific tag:

<h1>: Defines the most important heading.

<h2>: Defines the second most important heading.

<h3>: Defines the third most important heading.

<h4>: Defines the fourth most important heading.

<h5>: Defines the fifth most important heading.

<h6>: Defines the least important heading.

Example:-


<!DOCTYPE html>
<html>
<head>
    <title>HTML Headings Example</title>
</head>
<body>
    <h1>This is an H1 heading</h1>
    <p>This is a paragraph under the H1 heading.</p>
    
    <h2>This is an H2 heading</h2>
    <p>This is a paragraph under the H2 heading.</p>
    
    <h3>This is an H3 heading</h3>
    <p>This is a paragraph under the H3 heading.</p>
    
    <h4>This is an H4 heading</h4>
    <p>This is a paragraph under the H4 heading.</p>
    
    <h5>This is an H5 heading</h5>
    <p>This is a paragraph under the H5 heading.</p>
    
    <h6>This is an H6 heading</h6>
    <p>This is a paragraph under the H6 heading.</p>
</body>
</html>

Importance of Headings

Organizational Structure: Headings help to structure the content, making it easier for readers to understand and navigate through the document.

SEO (Search Engine Optimization): Search engines use headings to understand the content of a webpage. Proper use of headings can improve the page’s ranking in search results.

Accessibility: Screen readers and other assistive technologies use headings to help users navigate through the content. Properly structured headings can enhance the accessibility of a web page.

Best Practices

Use headings hierarchically: Start with <h1> for the main heading and use <h2> to <h6> for subheadings in a hierarchical manner.

Avoid skipping heading levels: Do not skip heading levels (e.g., from <h1> directly to <h3>) as it can confuse both users and search engines.

Keep headings concise and descriptive: Headings should clearly indicate the content of the section they introduce.

Use one <h1> per page: Typically, a webpage should have only one <h1> element that represents the main topic or title of the page. Use <h2> to <h6> for subheadings.

HTML Attribute

HTML attributes provide additional information about HTML elements. They are always included in the opening tag of the element and come in name/value pairs like name="value". Attributes help customize elements, specify their behavior, and provide metadata.

Key Points About HTML Attributes

  1. Attributes are placed in the opening tag: They are written inside the opening tag of an HTML element.
  2. Attributes come in name/value pairs: The name is the attribute itself, and the value is assigned to it. The value is enclosed in quotes.
  3. Not all elements have the same attributes: Some attributes are specific to certain elements, while others are global and can be used with any element.

Common HTML Attributes

1. Global Attributes

id: Specifies a unique id for an element.


<div id="header">This is the header</div>

class: Specifies one or more class names for an element (used for CSS and JavaScript).


<p class="intro">This is an introductory paragraph.</p>

style: Contains inline CSS to style an element.


<h1 style="color:blue;">This is a blue heading</h1>

lang: Specifies the language of the element’s content.


<p lang="en">This paragraph is in English.</p>

2. Specific Attributes

href: Specifies the URL of a link (used in <a> tags).


<a href="https://www.example.com">Visit Example</a>

src: Specifies the path to an image (used in <img> tags).


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

alt: Provides alternative text for an image, which is important for accessibility (used in <img> tags).


<img src="image.jpg" alt="A beautiful scenery" />

width and height: Specifies the width and height of an image or other element.


<img src="image.jpg" width="500" height="600" />

type: Specifies the type of input element (used in <input> tags).


<input type="text">
<input type="password">
<input type="submit">

value: Specifies the initial value of an input element (used in <input> tags).


<input type="text" value="John">

name: Specifies the name of an input element (used in forms).


<input type="text" value="John">

placeholder: Provides a hint to the user of what can be entered in the input field.


<input type="text" placeholder="Enter your name">

disabled: Specifies that an input element should be disabled.


<input type="text" disabled>

checked: Specifies that an input element (checkbox or radio button) should be pre-selected when the page loads.


<input type="checkbox" checked>

action: Specifies where to send the form data when a form is submitted (used in <form> tags).


<form action="/submit-form">

method: Specifies the HTTP method to use when sending form data (used in <form> tags).


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

Example Usage of Attributes

Here’s an example of a form that uses various HTML attributes:


<!DOCTYPE html>
<html>
<head>
    <title>Form Example</title>
</head>
<body>
    <form action="/submit-form" method="post">
        <label for="name">Name:</label>
        <input type="text" id="name" name="name" placeholder="Enter your name" required><br><br>
        
        <label for="email">Email:</label>
        <input type="email" id="email" name="email" placeholder="Enter your email"><br><br>
        
        <label for="password">Password:</label>
        <input type="password" id="password" name="password"><br><br>
        
        <input type="submit" value="Submit">
    </form>
</body>
</html>

In this example:

  1. The action attribute in the <form> tag specifies where to send the form data.
  2. The method attribute specifies the HTTP method (post) to use.
  3. The id, name, placeholder, and required attributes are used in the <input> tags to define their behavior and provide hints to the user.

HTML Elements

HTML elements are the building blocks of an HTML document. They define the structure and content of a web page. Here is a comprehensive guide to the most common HTML elements:

1. Basic Elements

<!DOCTYPE html>: Declares the document type and version of HTML.

<html>: The root element of an HTML document.

<head>: Contains meta-information about the document.

<title>: Sets the title of the document, shown in the browser’s title bar or tab.

<body>: Contains the content of the HTML document.

2. Text Elements

<h1> to <h6>: Headings, with <h1> being the highest (most important) and <h6> the lowest (least important).

<p>: Defines a paragraph.

<br>: Inserts a line break.

<hr>: Defines a thematic break (horizontal rule).

3. Formatting Elements

<b>: Bold text.

<strong>: Important text (typically rendered as bold).

<i>: Italic text.

<em>: Emphasized text (typically rendered as italic).

<mark>: Marked/highlighted text.

<small>: Smaller text.

<del>: Deleted (strikethrough) text.

<ins>: Inserted (underlined) text.

<sub>: Subscript text.

<sup>: Superscript text

4. Lists

<ul>: Unordered list (bulleted).

<ol>: Ordered list (numbered).

<li>: List item.

<dl>: Description list.

<dt>: Term in a description list.

<dd>: Description of the term in a description list.

5. Links

<a>: Anchor (hyperlink). The href attribute specifies the URL of the page the link goes to.


<a href="https://www.example.com">Visit Example</a>

6. Images

<img>: Embeds an image. The src attribute specifies the path to the image, and the alt attribute provides alternative text.


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

7. Tables

<table>: Defines a table.

<tr>: Table row.

<th>: Table header cell.

<td>: Table data cell.

<caption>: Table caption.


<table>
  <caption>Table Title</caption>
  <tr>
    <th>Header 1</th>
    <th>Header 2</th>
  </tr>
  <tr>
    <td>Data 1</td>
    <td>Data 2</td>
  </tr>
</table>

What is HTML?

HTML (HyperText Markup Language) is the standard language used to create and design web pages. It describes the structure of a webpage and consists of a series of elements that tell the browser how to display content.

History and Versions of HTML

HTML 1.0 (1991): The first version, a very basic version of HTML.

HTML 2.0 (1995): Standardized version with additional features.

HTML 3.2 (1997): Included new features such as tables and applets.

HTML 4.01 (1999): Introduced more complex features like CSS support.

XHTML (2000): A stricter, XML-based version of HTML.

HTML5 (2014): The latest version, which includes powerful new features like video playback and improved semantics for better accessibility and SEO.

How HTML Works

HTML uses “tags” to mark up content. Tags are enclosed in angle brackets (< >) and typically come in pairs: an opening tag and a closing tag. The content goes between the tags.

Example of a simple HTML element:

<p> is the opening tag.

</p> is the closing tag.

This is a paragraph. is the content.

Basic Structure of an HTML Document

An HTML document has a basic structure that includes several key elements:


<!DOCTYPE html>
<html>
<head>
    <title>Page Title</title>
</head>
<body>
    <h1>This is a Heading</h1>
    <p>This is a paragraph.</p>
</body>
</html>

<!DOCTYPE html>: This declaration defines the document type and version of HTML.

<html>: The root element of an HTML page.

<head>: Contains meta-information about the document (like the title, character set, styles, links, etc.).

<title>: Specifies the title of the document, which is shown in the browser’s title bar or tab.

<body>: Contains the content of the HTML document, such as text, images, links, tables, etc.