HTML Interview Question and Answer

1. What is HTML?

HTML (HyperText Markup Language) is the standard markup language used to create web pages. It structures web content using elements and tags.


  <!DOCTYPE html>
  <html>
    <head>
      <title>My First HTML Page</title>
    </head>
    <body>
      <h1>Welcome to HTML</h1>
      <p>This is a simple paragraph.</p>
    </body>
  </html>

2. What are the main features of HTML?

  • Platform-Independent: Works across all devices and operating systems.
  • Easy to Learn: Simple and beginner-friendly.
  • Supports Multimedia: Includes tags for videos, images, and audio.
  • Flexible: Integrates well with CSS, JavaScript, etc.
  • SEO-Friendly: Semantic tags improve search engine rankings.

3. What is the purpose of the <html> tag?

The <html> tag is the root of an HTML document and contains all other elements such as <head> and <body>.


  <html>
    <head>
        <title>HTML Example</title>
    </head>
    <body>
        <h1>Hello, World!</h1>
    </body>
  </html>

4. What is the difference between HTML and XHTML?

HTML XHTML
Forgiving syntax Strict syntax
Tags can be unclosed All tags must be closed
Case-insensitive for tags Tags must be lowercase
DOCTYPE optional DOCTYPE required

5. What is the latest version of HTML, and what are its new features?

The latest version of HTML is HTML5.

  • New semantic elements: <article>, <section>, <nav>.
  • Multimedia support: <audio> and <video>.
  • Canvas and SVG for graphics.
  • Form enhancements like type="email".

  <!DOCTYPE html>
  <html>
  <head>
      <title>HTML5 Features</title>
  </head>
  <body>
      <section>
          <h1>Welcome to HTML5</h1>
          <video controls>
              <source src="sample.mp4" type="video/mp4">
          </video>
      </section>
  </body>
  </html>

6. Explain the basic structure of an HTML document.

An HTML document includes the following:


  <!DOCTYPE html>
  <html>
  <head>
      <title>Page Title</title>
  </head>
  <body>
      <h1>Main Heading</h1>
      <p>Welcome to the website.</p>
  </body>
  </html>

7. What are empty elements in HTML? Provide examples.

Empty elements are tags without closing tags and content.

  • <br>: Line break
  • <img>: Embeds images
  • <meta>: Metadata

  <img src="image.jpg" alt="Example Image">
  <br>
  <meta charset="UTF-8">

8. What is semantic HTML? Why is it important?

Semantic HTML uses meaningful tags to improve accessibility and SEO.

  • <article>: Defines an article
  • <section>: Groups related content
  • <nav>: Navigation links

  <article>
  <h2>Semantic HTML</h2>
  <p>This is an example of using semantic tags.</p>
  </article>

9. How is an HTML file saved and opened?

Save the file with a .html or .htm extension using a text editor. Open the file in any browser to view the output.


  <!DOCTYPE html>
  <html>
  <head>
      <title>My HTML Page</title>
  </head>
  <body>
      <p>Hello, World!</p>
  </body>
  </html>

10. What is the difference between an HTML element and an HTML tag?

HTML Tag HTML Element
Part of an element (e.g., <p>, </p>). The complete structure (e.g., <p>Hello</p>).
Defines start or end. Includes tags and content.
  
    <p>HTML Example</p>
  

11. Explain the purpose of the <head> tag.

The <head> tag contains metadata and settings for the document, such as the title, styles, and scripts. This content is not displayed directly on the webpage.


  <head>
    <title>About HTML</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="styles.css">
  </head>

12. What does the <title> tag do?

The <title> tag specifies the title of the HTML document, which appears in the browser tab and search engine results.


  <head>
    <title>Learn HTML Basics</title>
  </head>

13. What is the <body> tag used for?

The <body> tag contains all the visible content of the webpage, such as text, images, videos, and other elements.


  <body>
    <h1>Welcome to My Website</h1>
    <p>This is the main content of the page.</p>
  </body>

14. What is the difference between <div> and <span>?

<div> <span>
Block-level element. Inline element.
Creates a new line. Does not create a new line.
Used for grouping block elements. Used for styling inline text.

  <div>This is a block-level element.</div>
  <p>This is an inline element: <span style="color:red;">Red Text</span></p>

15. How do you insert comments in HTML?

HTML comments are added using <!-- and --> and are ignored by the browser.


  <!-- This is a comment -->
  <p>This paragraph is visible.</p>
  <!-- <p>This paragraph is hidden.</p> -->

16. What is the use of the <meta> tag?

The <meta> tag provides metadata about the HTML document, such as character encoding, viewport settings, and descriptions for SEO.


  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="Learn HTML Basics">

17. How can you include an image in an HTML document?

The <img> tag is used to embed an image. The src attribute specifies the image path, and alt provides alternative text for accessibility.


  <img src="image.jpg" alt="Example Image" width="300" height="200">

18. What are block-level and inline elements? Provide examples.

Block-level elements take up the full width of the container and start on a new line, while inline elements only take up as much width as needed and appear within the same line as surrounding content.


  <div>This is a block element.</div>
  <p>This is an inline element: <span style="color:blue;">Blue Text</span></p>

19. What is the difference between <ol> and <ul>?

The <ol> tag creates an ordered (numbered) list, while <ul> creates an unordered (bulleted) list.


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

  <ul>
    <li>Bullet One</li>
    <li>Bullet Two</li>
    <li>Bullet Three</li>
  </ul>

20. What is the <a> tag? How do you create hyperlinks in HTML?

The <a> tag creates hyperlinks to other webpages, sections within the same page, or external resources.


  <a href="https://www.example.com" target="_blank">Visit Example</a>
  <a href="#section2">Go to Section 2</a>
  <h2 id="section2">Section 2</h2>

21. How do you create a form in HTML?

Forms are an essential part of web applications as they collect user input and send it to a server for processing. In HTML, forms are created using the <form> tag, which acts as a container for input elements like text fields, buttons, radio buttons, and more.

Key attributes of the <form> tag include:

  • action: Specifies the URL where the form data will be sent.
  • method: Defines the HTTP method to be used when submitting the form. Common values are GET and POST.

  <form action="/submit-form" method="post">
    <label for="username">Username:</label>
    <input type="text" id="username" name="username" required>
    <button type="submit">Submit</button>
  </form>

22. What is the purpose of the <input> tag?

The <input> tag is one of the most versatile HTML elements used to create various input controls in forms, such as text fields, checkboxes, radio buttons, and password fields. It supports different type attributes to customize the input behavior.

Some common type values include:

  • text: Single-line text input.
  • password: Input where characters are masked.
  • checkbox: Checkable input for binary choices.

    <input type="text" placeholder="Enter your name">
    <input type="checkbox" id="subscribe" name="subscribe" value="yes">
    <label for="subscribe">Subscribe to Newsletter</label>

23. List different input types in HTML5.

HTML5 introduced several new input types to enhance user experience and simplify data validation. Each input type ensures that the correct data format is entered, reducing the need for external validation.

Popular input types include:

  • email: Validates email addresses automatically.
  • date: Provides a date picker interface.
  • range: Displays a slider for numerical input.
  • color: Opens a color picker tool.

  <input type="email" placeholder="Enter your email">
  <input type="date">
  <input type="color">

24. What is the difference between the name and id attributes in a form?

The name and id attributes serve different purposes in forms:

Attribute Description
name Used to identify the form field when data is submitted to the server.
id Uniquely identifies an element within the HTML document, often for CSS or JavaScript usage.

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

25. How do you create a dropdown menu in a form?

A dropdown menu is created using the <select> tag in HTML, with each option defined by the <option> tag. Dropdown menus are widely used to allow users to select one option from a predefined list.


  <label for="country">Choose your country:</label>
  <select id="country" name="country">
    <option value="us">United States</option>
    <option value="ca">Canada</option>
    <option value="uk">United Kingdom</option>
  </select>

26. What is the <label> tag? Why is it important in forms?

The <label> tag associates a text label with a specific input element, improving accessibility and usability. Clicking on the label also activates the associated input field.


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

27. How do you create a radio button group in a form?

Radio buttons are used when you want the user to select only one option from a predefined group. To group radio buttons, use the same name attribute for each button in the group.


  <label>
    <input type="radio" name="gender" value="male"> Male
  </label>
  <label>
    <input type="radio" name="gender" value="female"> Female
  </label>

28. How can you specify a default value for an input field?

You can specify a default value for an input field by using the value attribute. For radio buttons or checkboxes, use the checked attribute to set the default option.


  <input type="text" name="username" value="Guest">
  <input type="radio" name="gender" value="male" checked> Male

29. What is the <textarea> tag used for?

The <textarea> tag is used for creating a multi-line text input field, ideal for collecting longer text inputs like comments or messages.


  <label for="message">Message:</label>
  <textarea id="message" name="message" rows="4" cols="50">Default text</textarea>

30. How do you validate a form using HTML5?

HTML5 introduces built-in validation attributes to ensure user input meets specific criteria. Common validation attributes include:

  • required: Ensures the field is not left blank.
  • min and max: Sets numerical boundaries.
  • pattern: Validates input using regular expressions.

  <form>
    <label for="email">Email:</label>
    <input type="email" id="email" name="email" required>
    <label for="age">Age:</label>
    <input type="number" id="age" name="age" min="18" max="99">
    <button type="submit">Submit</button>
  </form>

31. How do you embed a video in an HTML document?

To embed a video in an HTML document, you use the <video> tag. The <video> tag supports attributes like controls, autoplay, loop, and muted to control playback behavior.


  <video controls width="640" height="360">
    <source src="example.mp4" type="video/mp4">
    Your browser does not support the video tag.
  </video>

32. How do you embed audio in an HTML document?

Embedding audio in HTML is done using the <audio> tag. You can add attributes like controls, autoplay, and loop for customization.


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

33. What is the <iframe> tag, and how is it used?

The <iframe> tag is used to embed another HTML document or external content (like YouTube videos) within the current page.


  <iframe src="https://www.example.com" width="600" height="400" frameborder="0">
    Your browser does not support iframes.
  </iframe>

34. How do you add captions to a video in HTML?

You can add captions to a video using the <track> tag within the <video> tag. The <track> tag requires attributes like kind, src, and label.


  <video controls>
    <source src="movie.mp4" type="video/mp4">
    <track src="captions.vtt" kind="subtitles" srclang="en" label="English">
  </video>

35. What are the supported video formats in HTML5?

HTML5 supports the following video formats:

  • MP4: Widely supported, uses H.264 codec.
  • WebM: Uses VP8/VP9 codec, optimized for web.
  • Ogg: Uses Theora codec.

36. How can you control audio playback in HTML?

Audio playback is controlled using attributes like controls for a user interface, autoplay to start playback automatically, loop to repeat, and muted to start without sound.


  <audio controls autoplay loop muted>
    <source src="audio.mp3" type="audio/mpeg">
  </audio>

37. Explain the <canvas> element and its uses.

The <canvas> element is used for rendering graphics on the fly via JavaScript. It is ideal for creating interactive content like games, charts, and animations.


  <canvas id="myCanvas" width="200" height="100">
    Your browser does not support the canvas element.
  </canvas>

  <script>
    var canvas = document.getElementById('myCanvas');
    var ctx = canvas.getContext('2d');
    ctx.fillStyle = 'blue';
    ctx.fillRect(10, 10, 150, 75);
  </script>

38. What is the difference between <embed> and <object> tags?

The <embed> and <object> tags are used to embed external resources like PDFs or multimedia files into an HTML document. The key differences are:

<embed> <object>
Directly embeds content into the page. Provides more control over the embedded content.
Does not allow fallback content. Allows fallback content if the resource fails to load.

39. How do you embed external content into your webpage?

To embed external content, use tags like <iframe>, <embed>, or <object>, depending on the type of resource.


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

40. How do you create an image map in HTML?

An image map allows you to create clickable areas on an image that link to different destinations. Use the <map> and <area> tags.


  <img src="image.jpg" usemap="#mapname" alt="Example Image">
  <map name="mapname">
    <area shape="rect" coords="0,0,100,100" href="https://example.com">
    <area shape="circle" coords="150,75,50" href="https://another.com">
  </map>

41. What are global attributes in HTML?

Global attributes can be applied to any HTML element. Common global attributes include:

  • class: Assigns a CSS class to the element.
  • id: Assigns a unique identifier.
  • style: Adds inline CSS styling.
  • title: Adds a tooltip on hover.
  • data-*: Custom attributes for storing data.

42. Explain the class and id attributes in HTML.

The class and id attributes are used for identifying and styling HTML elements:

  • class: Used to group elements for styling with CSS. Multiple elements can share the same class.
  • id: Used to uniquely identify a single element. Should only be used once per page.

    <div class="container">Content</div>
    <div id="uniqueId">Unique Content</div>

43. What is the alt attribute in the <img> tag?

The alt attribute provides alternative text for an image, improving accessibility and SEO. It is displayed if the image fails to load.


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

44. How does the src attribute work in HTML?

The src (source) attribute specifies the location of external resources such as images, videos, or scripts.


    <img src="path/to/image.jpg" alt="Example Image">
    <script src="script.js"></script>

45. What is the difference between target="_blank" and target="_self"?

The target attribute specifies where to open a linked document:

  • _blank: Opens the link in a new tab or window.
  • _self: Opens the link in the same tab (default behavior).

  <a href="https://example.com" target="_blank">Open in New Tab</a>
  <a href="https://example.com" target="_self">Open in Same Tab</a>

46. What are custom data attributes (data-*)?

Custom data attributes allow embedding additional information into HTML elements. They are prefixed with data- and can be accessed in JavaScript.


    <div data-id="123" data-role="admin">Content</div>

47. How do you use the style attribute in HTML?

The style attribute allows inline CSS styling directly on an element.


    <p style="color: blue; font-size: 16px;">Styled Text</p>

48. What is the title attribute used for?

The title attribute specifies additional information about an element, shown as a tooltip when the user hovers over the element.


    <img src="image.jpg" alt="Image" title="This is a tooltip">

49. Explain the rel attribute in the <link> tag.

The rel attribute defines the relationship between the current document and the linked resource. Common values include:

  • stylesheet: Links an external CSS file.
  • icon: Links a favicon.

  <link rel="stylesheet" href="styles.css">
  <link rel="icon" href="favicon.ico">

50. What is the href attribute?

The href (hyperlink reference) attribute specifies the URL of the resource being linked, such as stylesheets or anchor links.


  <a href="https://example.com">Visit Example</a>
  <link href="styles.css" rel="stylesheet">

51. What is the purpose of the <article> tag?

The <article> tag defines self-contained content that is meant to be independently distributable or reusable. Examples include blog posts, news articles, or forum posts.


  <article>
    <h2>Understanding the Article Tag</h2>
    <p>The <article> tag is perfect for standalone pieces of content.</p>
  </article>

52. What is the <section> tag? How is it different from <div>?

The <section> tag represents a thematic grouping of content, typically with a heading. Unlike <div>, <section> carries semantic meaning and helps structure the document logically.


  <section>
    <h2>About Us</h2>
    <p>Information about the company.</p>
  </section>

53. Explain the <nav> tag.

The <nav> tag defines a block of navigation links. It is typically used for primary or secondary menus on a webpage.


  <nav>
    <ul>
      <li><a href="index.html">Home</a></li>
      <li><a href="about.html">About</a></li>
      <li><a href="contact.html">Contact</a></li>
    </ul>
  </nav>

54. What is the <footer> tag used for?

The <footer> tag represents the footer section of a document or section, often containing author information, copyright notices, or navigation links.


  <footer>
    <p>© 2025 Your Company Name. All rights reserved.</p>
  </footer>

55. What is the <aside> tag?

The <aside> tag defines content that is indirectly related to the main content, such as sidebars, advertisements, or related links.


  <aside>
    <h3>Related Articles</h3>
    <ul>
      <li><a href="article1.html">Article 1</a></li>
      <li><a href="article2.html">Article 2</a></li>
    </ul>
  </aside>

56. How does the <header> tag differ from <head>?

The <header> tag is used for content headers, such as logos or navigation menus, while <head> is for metadata and links to external resources.


  <header>
    <h1>Welcome to Our Site</h1>
    <nav>...</nav>
  </header>

57. What is the purpose of the <figure> and <figcaption> tags?

The <figure> tag groups media content, such as images or diagrams, with a <figcaption> tag to describe it.


  <figure>
    <img src="image.jpg" alt="A beautiful sunset">
    <figcaption>A breathtaking sunset over the ocean.</figcaption>
  </figure>

58. How do you use the <progress> tag in HTML5?

The <progress> tag displays progress of a task, such as file uploads or installation processes.


  <progress value="70" max="100">70%</progress>

59. What is the <time> tag used for?

The <time> tag represents a specific time or date, which can be machine-readable for applications like calendars or event tracking.


  <time datetime="2025-01-01">January 1, 2025</time>

60. What is the <dialog> tag?

The <dialog> tag is used to create a dialog box or modal window for user interactions like forms or notifications.


    <dialog open>
    <p>This is a dialog box.</p>
    <button>Close</button>
    </dialog>

61. What is ARIA in HTML?

ARIA (Accessible Rich Internet Applications) attributes improve accessibility by defining roles, states, and properties for interactive HTML elements.


  <button aria-label="Submit form">Submit</button>

62. How do you make a website accessible using HTML?

Accessibility in HTML involves using semantic elements, ARIA roles, proper labels, and keyboard navigation to ensure usability for all users, including those with disabilities.

63. What is the importance of the lang attribute in HTML?

The lang attribute specifies the language of the content, aiding screen readers and search engines in providing better services.


<html lang="en">

64. How do you use the tabindex attribute?

The tabindex attribute controls the order of elements when navigating using the keyboard's Tab key.


<button tabindex="1">First</button>
<button tabindex="2">Second</button>

65. What is the purpose of the aria-label attribute?

The aria-label attribute provides an accessible name for elements that don't have visible labels.


<button aria-label="Close"></button>

66. How do you create a responsive website using HTML?

Responsive websites adapt to different screen sizes. Use the viewport meta tag and CSS media queries for responsiveness.


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

67. What is the role of HTML in SEO?

HTML plays a vital role in SEO by using semantic tags, proper headings, meta tags, and alt attributes to make content discoverable by search engines.

68. What are semantic elements, and how do they help accessibility?

Semantic elements like <header>, <article>, and <footer> give meaning to content, making it more accessible and improving SEO.

69. Why should you avoid inline styles in HTML?

Inline styles make code less maintainable and harder to reuse compared to external stylesheets.

70. How do you optimize images in HTML for faster loading?

Use compressed image formats like WebP, responsive images with srcset, and the loading="lazy" attribute.


    <img src="image.jpg" loading="lazy" alt="Optimized Image">

71. What is lazy loading in HTML?

Lazy loading defers the loading of non-critical resources like images until they are needed, improving page performance.

72. How do you use the <picture> tag for responsive images?

The <picture> tag allows you to specify multiple image sources for different screen sizes or resolutions.


  <picture>
  <source srcset="image-large.jpg" media="(min-width: 800px)">
  <source srcset="image-small.jpg" media="(max-width: 799px)">
  <img src="fallback.jpg" alt="Responsive Image">
  </picture>

73. How do you include external JavaScript in an HTML document?

Use the <script> tag with the src attribute to include external JavaScript files.


  <script src="script.js"></script>

74. What is the difference between async and defer attributes in <script>?

Both attributes improve JavaScript loading, but:

  • async: Loads script asynchronously but may execute out of order.
  • defer: Ensures scripts execute in order after the HTML parsing is complete.

75. What is the <base> tag?

The <base> tag specifies a base URL for all relative links in a document, simplifying URL management.


  <base href="https://example.com/">

76. How do you minimize HTML file size?

Minimizing an HTML file size is crucial for improving page load speed and performance. Techniques include:

  • Removing unnecessary whitespace and comments.
  • Using minified versions of CSS and JavaScript files.
  • Inlining critical CSS and deferring non-essential resources.
  • Using tools like HTMLMinifier to automate minification.

  <!-- Minified Example -->
  <!DOCTYPE html><html><head><title>Minimized</title></head><body><h1>Hello</h1></body></html>

77. How do you prevent the browser from caching your HTML?

To prevent browsers from caching your HTML content, you can use cache-busting techniques like:

  • Appending a query string with a version number to resource URLs:
  • 
      <script src="script.js?v=2.0"></script>
    
    
  • Setting cache-control headers via the server:
  • 
      Cache-Control: no-store, no-cache, must-revalidate
    
    

78. What are some best practices for HTML coding?

Best practices for writing clean and maintainable HTML include:

  • Using semantic tags like <header> and <article> for better accessibility and SEO.
  • Keeping HTML indentation consistent for readability.
  • Avoiding inline styles; use external CSS instead.
  • Using descriptive and unique IDs and classes.
  • Ensuring all images have meaningful alt attributes for accessibility.

79. How do you debug HTML code?

Debugging HTML involves identifying and fixing issues in the document. Common debugging steps include:

  • Using browser developer tools to inspect and modify elements dynamically.
  • Validating your HTML code with the W3C Validator.
  • Checking browser compatibility for your tags and attributes.
  • Testing your site in different screen sizes and devices.

80. How do you use the <noscript> tag?

The <noscript> tag defines content to display if JavaScript is disabled or not supported by the browser. It is particularly useful for providing fallback messages or alternative content.


  <noscript>
    <p>JavaScript is required to view this page properly.</p>
  </noscript>

81. What is the difference between inline, block, and inline-block elements?

HTML elements are categorized as inline, block, or inline-block based on their behavior in the document flow:

  • Inline: Does not start a new line and only takes up as much width as necessary (e.g., <span>, <a>).
  • Block: Starts on a new line and takes up the full width of the container (e.g., <div>, <p>).
  • Inline-block: Behaves like inline elements but allows setting width and height.

    <!-- Example -->
    <div style="display: block;">Block Element</div>
    <span style="display: inline;">Inline Element</span>
    <div style="display: inline-block; width: 100px;">Inline-Block Element</div>

82. What is the difference between the <script> and <noscript> tags?

The <script> tag is used to include JavaScript in an HTML document, while the <noscript> tag defines content displayed if JavaScript is disabled or not supported by the browser.


  <script>
    console.log('JavaScript is enabled!');
  </script>

  <noscript>
    <p>Your browser does not support JavaScript.</p>
  </noscript>

83. What is the role of the <data> tag in HTML?

The <data> tag links a piece of content with a machine-readable value. It is commonly used for structured data or metadata representation.


  <p>Price: <data value="29.99">$29.99</data></p>

84. How do you create a tooltip in HTML?

You can create a tooltip by using the title attribute. The tooltip is displayed when the user hovers over the element.


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

85. What is the purpose of the <template> tag?

The <template> tag is used to define reusable HTML fragments that are not rendered directly in the DOM. They can be cloned and inserted dynamically using JavaScript.


    <template id="myTemplate">
    <p>This is a reusable template.</p>
    </template>

    <script>
    const template = document.getElementById('myTemplate');
    document.body.appendChild(template.content.cloneNode(true));
    </script>

86. How do you create a favicon for a website?

A favicon is a small icon displayed in the browser tab. To include one, use the <link> tag with rel="icon".


  <link rel="icon" href="favicon.ico" type="image/x-icon">

87. How do you make a hyperlink open in a new tab?

To make a hyperlink open in a new tab, use the target="_blank" attribute in the <a> tag.


  <a href="https://example.com" target="_blank">Open in New Tab</a>

88. What is the difference between relative and absolute URLs?

Relative URLs: Specify a path relative to the current document.

Absolute URLs: Specify the full path, including the protocol and domain name.


  <!-- Relative URL -->
  <a href="about.html">About Us</a>

  <!-- Absolute URL -->
  <a href="https://example.com/about.html">About Us</a>

89. What is the difference between <strong> and <b> tags?

Both tags make text bold, but <strong> conveys importance semantically, while <b> is purely presentational.


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

90. What is the difference between <em> and <i> tags?

Both tags italicize text, but <em> conveys emphasis semantically, while <i> is purely for presentation.


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

91. What are custom HTML data attributes?

Custom data attributes allow you to store additional data directly in HTML elements using attributes prefixed with data-.


  <div data-id="123" data-role="admin">User Info</div>

92. What is the purpose of the <base> tag?

The <base> tag specifies a base URL for all relative links in the document, making it easier to manage multiple relative URLs.


  <base href="https://example.com/">

93. What is the <meta> viewport tag, and why is it important?

The <meta> viewport tag controls the layout and scaling of a webpage on different screen sizes, making it essential for responsive design.


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

94. How do you use the <address> tag in HTML?

The <address> tag is used to define contact information for the author or owner of the document.


  <address>
  Written by John Doe.<br>
  Visit us at: <a href="https://example.com">Example</a>
  </address>

95. What is the <abbr> tag?

The <abbr> tag represents an abbreviation or acronym, providing the full form when hovered over.


  <p>The term <abbr title="Hypertext Markup Language">HTML</abbr> is widely used.</p>

96. What is the difference between ordered and unordered lists?

<ol> creates an ordered (numbered) list, while <ul> creates an unordered (bulleted) list.


  <ol>
    <li>First Item</li>
    <li>Second Item</li>
  </ol>

  <ul>
    <li>Bullet Item</li>
    <li>Another Item</li>
  </ul>

97. How do you create a horizontal rule in HTML?

The <hr> tag is used to create a horizontal rule, which acts as a thematic break.


  <hr>

98. What is the purpose of the <mark> tag?

The <mark> tag highlights text, indicating relevance or importance.


  <p>This is <mark>important</mark> text.</p>

99. How do you include an external CSS file in HTML?

Use the <link> tag to include an external CSS file in the <head> section of your HTML document.


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

100. How do you include inline CSS in HTML?

Use the style attribute within an HTML tag to include inline CSS.


  <p style="color: red; font-size: 16px;">This is styled text.</p>