1. Introduction to HTML

HTML (HyperText Markup Language) is the foundational language for creating web pages and applications. It defines the structure and content of a webpage by organizing information into meaningful components that browsers render for users. While it doesn't handle styling (CSS) or behavior (JavaScript), HTML serves as the backbone of any web document.

Breaking Down HTML:
  1. HTML (HyperText Markup Language):

    • A markup language that structures the information displayed on websites.
    • Specifies the roles and relationships of content elements (e.g., headings, paragraphs, images, and links).
  2. HyperText:

    • A term that describes text containing links (or "hyperlinks") to other text or resources.
    • Allows navigation between documents or parts of a document.
    • Example: <a href="https://example.com">Click here</a> creates a hyperlink to another webpage.
  3. Markup Language:

    • A system of tags and attributes used to annotate content, providing meaning and structure.
    • Example:
      <p>This is a paragraph.</p>
      Here, <p> is the tag marking the text as a paragraph.

Elements in HTML

An HTML element is the fundamental building block of a webpage. It consists of:

  1. Tags: Denote the start and end of an element.
  2. Attributes: Provide additional information about the element (e.g., src, href).
  3. Content: The data between the opening and closing tags.
Syntax of an HTML Element:

The basic structure of an HTML element is:

<start-tag attributes>content</end-tag>

Example of an Element:

<p class="intro">This is a paragraph.</p>
  • Opening tag: <p> marks the start of a paragraph.
  • Content: This is a paragraph. is the content.
  • Closing tag: </p> marks the end of the paragraph.
  • Attributes: class="intro" adds extra information to the element.

Self-Closing Elements:

Some elements do not have content and close themselves. Example:

<img src="image.jpg" alt="An image">

Semantic HTML Elements

Semantic HTML refers to elements with names that describe their purpose and role in the document. These elements improve accessibility, SEO, and developer clarity.

Examples of Semantic Elements:

  • <header>: Represents introductory content or a navigational aid.
  • <article>: Defines self-contained, independent content.
  • <footer>: Contains footer information like copyright or links.
  • <section>: Groups related content thematically.
  • <nav>: Denotes a navigation block.
  • <aside>: Represents tangential content, such as sidebars.

Comparison:

  • Non-semantic elements: <div> and <span> convey no meaning on their own.
  • Semantic elements: <header> and <article> provide meaningful context.

Example of a semantic structure:

<article>
  <header>
    <h1>Introduction to HTML</h1>
    <p>Published on: November 24, 2024</p>
  </header>
  <p>HTML is the backbone of web development...</p>
  <footer>
    <p>Written by: John Doe</p>
  </footer>
</article>

HTML Syntax Rules

To ensure valid HTML, adhere to the following syntax rules:

  1. Proper Nesting:

    • Tags must be properly nested.
    • Example:
      <div><p>Valid HTML</p></div>
      Incorrect Nesting: <div><p>Invalid HTML</div></p>
  2. Case Sensitivity:

    • HTML is case-insensitive but best practice is to use lowercase tags.
    • Example: <h1> is preferred over <H1>.
  3. Attributes:

    • Must be written in name="value" format.
    • Example: <img src="image.jpg" alt="An image">
  4. Quotes for Attribute Values:

    • Always enclose attribute values in quotes.
    • Example: class="intro" is valid, but class=intro is not.
  5. Void Elements:

    • These elements don’t have a closing tag and are self-closing.
    • Examples: <img>, <input>, <br>.
    • Use a forward slash for XHTML compatibility: <img src="image.jpg" />.
  6. Doctype Declaration:

    • Always start the document with <!DOCTYPE html> to declare the document type and version.
    • Example:
      <!DOCTYPE html>
  7. Character Encoding:

    • Use <meta charset="UTF-8"> to ensure the document supports special characters.

How Browsers Interpret HTML

When a browser receives an HTML document, it:

  1. Reads the HTML tags and content to understand the structure.
  2. Creates a Document Object Model (DOM), which represents the document as a tree of elements.
  3. Renders the DOM visually for users.

Example of a DOM Tree:

For the HTML:

<!DOCTYPE html>
<html>
  <head>
    <title>My Portfolio</title>
  </head>
  <body>
    <h1>Welcome</h1>
    <p>This is my portfolio.</p>
  </body>
</html>

The DOM tree would look like:

html
├── head
│   └── title: My Portfolio
└── body
    ├── h1: Welcome
    └── p: This is my portfolio.

Why HTML is Essential

  1. Accessibility:

    • Semantic elements help assistive technologies (e.g., screen readers) navigate content.
  2. SEO (Search Engine Optimization):

    • Search engines use HTML to understand webpage content and rank it accordingly.
  3. Interoperability:

    • HTML ensures consistency across browsers and devices.
  4. Foundation for Other Technologies:

    • HTML integrates with CSS (for styling) and JavaScript (for interactivity).

HTML in Context

When combined with CSS and JavaScript:

  1. HTML: Provides the structure.
    • Example: A table layout or a list of items.
  2. CSS: Adds style.
    • Example: Colors, fonts, and spacing.
  3. JavaScript: Adds behavior.
    • Example: Clickable buttons and animations.

HTML-Only Example:

<h1>Contact Me</h1>
<p>Email me at: contact@example.com</p>

HTML + CSS Example:

<h1 style="color: blue;">Contact Me</h1>
<p style="font-size: 18px;">Email me at: contact@example.com</p>

HTML + CSS + JavaScript Example:

<h1 style="color: blue;" onclick="alert('Contact Info Clicked!')">Contact Me</h1>

Basic HTML Document Structure

Every HTML document has a standard structure:

<!DOCTYPE html>
<html>
  <head>
    <title>My Portfolio</title>
  </head>
  <body>
    <h1>Hello, World!</h1>
    <p>This is my first webpage.</p>
  </body>
</html>

Explanation:

  1. <!DOCTYPE html>:

    • Declares the document type as HTML5.
    • Not technically a tag but an instruction to the browser.
  2. <html>:

    • The root element that wraps the entire HTML document.
    • Contains two main parts: <head> and <body>.
  3. <head>:

    • Contains metadata about the document (not visible on the webpage).
    • Includes:
      • <title>: Sets the page title displayed on the browser tab.
      • Other elements like <meta>, which we’ll cover later.
  4. <body>:

    • Contains the visible content of the webpage.
    • Includes text, images, links, forms, and more.

Setting Up Your First HTML File

  1. Create the HTML file:

    • Open a text editor (e.g., VS Code, Notepad++).
    • Save the file as index.html.
  2. Add the basic HTML structure:

<!DOCTYPE html>
<html>
  <head>
    <title>My Portfolio</title>
  </head>
  <body>
    <h1>Welcome to My Portfolio</h1>
    <p>This is a webpage where I showcase my projects and skills.</p>
  </body>
</html>
  1. Open in a browser:
    • Double-click the file to open it in your default web browser.

Adding Content to Your Portfolio

Let’s start building the basic structure of the portfolio:

<!DOCTYPE html>
<html>
  <head>
    <title>My Portfolio</title>
  </head>
  <body>
    <!-- Header Section -->
    <header>
      <h1>My Portfolio</h1>
      <p>Welcome to my personal webpage!</p>
    </header>

    <!-- Main Content -->
    <main>
      <section>
        <h2>About Me</h2>
        <p>I am a web developer passionate about creating amazing digital experiences.</p>
      </section>
    </main>

    <!-- Footer -->
    <footer>
      <p>&copy; 2024 My Portfolio. All rights reserved.</p>
    </footer>
  </body>
</html>

Explanation:

  1. <header>:

    • Used for introductory content, such as the title and tagline of the webpage.
  2. <main>:

    • Contains the central content of the page.
  3. <section>:

    • Represents a thematic grouping of content, such as "About Me."
  4. <footer>:

    • Used for footer content like copyright or contact details.

2. Text and Semantic Content

In this section, we’ll learn how to structure and organize content using headings, paragraphs, lists, and semantic elements. These components will give the portfolio webpage meaning and clarity for both users and search engines.

Headings

Headings help structure the content hierarchy of a webpage. HTML provides six levels of headings:

<h1>Main Heading</h1>
<h2>Subheading Level 2</h2>
<h3>Subheading Level 3</h3>
<h4>Subheading Level 4</h4>
<h5>Subheading Level 5</h5>
<h6>Subheading Level 6</h6>
  • Use cases:
    • <h1> is typically used for the main page title.
    • <h2> to <h6> are used for subsections and finer details.

Portfolio Update:

Add a title and subtitle to your portfolio:

<header>
  <h1>Welcome to My Portfolio</h1>
  <h2>Your One-Stop Showcase of My Skills and Projects</h2>
</header>

Paragraphs

Paragraphs group sentences into cohesive blocks of text. Use the <p> tag for paragraphs.

<p>This is a paragraph of text that provides information or context on the webpage.</p>

Portfolio Update:

Add an introductory paragraph to the "About Me" section:

<main>
  <section>
    <h2>About Me</h2>
    <p>
      Hello! I am a web developer passionate about creating innovative digital solutions. With a focus on clean, efficient, and accessible code, I aim to deliver exceptional user experiences.
    </p>
  </section>
</main>

Lists

Lists organize content into bullet points or numbered sequences.

  1. Unordered Lists (<ul>):

    • Use for items without a specific order.
    <ul>
      <li>HTML</li>
      <li>CSS</li>
      <li>JavaScript</li>
    </ul>
  2. Ordered Lists (<ol>):

    • Use for items with a sequence or priority.
    <ol>
      <li>Step 1: Plan</li>
      <li>Step 2: Design</li>
      <li>Step 3: Develop</li>
    </ol>
  3. Nested Lists:

    • Combine lists for subcategories.
    <ul>
      <li>Programming Languages
        <ul>
          <li>Python</li>
          <li>JavaScript</li>
        </ul>
      </li>
    </ul>

Portfolio Update:

Add a list of skills in a "Skills" section:

<section>
  <h2>Skills</h2>
  <ul>
    <li>Web Development</li>
    <li>Front-End Frameworks</li>
    <li>Responsive Design</li>
    <li>Problem Solving</li>
  </ul>
</section>

Block vs. Inline Elements

  • Block Elements:

    • Occupy the full width of their container.
    • Examples: <div>, <p>, <h1> to <h6>, <section>, <header>.
  • Inline Elements:

    • Only occupy as much width as their content requires.
    • Examples: <span>, <a>, <strong>, <em>.

Example:

<p>This is a <strong>strong</strong> word in the paragraph.</p>
<p>This is an <em>emphasized</em> word in the paragraph.</p>

Semantic HTML

Semantic elements provide meaningful structure to the document. They improve accessibility and SEO by clearly defining sections of the webpage.

| Semantic Tags | Purpose | |-----------------------|----------------------------------------------| | <header> | Defines introductory content or navigation. | | <main> | Represents the main content of the page. | | <section> | Groups related content thematically. | | <footer> | Contains footer information. | | <article> | Represents independent, self-contained content. | | <aside> | Represents content tangentially related to the main content. |

Portfolio Update:

Update the portfolio to include more semantic structure:

<main>
  <section>
    <h2>About Me</h2>
    <p>
      I am a web developer passionate about building efficient and engaging web applications.
    </p>
  </section>

  <section>
    <h2>Skills</h2>
    <ul>
      <li>HTML</li>
      <li>CSS</li>
      <li>JavaScript</li>
    </ul>
  </section>

  <section>
    <h2>Projects</h2>
    <p>Here are some of my recent projects:</p>
    <ul>
      <li>Portfolio Website</li>
      <li>Weather App</li>
      <li>Task Manager</li>
    </ul>
  </section>
</main>

<footer>
  <p>&copy; 2024 My Portfolio. All rights reserved.</p>
</footer>

3. Links and Navigation

In this section, we will learn how to create hyperlinks and build a navigation menu for the portfolio website. Links are one of the core elements of the web, enabling users to move between pages, sections, or external resources.

Hyperlinks with <a>

The <a> tag is used to create hyperlinks. It has the following structure:

<a href="URL">Link Text</a>

Attributes:

  1. href: Specifies the destination of the link.

    • Absolute URL: Links to an external site.
      <a href="https://example.com">Visit Example</a>
    • Relative URL: Links to another file in your project.
      <a href="projects.html">View Projects</a>
    • Anchor Links: Links to a specific section on the same page.
      <a href="#about-me">About Me</a>
  2. target: Determines where the link opens.

    • _self: Default, opens in the same tab.
    • _blank: Opens in a new tab.
      <a href="https://example.com" target="_blank">Visit Example</a>

Adding Internal Links

Internal links allow users to navigate within the same webpage using anchor links. For this, you need:

  1. A link that references an ID in the href attribute.
  2. An element with the corresponding id.

Example:

<a href="#skills">Go to Skills</a>

<section id="skills">
  <h2>Skills</h2>
  <p>HTML, CSS, JavaScript</p>
</section>

Building a Navigation Bar

A navigation bar is a collection of links that helps users move between sections of your website. We use an unordered list (<ul>) and list items (<li>) to structure the navigation menu.

Example:

<nav>
  <ul>
    <li><a href="#about-me">About Me</a></li>
    <li><a href="#skills">Skills</a></li>
    <li><a href="#projects">Projects</a></li>
    <li><a href="#contact">Contact</a></li>
  </ul>
</nav>

Portfolio Update:

Add a navigation bar to your portfolio:

<header>
  <h1>Welcome to My Portfolio</h1>
  <h2>Your One-Stop Showcase of My Skills and Projects</h2>
  <nav>
    <ul>
      <li><a href="#about-me">About Me</a></li>
      <li><a href="#skills">Skills</a></li>
      <li><a href="#projects">Projects</a></li>
      <li><a href="#contact">Contact</a></li>
    </ul>
  </nav>
</header>

Adding External Links

External links point to other websites or resources.

Example:

<a href="https://github.com/yourusername" target="_blank">Visit My GitHub</a>

Portfolio Update:

Add a section in the footer to link to external profiles:

<footer>
  <p>&copy; 2024 My Portfolio. All rights reserved.</p>
  <p>
    Find me on:
    <a href="https://github.com/yourusername" target="_blank">GitHub</a> |
    <a href="https://linkedin.com/in/yourusername" target="_blank">LinkedIn</a>
  </p>
</footer>

Enhancing the Portfolio

Here’s the updated HTML for the portfolio so far:

<!DOCTYPE html>
<html>
  <head>
    <title>My Portfolio</title>
  </head>
  <body>
    <!-- Header with Navigation -->
    <header>
      <h1>Welcome to My Portfolio</h1>
      <h2>Your One-Stop Showcase of My Skills and Projects</h2>
      <nav>
        <ul>
          <li><a href="#about-me">About Me</a></li>
          <li><a href="#skills">Skills</a></li>
          <li><a href="#projects">Projects</a></li>
          <li><a href="#contact">Contact</a></li>
        </ul>
      </nav>
    </header>

    <!-- Main Content -->
    <main>
      <section id="about-me">
        <h2>About Me</h2>
        <p>
          I am a web developer passionate about creating efficient and engaging web applications.
        </p>
      </section>

      <section id="skills">
        <h2>Skills</h2>
        <ul>
          <li>HTML</li>
          <li>CSS</li>
          <li>JavaScript</li>
        </ul>
      </section>

      <section id="projects">
        <h2>Projects</h2>
        <p>Here are some of my recent projects:</p>
        <ul>
          <li>Portfolio Website</li>
          <li>Weather App</li>
          <li>Task Manager</li>
        </ul>
      </section>

      <section id="contact">
        <h2>Contact</h2>
        <p>Email me at <a href="mailto:youremail@example.com">youremail@example.com</a></p>
      </section>
    </main>

    <!-- Footer -->
    <footer>
      <p>&copy; 2024 My Portfolio. All rights reserved.</p>
      <p>
        Find me on:
        <a href="https://github.com/yourusername" target="_blank">GitHub</a> |
        <a href="https://linkedin.com/in/yourusername" target="_blank">LinkedIn</a>
      </p>
    </footer>
  </body>
</html>

4. Adding Images and Multimedia

In this section, we’ll enhance the portfolio by adding images and multimedia content such as profile pictures, project screenshots, and videos. Images and multimedia make a webpage more engaging and visually appealing.

Adding Images

The <img> tag is used to display images in an HTML document.

Basic Structure:

<img src="image-source" alt="description">

Attributes:

  1. src: Specifies the source (path) of the image.

    • Relative path (e.g., images/profile.jpg).
    • Absolute URL (e.g., https://example.com/image.jpg).
  2. alt: Provides alternative text for the image (important for accessibility and SEO).

  3. Optional Attributes:

    • width and height: To set the dimensions of the image.
    • title: Adds a tooltip when you hover over the image.

Example:

<img src="profile.jpg" alt="Profile Picture" width="200">

Portfolio Update:

Add a profile picture to the "About Me" section:

<section id="about-me">
  <h2>About Me</h2>
  <img src="profile.jpg" alt="Profile Picture of [Your Name]" width="200">
  <p>
    I am a web developer passionate about creating efficient and engaging web applications.
  </p>
</section>

Organizing Image Files

To keep your project organized, create an images folder to store image files. Update the src attribute accordingly.

<img src="images/profile.jpg" alt="Profile Picture">

Adding Videos

The <video> tag is used to embed videos in HTML. It can include multiple <source> tags for different formats.

Basic Structure:

<video controls>
  <source src="video-file.mp4" type="video/mp4">
  <source src="video-file.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>

Attributes:

  • controls: Adds play, pause, and volume controls.
  • autoplay: Starts the video automatically.
  • loop: Repeats the video continuously.
  • muted: Mutes the video by default.

Portfolio Update:

Add a demo video to the "Projects" section:

<section id="projects">
  <h2>Projects</h2>
  <p>Here are some of my recent projects:</p>
  <ul>
    <li>Portfolio Website</li>
    <li>Weather App</li>
    <li>Task Manager</li>
  </ul>
  <video controls width="400">
    <source src="videos/project-demo.mp4" type="video/mp4">
    Your browser does not support the video tag.
  </video>
</section>

Adding Audio

The <audio> tag is used to add sound to a webpage.

Basic Structure:

<audio controls>
  <source src="audio-file.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

Portfolio Update:

Add an audio introduction to the "About Me" section (optional):

<section id="about-me">
  <h2>About Me</h2>
  <img src="images/profile.jpg" alt="Profile Picture of [Your Name]" width="200">
  <p>
    I am a web developer passionate about creating efficient and engaging web applications.
  </p>
  <audio controls>
    <source src="audio/introduction.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
  </audio>
</section>

Best Practices for Images and Multimedia

  1. Use descriptive alt text for images.

    • Example: alt="Screenshot of Task Manager App interface"
  2. Optimize file size to improve webpage performance.

    • Compress images and videos using tools like TinyPNG or HandBrake.
  3. Use appropriate file formats:

    • Images: Use .jpg for photos and .png for transparent graphics.
    • Videos: Use .mp4 for cross-browser compatibility.
  4. Organize multimedia assets in separate folders (e.g., images/, videos/, audio/).

Enhanced Portfolio Code

Here’s the updated portfolio code with images and multimedia:

<!DOCTYPE html>
<html>
  <head>
    <title>My Portfolio</title>
  </head>
  <body>
    <!-- Header with Navigation -->
    <header>
      <h1>Welcome to My Portfolio</h1>
      <h2>Your One-Stop Showcase of My Skills and Projects</h2>
      <nav>
        <ul>
          <li><a href="#about-me">About Me</a></li>
          <li><a href="#skills">Skills</a></li>
          <li><a href="#projects">Projects</a></li>
          <li><a href="#contact">Contact</a></li>
        </ul>
      </nav>
    </header>

    <!-- Main Content -->
    <main>
      <section id="about-me">
        <h2>About Me</h2>
        <img src="images/profile.jpg" alt="Profile Picture of [Your Name]" width="200">
        <p>
          I am a web developer passionate about creating efficient and engaging web applications.
        </p>
        <audio controls>
          <source src="audio/introduction.mp3" type="audio/mpeg">
          Your browser does not support the audio element.
        </audio>
      </section>

      <section id="skills">
        <h2>Skills</h2>
        <ul>
          <li>HTML</li>
          <li>CSS</li>
          <li>JavaScript</li>
        </ul>
      </section>

      <section id="projects">
        <h2>Projects</h2>
        <p>Here are some of my recent projects:</p>
        <ul>
          <li>Portfolio Website</li>
          <li>Weather App</li>
          <li>Task Manager</li>
        </ul>
        <video controls width="400">
          <source src="videos/project-demo.mp4" type="video/mp4">
          Your browser does not support the video tag.
        </video>
      </section>

      <section id="contact">
        <h2>Contact</h2>
        <p>Email me at <a href="mailto:youremail@example.com">youremail@example.com</a></p>
      </section>
    </main>

    <!-- Footer -->
    <footer>
      <p>&copy; 2024 My Portfolio. All rights reserved.</p>
      <p>
        Find me on:
        <a href="https://github.com/yourusername" target="_blank">GitHub</a> |
        <a href="https://linkedin.com/in/yourusername" target="_blank">LinkedIn</a>
      </p>
    </footer>
  </body>
</html>

5. Tables for Structured Data

Tables are a great way to display structured information, such as project details, skills, or schedules. In this section, we’ll learn how to create and use HTML tables to enhance the portfolio.

Basic Table Structure

The <table> tag is used to define a table. It contains rows (<tr>) and cells (<td> for data and <th> for headers).

Example:

<table>
  <tr>
    <th>Project</th>
    <th>Technology</th>
    <th>Status</th>
  </tr>
  <tr>
    <td>Portfolio Website</td>
    <td>HTML, CSS</td>
    <td>Completed</td>
  </tr>
  <tr>
    <td>Weather App</td>
    <td>JavaScript</td>
    <td>In Progress</td>
  </tr>
</table>

Explanation:

  1. <table>: Defines the table.
  2. <tr> (Table Row): Represents a row in the table.
  3. <th> (Table Header): Defines a header cell, usually bold and centered.
  4. <td> (Table Data): Defines standard data cells.

Adding a Table to the Portfolio

Let’s use a table to showcase project details in the "Projects" section.

<section id="projects">
  <h2>Projects</h2>
  <p>Here are some of my recent projects:</p>
  <table>
    <tr>
      <th>Project</th>
      <th>Technology</th>
      <th>Status</th>
    </tr>
    <tr>
      <td>Portfolio Website</td>
      <td>HTML, CSS</td>
      <td>Completed</td>
    </tr>
    <tr>
      <td>Weather App</td>
      <td>JavaScript</td>
      <td>In Progress</td>
    </tr>
    <tr>
      <td>Task Manager</td>
      <td>React, Node.js</td>
      <td>Completed</td>
    </tr>
  </table>
</section>

Adding Captions

Use the <caption> tag to add a title to the table for better accessibility and context.

<table>
  <caption>My Recent Projects</caption>
  <tr>
    <th>Project</th>
    <th>Technology</th>
    <th>Status</th>
  </tr>
  <tr>
    <td>Portfolio Website</td>
    <td>HTML, CSS</td>
    <td>Completed</td>
  </tr>
</table>

Table Sections

To organize tables, you can use <thead>, <tbody>, and <tfoot> tags.

  1. <thead>: Groups header rows.
  2. <tbody>: Groups the body (data rows).
  3. <tfoot>: Groups footer rows, often for summary or notes.

Example:

<table>
  <caption>My Recent Projects</caption>
  <thead>
    <tr>
      <th>Project</th>
      <th>Technology</th>
      <th>Status</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Portfolio Website</td>
      <td>HTML, CSS</td>
      <td>Completed</td>
    </tr>
    <tr>
      <td>Weather App</td>
      <td>JavaScript</td>
      <td>In Progress</td>
    </tr>
    <tr>
      <td>Task Manager</td>
      <td>React, Node.js</td>
      <td>Completed</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td colspan="3">Total Projects: 3</td>
    </tr>
  </tfoot>
</table>

Adding Borders and Spacing

Although we’re focusing on HTML (not CSS), basic table styling can be applied using attributes:

  1. border: Adds borders to the table and cells.

    <table border="1">
      <tr>
        <th>Project</th>
        <th>Technology</th>
        <th>Status</th>
      </tr>
    </table>
  2. cellpadding: Adds padding inside cells.

  3. cellspacing: Adds space between cells.

Example:

<table border="1" cellpadding="5" cellspacing="2">
  <tr>
    <th>Project</th>
    <th>Technology</th>
    <th>Status</th>
  </tr>
  <tr>
    <td>Portfolio Website</td>
    <td>HTML, CSS</td>
    <td>Completed</td>
  </tr>
</table>

Enhanced Portfolio Code

Here’s the updated portfolio code with a table in the "Projects" section:

<section id="projects">
  <h2>Projects</h2>
  <p>Here are some of my recent projects:</p>
  <table border="1" cellpadding="5" cellspacing="0">
    <caption>My Recent Projects</caption>
    <thead>
      <tr>
        <th>Project</th>
        <th>Technology</th>
        <th>Status</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Portfolio Website</td>
        <td>HTML, CSS</td>
        <td>Completed</td>
      </tr>
      <tr>
        <td>Weather App</td>
        <td>JavaScript</td>
        <td>In Progress</td>
      </tr>
      <tr>
        <td>Task Manager</td>
        <td>React, Node.js</td>
        <td>Completed</td>
      </tr>
    </tbody>
    <tfoot>
      <tr>
        <td colspan="3">Total Projects: 3</td>
      </tr>
    </tfoot>
  </table>
</section>

6. Forms for User Interaction

Forms allow users to input and submit information. In the context of a portfolio, a contact form is a great way to let visitors reach out directly. In this section, we’ll learn how to create and structure a contact form for the portfolio.

Basic Structure of a Form

The <form> tag is the container for all input elements. It includes attributes to define its behavior:

Basic Example:

<form action="submit-url" method="post">
  <input type="text" name="username" placeholder="Enter your name">
  <input type="submit" value="Submit">
</form>

Attributes:

  1. action: The URL where the form data will be sent (e.g., a server endpoint or email service).

    • For now, use # as a placeholder.
  2. method:

    • get: Sends data as part of the URL (e.g., search queries).
    • post: Sends data in the HTTP request body (more secure for sensitive data).

Common Input Elements

  1. Text Inputs:

    <input type="text" name="name" placeholder="Your Name">
  2. Email Inputs:

    <input type="email" name="email" placeholder="Your Email">
  3. Textarea:

    • For multi-line text input.
    <textarea name="message" rows="5" cols="30" placeholder="Your Message"></textarea>
  4. Buttons:

    • For form submission.
    <button type="submit">Send</button>
  5. Radio Buttons:

    • For single-choice options.
    <input type="radio" name="contact-method" value="email"> Email
    <input type="radio" name="contact-method" value="phone"> Phone
  6. Checkboxes:

    • For multiple-choice options.
    <input type="checkbox" name="subscribe" value="newsletter"> Subscribe to Newsletter
  7. Dropdowns:

    • For selecting from a list of options.
    <select name="inquiry-type">
      <option value="general">General Inquiry</option>
      <option value="project">Project Collaboration</option>
    </select>

Building the Contact Form

Let’s add a contact form to the "Contact" section of the portfolio:

<section id="contact">
  <h2>Contact</h2>
  <p>Feel free to reach out using the form below:</p>
  <form action="#" method="post">
    <!-- Name Input -->
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" placeholder="Your Name" required>

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

    <!-- Message Textarea -->
    <label for="message">Message:</label>
    <textarea id="message" name="message" rows="5" cols="30" placeholder="Your Message" required></textarea>

    <!-- Submit Button -->
    <button type="submit">Send Message</button>
  </form>
</section>

Enhancing Accessibility with Labels

Always pair inputs with <label> elements to improve accessibility. Use the for attribute in the label to link it to the input’s id.

Example:

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

Adding Validation

HTML5 provides built-in validation features, such as:

  1. required: Ensures the field is filled before submission.
  2. type="email": Validates email format.
  3. maxlength and minlength: Restricts the length of input.
  4. pattern: Matches input to a custom regular expression.

Example:

<input type="text" name="name" placeholder="Your Name" required minlength="3" maxlength="50">

Full Contact Form Code

Here’s the complete HTML code for the "Contact" section with a functional and accessible form:

<section id="contact">
  <h2>Contact</h2>
  <p>Feel free to reach out using the form below:</p>
  <form action="#" method="post">
    <!-- Name Input -->
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" placeholder="Your Name" required>

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

    <!-- Message Textarea -->
    <label for="message">Message:</label>
    <textarea id="message" name="message" rows="5" cols="30" placeholder="Your Message" required></textarea>

    <!-- Inquiry Type -->
    <label for="inquiry-type">Inquiry Type:</label>
    <select id="inquiry-type" name="inquiry-type">
      <option value="general">General Inquiry</option>
      <option value="project">Project Collaboration</option>
    </select>

    <!-- Submit Button -->
    <button type="submit">Send Message</button>
  </form>
</section>

7. Metadata and Document Optimization

In this section, we will enhance the portfolio by adding metadata and optimizing the document structure. Metadata helps improve SEO (Search Engine Optimization), ensures proper display across devices, and provides additional information to browsers and search engines.

1. The <head> Section

The <head> tag contains metadata and resources that do not appear on the webpage but are vital for its functionality and visibility.

Basic Elements of <head>:

  1. <title>:

    • Specifies the title of the webpage (appears in the browser tab).
    <title>My Portfolio</title>
  2. <meta charset="UTF-8">:

    • Ensures the webpage displays characters correctly, supporting special symbols and international characters.
    <meta charset="UTF-8">
  3. <meta name="viewport">:

    • Optimizes the website for mobile devices.
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  4. <meta name="description">:

    • Provides a short description of the webpage for search engines.
    <meta name="description" content="My portfolio showcasing web development skills and projects.">
  5. <link rel="icon">:

    • Adds a favicon (small icon displayed in the browser tab).
    <link rel="icon" href="images/favicon.ico" type="image/x-icon">

2. Adding Metadata to the Portfolio

Update the <head> section of your portfolio:

<head>
  <title>My Portfolio</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="My portfolio showcasing web development skills and projects.">
  <link rel="icon" href="images/favicon.ico" type="image/x-icon">
</head>

3. Adding Social Media Metadata

You can enhance your website's preview on social media platforms by adding Open Graph (OG) tags.

Example:

<meta property="og:title" content="My Portfolio">
<meta property="og:description" content="Showcasing web development skills and projects.">
<meta property="og:image" content="images/portfolio-preview.jpg">
<meta property="og:url" content="https://myportfolio.com">
<meta property="og:type" content="website">

4. Accessibility Features

Accessibility ensures that your portfolio is usable for people with disabilities.

Alt Text for Images:

Always use meaningful alt attributes in <img> tags.

<img src="images/profile.jpg" alt="Profile picture of [Your Name]">

Logical Heading Structure:

Use headings (<h1> to <h6>) in a logical and hierarchical order.

5. Performance Optimization

Improving page performance ensures a faster, smoother user experience.

  1. Minimize Image Sizes:

    • Use optimized image formats (.jpg, .png, .webp).
    • Compress images using tools like TinyPNG.
  2. Organize Files and Folders:

    • Create folders like images/, videos/, and audio/ to keep assets organized.
  3. Test Responsiveness:

    • Use the <meta name="viewport"> tag to ensure the layout adapts to different screen sizes.

6. Full Portfolio Code with Metadata

Here’s the complete portfolio code with metadata and document optimizations:

<!DOCTYPE html>
<html>
  <head>
    <title>My Portfolio</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="My portfolio showcasing web development skills and projects.">
    <link rel="icon" href="images/favicon.ico" type="image/x-icon">
    <meta property="og:title" content="My Portfolio">
    <meta property="og:description" content="Showcasing web development skills and projects.">
    <meta property="og:image" content="images/portfolio-preview.jpg">
    <meta property="og:url" content="https://myportfolio.com">
    <meta property="og:type" content="website">
  </head>
  <body>
    <!-- Header with Navigation -->
    <header>
      <h1>Welcome to My Portfolio</h1>
      <h2>Your One-Stop Showcase of My Skills and Projects</h2>
      <nav>
        <ul>
          <li><a href="#about-me">About Me</a></li>
          <li><a href="#skills">Skills</a></li>
          <li><a href="#projects">Projects</a></li>
          <li><a href="#contact">Contact</a></li>
        </ul>
      </nav>
    </header>

    <!-- Main Content -->
    <main>
      <section id="about-me">
        <h2>About Me</h2>
        <img src="images/profile.jpg" alt="Profile picture of [Your Name]" width="200">
        <p>I am a web developer passionate about creating efficient and engaging web applications.</p>
      </section>

      <section id="skills">
        <h2>Skills</h2>
        <ul>
          <li>HTML</li>
          <li>CSS</li>
          <li>JavaScript</li>
        </ul>
      </section>

      <section id="projects">
        <h2>Projects</h2>
        <p>Here are some of my recent projects:</p>
        <table border="1" cellpadding="5" cellspacing="0">
          <caption>My Recent Projects</caption>
          <thead>
            <tr>
              <th>Project</th>
              <th>Technology</th>
              <th>Status</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>Portfolio Website</td>
              <td>HTML, CSS</td>
              <td>Completed</td>
            </tr>
            <tr>
              <td>Weather App</td>
              <td>JavaScript</td>
              <td>In Progress</td>
            </tr>
            <tr>
              <td>Task Manager</td>
              <td>React, Node.js</td>
              <td>Completed</td>
            </tr>
          </tbody>
          <tfoot>
            <tr>
              <td colspan="3">Total Projects: 3</td>
            </tr>
          </tfoot>
        </table>
      </section>

      <section id="contact">
        <h2>Contact</h2>
        <p>Feel free to reach out using the form below:</p>
        <form action="#" method="post">
          <label for="name">Name:</label>
          <input type="text" id="name" name="name" placeholder="Your Name" required>
          <label for="email">Email:</label>
          <input type="email" id="email" name="email" placeholder="Your Email" required>
          <label for="message">Message:</label>
          <textarea id="message" name="message" rows="5" cols="30" placeholder="Your Message" required></textarea>
          <button type="submit">Send Message</button>
        </form>
      </section>
    </main>

    <!-- Footer -->
    <footer>
      <p>&copy; 2024 My Portfolio. All rights reserved.</p>
      <p>
        Find me on:
        <a href="https://github.com/yourusername" target="_blank">GitHub</a> |
        <a href="https://linkedin.com/in/yourusername" target="_blank">LinkedIn</a>
      </p>
    </footer>
  </body>
</html>