Skip to content

Latest commit

 

History

History
377 lines (274 loc) · 20.5 KB

File metadata and controls

377 lines (274 loc) · 20.5 KB

Q1. What is HTML, and what are its key components?

==> HTML is the standard language used to create and structure web pages. It provides the basic framework for web content by defining elements like headings, paragraphs, links, images, and more.

Key Components of HTML:

  1. Doctype Declaration (<!DOCTYPE html>) – Specifies the version of HTML being used.
  2. HTML Element (<html>) – The root element that wraps all content on the page.
  3. Head (<head>) – Contains metadata such as the title, character encoding, styles, and scripts.
  4. Title (<title>) – Defines the title of the web page, shown in the browser tab.
  5. Meta Tags (<meta>) – Provide metadata like character set, viewport settings, and SEO details.
  6. Body (<body>) – Contains the main content of the web page, such as text, images, and other elements.
  7. Headings (<h1> to <h6>) – Define hierarchical headings.
  8. Paragraphs (<p>) – Define blocks of text.
  9. Links (<a>) – Create hyperlinks to other pages or resources.
  10. Images (<img>) – Embed images into the page.
  11. Lists (<ul>, <ol>, <li>) – Define ordered and unordered lists.
  12. Tables (<table>, <tr>, <td>) – Create structured tabular data.
  13. Forms (<form>, <input>, <textarea>, <button>) – Collect user input.
  14. Semantic Elements (<section>, <article>, <header>, <footer>) – Provide meaning and structure to web pages.

Q2. What are the new features introduced in HTML5?

==> # New Features Introduced in HTML5
HTML5 brought several enhancements to web development, improving semantics, multimedia, form controls, APIs, and performance.

1. New Semantic Elements 🏷️

HTML5 introduced semantic elements to improve readability and SEO:

  • <header> – Defines the header section.
  • <nav> – Represents navigation links.
  • <section> – Groups content thematically.
  • <article> – Represents standalone content like blogs or news articles.
  • <aside> – Defines side content (e.g., ads, sidebars).
  • <footer> – Contains footer-related content.
  • <figure> & <figcaption> – For images, diagrams, and captions.

2. Multimedia Elements 🎥🎵

HTML5 replaced Flash with built-in support for audio and video:

  • <audio> – Embeds audio files (.mp3, .wav, .ogg).

  • <video> – Embeds video files (.mp4, .webm, .ogg).

  • <source> – Defines multiple media sources for compatibility.

  • <track> – Adds captions or subtitles to videos.

    3. Enhanced Form Elements 📝

HTML5 introduced new input types and attributes for better form handling:

New Input Types

  • email – Validates email input.

  • tel – Input for phone numbers.

  • url – Validates URL input.

  • date, datetime-local, time, month, week – For date and time selection.

  • range – A slider for selecting a numeric value.

  • color – Color picker.

  • number – Allows numeric input with increment/decrement buttons.

    4. Canvas API 🎨
    The <canvas> element allows for dynamic drawing of graphics, animations, and charts using JavaScript.

    5. Local Storage & Session Storage 💾
    HTML5 introduced the Web Storage API to store data locally in the browser.

  • LocalStorage – Stores data persistently.

  • SessionStorage – Stores data only for the session.

    6. Geolocation API 📍
    Enables websites to fetch the user's location.

📌 Example:

javascript
navigator.geolocation.getCurrentPosition(function(position) {
  console.log("Latitude: " + position.coords.latitude);
  console.log("Longitude: " + position.coords.longitude);
});

7. WebSockets 📡
Enables real-time communication between the client and server.

8. Drag & Drop API 🖱️
Allows elements to be dragged and dropped using JavaScript.

9. Web Workers 🏃
Allows running scripts in the background without affecting the main thread.

Q3. What Are Semantic HTML Elements?

==> Semantic HTML elements are elements that convey meaning about their content to both the browser and developers. Unlike non-semantic elements (<div>, <span>), semantic elements clearly define their purpose, improving SEO, accessibility, and readability.

For example:
<article> → Represents an independent content block (like a blog post).
<div class="article"> → Requires extra styling & description to give meaning.

Examples of Semantic HTML Elements 🏷️

Semantic Element Purpose
<header> Represents the top section of a page or article (usually contains a logo, navigation, etc.).
<nav> Defines navigation links (menus, breadcrumbs, etc.).
<section> Groups related content thematically.
<article> Represents self-contained content like a blog post or news article.
<aside> Defines side content, such as ads, sidebars, or related links.
<footer> Contains footer information (copyright, links, etc.).
<main> Identifies the main content of the document.
<figure> Wraps images, illustrations, charts, etc.
<figcaption> Provides a caption for the <figure> element.
<mark> Highlights text for emphasis.
<time> Represents a date or time.

Q4. What is the difference between <section>, <article>, <aside>, and <div>?

==> Difference Between <section>, <article>, <aside>, and <div>

Each of these elements serves a different structural purpose in HTML.

Element Purpose When to Use?
<section> Groups related content within a webpage. When content is thematically related but not a standalone article.
<article> Represents a self-contained, independent piece of content. When content can be shared or distributed separately (blog post, news, etc.).
<aside> Represents supplementary content, like sidebars or related links. When content is not part of the main flow but adds context (ads, links, etc.).
<div> A generic container with no specific meaning. When no semantic element fits, used mainly for styling and layout.

Q5. What is the difference between inline and block-level elements?

==> Key Differences: Block-Level vs. Inline Elements

Feature Block-Level Elements Inline Elements
Line Break Always start on a new line. Stays in the same line.
Width Takes the full width of its container. Takes only the required width.
Containment Can contain both block and inline elements. Can contain only text or other inline elements.
Use Case Used for layout structuring. Used for styling small portions of text.
Examples <div>, <p>, <section>, <article>, <header>, <footer> <span>, <a>, <strong>, <em>, <label>, <abbr>

Q6. What is the difference between id and class attributes?

==> Difference Between id and class Attributes

Feature id class
Uniqueness Unique (only one per page). Can be used for multiple elements.
Selector in CSS #id (e.g., #intro). .class (e.g., .highlight).
Selection in JavaScript document.getElementById("id"). document.getElementsByClassName("class") or querySelectorAll(".class").
Reusability Cannot be reused. Can be reused on multiple elements.
Priority in CSS Higher specificity. Lower specificity.

Q7. What is the purpose of the alt attribute in images?

==> Importance of the alt Attribute in the <img> Tag

The alt (alternative text) attribute provides a textual description of an image. It serves several important purposes:

1️⃣ Accessibility
For visually impaired users

  • Screen readers read the alt text aloud, allowing visually impaired users to understand the content of the image.

  • Improves web accessibility (following WCAG guidelines).

    2️⃣ SEO (Search Engine Optimization)
    Helps search engines understand images

  • Search engines like Google can't "see" images, but they can read alt text.

  • Properly written alt text improves image search rankings and website visibility.

    3️⃣ Display Issues (Backup for Broken Images)
    ✅ If an image fails to load, the alt text appears instead, giving users context.

Example:

<img src="missing-image.jpg" alt="Company logo">

Q8. What is the difference between GET and POST methods in forms?

==> When to Use GET vs. POST?

Use GET when retrieving public data (search queries, filters, sharing URLs).
Use POST when submitting sensitive or large data (forms, passwords, files).

Feature Comparison: GET vs. POST

Feature GET POST
Data Location URL (query string) Request body
Security Less secure (data visible in URL) More secure (data hidden)
Data Size Limit Limited (depends on URL length) No limit
Caching Can be cached Not cached
Browser History Stored Not stored
Use Case Search, filters, bookmarks Login, forms, file uploads

Q9. What is the purpose of the and tags?

==> Importance of the <fieldset> and <legend> Tags

The <fieldset> tag is used to group related form elements together, providing a container for them. It's often used for styling and accessibility purposes.

The <legend> tag is used to provide a caption or label for the <fieldset>. It's often used for accessibility and screen readers.

Example:

<fieldset>
  <legend>Personal Information</legend>
  <label for="name">Name:</label>
  <input type="text" id="name" name="name">
  <label for="email">Email:</label>
  <input type="email" id="email" name="email">
</fieldset>

When to Use <fieldset> and <legend>?

Use <fieldset> when your form has related sections (e.g., login info, payment details).
Use <legend> to describe the section’s purpose clearly.

Feature Comparison: <fieldset> vs. <legend>

Feature <fieldset> <legend>
Purpose Groups related inputs Provides a title for the group
Accessibility Helps screen readers understand structure Describes the section clearly
UI Improvement Visually separates form sections Labels the group for better readability
Best Practice Used when a form has multiple logical sections Always use inside <fieldset>

Q10. What is the difference between <input type="submit"> and <button>?

==> Difference Between <input type="submit"> and <button>

1. <input type="submit">
Purpose:

  • Used specifically to submit a form.
  • Has default styling based on the browser.
  • Cannot contain additional HTML elements inside.

🔹 Example Usage:

<form action="/submit" method="post">
  <input type="submit" value="Submit Form" />
</form>

2. <button>
Purpose:

  • Can be used for form submission, navigation, or JavaScript actions.
  • Can contain additional HTML elements inside.
  • Can be styled with CSS.

🔹 Example Usage:

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

When to Use <input type="submit"> vs. <button>?

Use <input type="submit"> if you just need a simple submit button with no extra customization.
Use <button> when you need more flexibility, custom styling, or interactive elements inside the button.

Feature Comparison: <input type="submit"> vs. <button>

Feature <input type="submit"> <button>
Purpose Only for form submission Can be used for form submission, navigation, JavaScript actions
Flexibility Limited styling & functionality Highly customizable
Can Contain HTML? ❌ No ✅ Yes (icons, images, etc.)
JavaScript Events Limited More event handling options
Browser Default Style Basic submit button style Can be fully styled with CSS

Q11. What Are HTML Meta Tags?

Meta tags are special elements in HTML that provide metadata (information about the webpage) to browsers and search engines. They are placed inside the <head> section of an HTML document and do not appear directly on the webpage.

🔹 Why Are Meta Tags Important?
SEO (Search Engine Optimization): Helps search engines understand page content.
Social Media Sharing: Defines how a page appears when shared on social media.
Browser Behavior & Compatibility: Controls viewport settings for mobile responsiveness.
Security & Privacy: Can prevent search engines from indexing certain pages.

🔹 Commonly Used Meta Tags in HTML

Meta Tag Purpose Example
Charset Defines character encoding (UTF-8 is recommended). <meta charset="UTF-8">
Viewport Makes the page responsive on mobile devices. <meta name="viewport" content="width=device-width, initial-scale=1.0">
Description Provides a short description of the webpage for search engines. <meta name="description" content="Best online store for electronics and gadgets.">
Keywords (Less used today) Lists keywords related to the page content. <meta name="keywords" content="electronics, gadgets, online store">
Author Specifies the author of the webpage. <meta name="author" content="John Doe">
Robots Controls how search engines index the page. <meta name="robots" content="index, follow">
Refresh/Redirect Refreshes or redirects the page automatically. <meta http-equiv="refresh" content="5; url=https://example.com">
Open Graph (OG) Tags Enhances how links appear when shared on social media. <meta property="og:title" content="Best Online Store">
Theme Color (For mobile browsers) Changes the browser tab or address bar color on mobile devices. <meta name="theme-color" content="#ff6600">

Q12. How do you optimize an HTML page for SEO?

==> Best Practices for SEO Optimization for an HTML Page (Short & Simple)

  • Use Proper Meta Tags – Add a unique title, meta description, and robots meta tag.
  • SEO-Friendly URLs – Keep URLs short, descriptive, and keyword-rich.
  • Optimize Headings – Use H1 for the main title, H2-H3 for structure.
  • Image Optimization – Use descriptive filenames, alt text, and compress images.
  • Improve Page Speed – Enable lazy loading, minify CSS/JS, and use a CDN.
  • Mobile-Friendly Design – Use responsive design and a viewport meta tag.
  • Internal & External Links – Link to relevant pages and credible external sources.
  • Schema Markup – Use structured data (JSON-LD) for rich search results.
  • HTTPS Security – Ensure your site is SSL-secured.
  • Submit Sitemap & Robots.txt – Help search engines index your site properly.

Q13. What is the difference between <iframe> and <embed>?

==> Difference Between <iframe> and <embed>

<iframe> vs <embed> in HTML

Both <iframe> and <embed> are used to include external content in an HTML document, but they serve different purposes and have different capabilities.

<iframe> (Inline Frame)

Purpose: Used to embed another HTML document or webpage inside the current page.
Supports: HTML, CSS, and JavaScript from the embedded page.
Interactivity: Can interact with the parent page using JavaScript (window.postMessage).
Common Attributes:

  • src
  • width
  • height
  • sandbox
  • allow

✅ Example:

<iframe src="https://example.com" width="600" height="400"></iframe>

<embed> (Embed)

Purpose: Used to embed media or plugins directly into the page.
Supports: Limited to media types (e.g., videos, Flash, etc.).
Interactivity: Limited interactivity; depends on the plugin.
Common Attributes:

  • src
  • type
  • width
  • height

✅ Example:

<embed
  src="https://example.com/video.mp4"
  type="video/mp4"
  width="600"
  height="400"
/>
Feature <iframe> <embed>
Purpose Embeds another HTML document or external content. Embeds media or plugins directly into the page.
Content Can contain an entire HTML document. Typically used for media (videos, Flash, etc.).
Control Offers more control over the embedded content. Less control; more dependent on the plugin.
Example <iframe src="https://example.com"></iframe> <embed src="https://example.com/video.mp4"></embed>