Top HTML Interview Questions and Answers

Are you an HTML developer looking to work with a top company, or a recruiter from a reputable company trying to find the right HTML expert? Either way, you’ve come to the right place. This set of HTML interview questions and answers will help developers prepare for real-world interviews and assist recruiters in spotting the best talent.

interview_bnr_img.png

Basic HTML Interview Questions for Freshers

The <section> tag is used to group similar content. For example, a webpage section. The <article> tag can be used for blog posts, news, or articles. <section> arranges the content.<article> is independent and reusable. The <div> tag is a general container to create a layout. 

The alt attribute in the <img> tag gives a textual description of the image. It has three main purposes.

1. Accessibility: Assists screen readers for the visually impaired.
2. Fallback: Shows when the image fails to load.
3. SEO: Enhances search engine understanding of the image.

<meta> tags give the webpage metadata like description, keywords and author. We can include them inside the <head> tag. These tags will not be visible on the website. These tags help with SEO and are useful for search engines and browsers to get information about a web page.

Example:

A <strong> tag and a <b> tag display the content in bold font. The only difference is that the <strong> tag is semantic. It emphasises the importance of content to search engines or screen readers.

We can use the <a> tag to create a hyperlink. The link has to be mentioned in the href attribute.

<a href="https://www.test.com">Click this link</a>. This is an external link that links to a site outside the current domain
<a href="/help.html">Help</a>. This is an internal link on the same website.
<a href="#sectiona">Go to Section A</a>. This is an anchor link that points to a specific section on a webpage.
<a href="mailto:test@test.com">Test Email</a> This is a mailto link that opens a mail service to send an email to the specified email address
<a href="tel:+91 9823427820">Call Me</a> This is a telephone link that allows you to make a call to the mentioned number

Void elements are the tags without a closing tag. They can't have any content inside. They close by self and do not strictly require a closing tag.

Examples: <br> <img> <input> <hr> <meta> <link> <area>, <base>, <col>, <embed>, <source>, <track>, <wbr>

Block-level elements start on a new line and take the 100% width of the parent element. They can contain other block elements or inline elements.

Examples: <div>, <p>, <h1> to <h6>, <section>, <article>

Inline elements do not start on a new line (without any break) and take only the required width. They can contain text or other inline elements.

Examples: <span>, <a>, <strong>, <img>, <em>

The DOCTYPE declaration tells the browser that the webpage is in HTML5 (modern HTML). This is to ensure that the browser renders the page correctly based on standard HTML rules or standards mode. This helps avoid quirks mode in which the browser may behave differently to support old code.

We can use the <textarea> tag to create a multi-line text input.

To create a multi-line text input in an HTML form, use the <textarea> element. The attribute rows sets the number of lines (height). The cols attribute sets the width.

Example:

HTML5 is the latest version of HTML. It supports new tags like <video>, <audio>, and <article>.  HTML5 has improved semantics, better multimedia support, and new APIs for modern web development.

Why waste time screening?

Hire expert developers, vetted and ready in 48 hours

Hire now
hire_block (1).png

Intermediate HTML Interview Questions

<figure> group media content like images, diagrams, or code snippets.

<figcaption> adds a caption or description for that content.

Semantic element clearly explains their meaning and allow browsers and developers to understand the structure. Some examples are, <header>, <footer>, <article>, and <section>. Semantic elements improve SEO.

Web storage in HTML5 is used to store data in the browser. It has both localStorage and sessionStorage. Local storage stores the data with no expiration time. The data remains until we clear it manually. Session storage stores data for one session only. The data stored in session storage gets cleared once you close the tab or the browser. Session storage is useful for saving user preferences or temporary information instead of cookies.

The purpose of the novalidate attribute is to inform the browser not to validate the form inputs before submitting. So, developers can validate the form using JavaScript or on the server instead of allowing the browser’s default form validation.

You can store custom information in HTML elements with the prefix data-. With this, you can access the information using JavaScript later.

Access through Javascript

When you do not want something to get rendered on a page, you can insert such HTML code inside the template tag. It remains reusable code and can be used later with JavaScript.

The <template> tag is used to define HTML code that is not rendered when the page loads. It serves as a reusable chunk of code that can be displayed later with JavaScript. This is useful for creating reusable UI parts at run time.

You can use the hreflang attribute in the <link> tag inside the <head> tag. Therefore, search engines can display the correct language version to the users based on the region.

ARIA stands for Accessible Rich Internet Applications. These are some attributes used to improve the accessibility of the web content, particularly for disabled people. It helps screen readers explain the purpose of each element on the webpage to the visually impaired users.

Here, when a visually impaired user accesses the button element, the screen reader can explain it as a close to the user.

The <iframe> tag is used to embed an external webpage within the current page. For example, videos, maps, and other webpages.

The <object> tag is used to embed various media or external resources such as PDFs, Flash files, or multimedia content.

The z-index property determines the stack order of elements on a web page. The higher the z-index, the element appears on top and vice versa. It works only on the elements that have the positions relative, absolute, or fixed.

Here, the second div will appear in front of the first div.

Advanced HTML Interview Questions for Experienced Professionals

Adding drag-and-drop functionality in HTML5 is important as it improves user interaction. For example, when an image is set as draggable, the user can drag it. You can use JavaScript to handle the drop actions as well. When the attribute draggable is set to true, the user will be able to drag the element.

The server-sent events (SSE) in HTML5 allow the server to send real-time updates (live notification, news feeds) to the browser. So, the client side doesn't need to request server updates every time.

You can use a combination of an unordered list <ul> or an ordered list <ol> along with nested <li> elements.

Use cases: Menus and submenus, Table of Contents, Categories and subcategories.

It's now outdated and replaced by Service Workers. A manifest file was used for making offline access to a web application through AppCache. It lists the HTML, CSS, JS, and image resources that the browser should cache and make available offline.

A shadow DOM is a feature that developers can use to build reusable, isolated ui components without thinking about CSS or JavaScript conflicts.

HTML parsing is the process of reading the html to create the DOM. Rendering is the process of applying styles and displaying the visual on the page.

Lazy loading loads the images when the user scrolls or is about to view an image on a webpage. This improves page load speed and performance. HTML5 uses the attribute loading=” lazy” to implement this.

XSS means Cross-Site Scripting (XSS) attacks through HTML inputs.

Always escape user input before rendering it on the HTML. Utilise content security policies, avoid inline JavaScript, and validate inputs always.

  • Sanitise User Input: Convert < to &lt;  > to &gt; & to &amp;
  • Use Proper Escaping
  • Content Security Policy (CSP): Block malicious scripts by adding a CSP header.
  • Avoid Inline JavaScript: Avoid inline scripts and add them to an external script file and handle using event handlers.
  • Validate and Limit Input: Allow only required data and set a limit for the input. Reject malicious content.
  • Use HTML5 Input Types: Use only HTML5 input types to avoid unnecessary inputs from the user.

<canvas> is used for dynamic, pixel-based, real-time graphics. Examples: Games, Image Editing

You can use <svg>for a scalable, vector-based graphic.SVG is interactive and accessible. Examples: Icons, logos, charts

You can define a relative URL for a webpage with the base tag. It becomes easy to manage the links.

Here, the image URL will be https://www.test.com/images/logo.png

This collection includes questions that cover everything from the basics to more advanced topics in HTML. Whether you’re preparing for an interview or trying to find a skilled developer, this guide can help. Tired of long hiring processes? WAC makes it easy to find skilled developers without waiting. And if you’re an experienced HTML developer aiming for a role with a leading company, these interview questions are worth checking out, and feel free to visit our careers page.

Hire Top Caliber HTML Developers

Quickly hire expert HTML developers. WAC helps you find vetted talent in 48 hours to supercharge your development efforts.

IKEA.svg
logo_service_caribou.svg
logo.svg
Lulu international.svg

Hire Software Developers

Get top pre-vetted software developers and scale your team in just 48 hours.

Hire Developers Now
team iamge

Insights

WAC 11th Anniversary - Kerala’s First-Ever Private Office Anniversary Celebration

WAC Creates History: Kerala’s First-Ever Private Office Anniversary Celebration

Top Advantages, Disadvantages and Limitations of Ecommerce - A Complete Guide

Top Advantages, Disadvantages and Limitations of Ecommerce - A Complete Guide

Speed up Your Website.png

10 ways to speed up your website