Skip to content

๐ŸŸฃ HTML5 coding interview questions and answers for web developers.

Notifications You must be signed in to change notification settings

kchaitu27/html5-interview-questions

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 

Repository files navigation

๐Ÿ–ฒ Top 54 HTML5 interview questions and answers in 2021

You can check all 54 HTML5 tech interview questions here ๐Ÿ‘‰ https://devinterview.io/dev/html5-interview-questions


๐Ÿ”น 1. Write a HTML table tag sequence that outputs the following

Answer:

Write a HTML table tag sequence that outputs the following:

50 pcs 100 500
10 pcs 5 50

Answer:

<table>
  <tr>
    <td>50 pcs</td>
    <td>100</td>
    <td>500</td>
  </tr>
  <tr>
    <td>10 pcs</td>
    <td>5</td>
    <td>50</td>
  </tr>
</table>
Source:ย toptal.comย  ย 


๐Ÿ”น 2. What is an iframe and how it works?

Answer:

An iframe is an HTML document which can be embedded inside another HTML page.

Example:

<iframe src="https://github.com" height="300px" width="300px"></iframe>
Source:ย github.com/FuelFrontendย  ย 


๐Ÿ”น 3. Explain meta tags in HTML

Answer:

  • Meta tags always go inside head tag of the HTML page
  • Meta tags is always passed as name/value pairs
  • Meta tags are not displayed on the page but intended for the browser
  • Meta tags can contain information about character encoding, description, title of the document etc,

Example:

<!DOCTYPE html>
<html>
<head>
  <meta name="description" content="I am a web page with description"> 
  <title>Home Page</title>
</head>
<body>

</body> </html>

Source:ย github.com/FuelFrontendย  ย 


๐Ÿ”น 4. What is the purpose of the alt attribute on images?

Answer:

The alt attribute provides alternative information for an image if a user cannot view it. The alt attribute should be used to describe any images except those which only serve a decorative purposes, in which case it should be left empty.

Source:ย developer.mozilla.orgย  ย 


๐Ÿ”น 5. What is the difference between span and div?

Answer:

  • div is a block element
  • span is inline element

For bonus points, you could point out that itโ€™s illegal to place a block element inside an inline element, and that while div can have a p tag, and a p tag can have a span, it is not possible for span to have a div or p tag inside.

Source:ย thatjsdude.comย  ย 


๐Ÿ”น 6. How can you highlight text in HTML?

Answer:

If you are working with an HTML5 page, the <mark> tag can be a quick and easy way of highlighting or marking text on a page:

<mark>highlighted text</mark>

To highlight text with just HTML code and support for all browsers, set the background-color style, as shown in the example below, using the HTML tag.

<span style="background-color: #FFFF00">Yellow text.</span>
Source:ย computerhope.comย  ย 


๐Ÿ”น 7. What were some of the key goals and motivations for the HTML5 specification?

Answer:

HTML5 was designed to replace HTML 4, XHTML, and the HTML DOM Level 2. The key goals and motivations behind the HTML5 specification were to:

  • Deliver rich content (graphics, movies, etc.) without the need for additional plugins, such as Flash.
  • Provide better semantic support for web page structure through new structural element tags.
  • Provide a stricter parsing standard to simplify error handling, ensure more consistent cross-browser behaviour, and simplify compatibility with documents written to older standards.
  • Provide better cross-platform support whether running on a PC, Tablet, or Smartphone.
Source:ย toptal.comย  ย 


๐Ÿ”น 8. What is Character Encoding?

Answer:

To display an HTML page correctly, a web browser must know which character set (character encoding) to use. This is specified in the tag:

HTML4:

<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">

HTML5:

<meta charset="UTF-8">
Source:ย w3schools.comย  ย 


๐Ÿ”น 9. What is a self closing tag?

Answer:

In HTML5 it is not strictly necessary to close certain HTML tags. The tags that arenโ€™t required to have specific closing tags are called โ€œself closingโ€ tags.

An example of a self closing tag is something like a line break (<br />) or the meta tag (<meta>). This means that the following are both acceptable:

<meta charset="UTF-8">
...
<meta charset="UTF-8" />
Source:ย blog.teamtreehouse.comย  ย 


๐Ÿ”น 10. How Can I Get Indexed Better by Search Engines?

Answer:

It is possible to get indexed better by placing the following two statements in the <HEAD> part of your documents:

<META NAME="keywords" CONTENT="keyword keyword keyword keyword">
<META NAME="description" CONTENT="description of your site">

Both may contain up to 1022 characters. If a keyword is used more than 7 times, the keywords tag will be ignored altogether. Also, you cannot put markup (other than entities) in the description or keywords list.

Source:ย freejavaguide.comย  ย 


๐Ÿ”น 11. Briefly describe the correct usage of the following HTML5 semantic elements: header, article, section, footer

Answer:

  • <header> is used to contain introductory and navigational information about a section of the page. This can include the section heading, the authorโ€™s name, time and date of publication, table of contents, or other navigational information.

  • <article> is meant to house a self-contained composition that can logically be independently recreated outside of the page without losing itโ€™s meaining. Individual blog posts or news stories are good examples.

  • <section> is a flexible container for holding content that shares a common informational theme or purpose.

  • <footer> is used to hold information that should appear at the end of a section of content and contain additional information about the section. Authorโ€™s name, copyright information, and related links are typical examples of such content.

Source:ย w3schools.comย  ย 


๐Ÿ”น 12. hat's the difference between an "attribute" and a "property" in HTML?

Answer:

Attributes are defined on the HTML markup but properties are defined on the DOM. To illustrate the difference, imagine we have this text field in our HTML: <input type="text" value="Hello">.

const input = document.querySelector('input');
console.log(input.getAttribute('value')); // Hello
console.log(input.value); // Hello

But after you change the value of the text field by adding "World!" to it, this becomes:

console.log(input.getAttribute('value')); // Hello
console.log(input.value); // Hello World!
Source:ย github.com/yangshunย  ย 


๐Ÿ”น 13. When is it appropriate to use the small element?

Answer:

The HTML <small> element makes the text font size one size smaller (for example, from large to medium, or from small to x-small) down to the browser's minimum font size. In HTML5, this element is repurposed to represent side-comments and small print, including copyright and legal text, independent of its styled presentation.

Consider:

<img src="image.jpg" alt="London by night">
<small>The copyright of this image is owned by Aurelio De Rosa</small>
Source:ย developer.mozilla.orgย  ย 


๐Ÿ”น 14. How do you serve a page with content in multiple languages?

Answer:

The question is a little vague, I will assume that it is asking about the most common case, which is how to serve a page with content available in multiple languages, but the content within the page should be displayed only in one consistent language.

When an HTTP request is made to a server, the requesting user agent usually sends information about language preferences, such as in the Accept-Language header. The server can then use this information to return a version of the document in the appropriate language if such an alternative is available. The returned HTML document should also declare the lang attribute in the <html> tag, such as <html lang="en">...</html>.

In the back end, the HTML markup will contain i18n placeholders and content for the specific language stored in YML or JSON formats. The server then dynamically generates the HTML page with content in that particular language, usually with the help of a back end framework.

Source:ย w3.orgย  ย 


๐Ÿ”น 15. What's new in HTML 5?

Answer:

HTML 5 adds a lot of new features to the HTML specification

New Doctype

Still using that pesky, impossible-to-memorize XHTML doctype?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

If so, why? Switch to the new HTML5 doctype. You'll live longer -- as Douglas Quaid might say.

<!DOCTYPE html>

New Structure

  • <section> - to define sections of pages
  • <header> - defines the header of a page
  • <footer> - defines the footer of a page
  • <nav> - defines the navigation on a page
  • <article> - defines the article or primary content on a page
  • <aside> - defines extra content like a sidebar on a page
  • <figure> - defines images that annotate an article

New Inline Elements

These inline elements define some basic concepts and keep them semantically marked up, mostly to do with time:

  • <mark> - to indicate content that is marked in some fashion
  • <time> - to indicate content that is a time or date
  • <meter> - to indicate content that is a fraction of a known range - such as disk usage
  • <progress> - to indicate the progress of a task towards completion

New Form Types

  • <input type="datetime">
  • <input type="datetime-local">
  • <input type="date">
  • <input type="month">
  • <input type="week">
  • <input type="time">
  • <input type="number">
  • <input type="range">
  • <input type="email">
  • <input type="url">

New Elements

There are a few exciting new elements in HTML 5:

  • <canvas> - an element to give you a drawing space in JavaScript on your Web pages. It can let you add images or graphs to tool tips or just create dynamic graphs on your Web pages, built on the fly.
  • <video> - add video to your Web pages with this simple tag.
  • <audio> - add sound to your Web pages with this simple tag.

No More Types for Scripts and Links

You possibly still add the type attribute to your link and script tags.

<link rel="stylesheet" href="path/to/stylesheet.css" type="text/css" />
<script type="text/javascript" src="path/to/script.js"></script>

This is no longer necessary. It's implied that both of these tags refer to stylesheets and scripts, respectively. As such, we can remove the type attribute all together.

<link rel="stylesheet" href="path/to/stylesheet.css" />
<script src="path/to/script.js"></script>

Make your content editable

The new browsers have a nifty new attribute that can be applied to elements, called contenteditable. As the name implies, this allows the user to edit any of the text contained within the element, including its children. There are a variety of uses for something like this, including an app as simple as a to-do list, which also takes advantage of local storage.

<h2> To-Do List </h2>
<ul contenteditable="true">
<li> Break mechanical cab driver. </li>
<li> Drive to abandoned factory
<li> Watch video of self </li>
</ul>

Attributes

  • require to mention the form field is required
  • autofocus puts the cursor on the input field
Source:ย github.com/FuelFrontendย  ย 


๐Ÿ”น 16. What is the difference between section and div?

Answer:

  • <section> means that the content inside is grouped (i.e. relates to a single theme), and should appear as an entry in an outline of the page.

  • <div>, on the other hand, does not convey any meaning, aside from any found in its class, lang and title attributes.

Source:ย stackoverflow.comย  ย 


๐Ÿ”น 17. Where and why is the rel="noopener" attribute used?

Answer:

The rel="noopener" is an attribute used in <a> elements (hyperlinks). It prevents pages from having a window.opener property, which would otherwise point to the page from where the link was opened and would allow the page opened from the hyperlink to manipulate the page where the hyperlink is.

Source:ย developers.google.comย  ย 


๐Ÿ”น 18. Can a web page contain multiple <header> elements? What about <footer> elements?

Answer:

Yes to both. The W3 documents state that the tags represent the header(<header>) and footer(<footer>) areas of their nearest ancestor "section". So not only can the page <body> contain a header and a footer, but so can every <article> and <section> element.

Source:ย stackoverflow.comย  ย 


๐Ÿ”น 19. What is WebSQL?

Answer:

  • WebSQL is database API for client (browser) database using SQL.
  • Similar to SQL, API are pretty simple.
  • Not all the browser supports WebSQL.
  • As of now WebSQL is deprecated.
Source:ย github.com/FuelFrontendย  ย 


๐Ÿ”น 20. What is the DOM?

Answer:

The DOM (Document Object Model) is a cross-platform API that treats HTML and XML documents as a tree structure consisting of nodes. These nodes (such as elements and text nodes) are objects that can be programmatically manipulated and any visible changes made to them are reflected live in the document. In a browser, this API is available to JavaScript where DOM nodes can be manipulated to change their styles, contents, placement in the document, or interacted with through event listeners.

  • The DOM was designed to be independent of any particular programming language, making the structural representation of the document available from a single, consistent API.
  • The DOM is constructed progressively in the browser as a page loads, which is why scripts are often placed at the bottom of a page, in the <head> with a defer attribute, or inside a DOMContentLoaded event listener. Scripts that manipulate DOM nodes should be run after the DOM has been constructed to avoid errors.
  • document.getElementById() and document.querySelector() are common functions for selecting DOM nodes.
  • Setting the innerHTML property to a new value runs the string through the HTML parser, offering an easy way to append dynamic HTML content to a node.
Source:ย developer.mozilla.orgย  ย 


๐Ÿ”น 21. What is HTML5 Web Storage? Explain localStorage and sessionStorage.

Answer:

With HTML5, web pages can store data locally within the userโ€™s browser. The data is stored in name/value pairs, and a web page can only access data stored by itself.

Differences between localStorage and sessionStorage regarding lifetime:

  • Data stored through localStorage is permanent: it does not expire and remains stored on the userโ€™s computer until a web app deletes it or the user asks the browser to delete it.
  • sessionStorage has the same lifetime as the top-level window or browser tab in which the data got stored. When the tab is permanently closed, any data stored through sessionStorage is deleted.

Differences between localStorage and sessionStorage regarding storage scope:

Both forms of storage are scoped to the document origin so that documents with different origins will never share the stored objects.

  • sessionStorage is also scoped on a per-window basis. Two browser tabs with documents from the same origin have separate sessionStorage data.
  • Unlike in localStorage, the same scripts from the same origin can't access each other's sessionStorage when opened in different tabs.
Source:ย w3schools.comย  ย 


๐Ÿ”น 22. What are data- attributes good for?

Answer:

Before JavaScript frameworks became popular, front end developers used data- attributes to store extra data within the DOM itself, without other hacks such as non-standard attributes, extra properties on the DOM. It is intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements.

These days, using data- attributes is not encouraged. One reason is that users can modify the data attribute easily by using inspect element in the browser. The data model is better stored within JavaScript itself and stay updated with the DOM via data binding possibly through a library or a framework.

Source:ย w3.orgย  ย 


๐Ÿ”น 23. Explain the difference between cookies, session and local storage

Answer:

Cookies

  • Limited storage space 4096 bytes / ~4 kb
  • Only allow to store data as strings
  • Stored data is sent back to server on every HTTP request such as HTML, CSS, Images etc,
  • Can store only 20 cookies per domain
  • In total 300 cookies are allowed on a site
  • Setting HTTP only flag will prevent accessing cookies via javascript
  • Can set expiration duration for auto deletion (can be set either from server or client)

Example:

// Set with expiration & path
document.cookie = "name=Gokul; expires=Thu, 18 Dec 2016 12:00:00 UTC; path=/;";

// Get document.cookie;

// Delete by setting empty value and same path document.cookie = "name=; expires=Thu, 18 Dec 2016 12:00:00 UTC; path=/;";

Session Storage

  • Storage space is 5 mb / ~5120 kb
  • Storage space may vary a little based on the browser
  • Only allow to store data as strings
  • Data is available per window or tab
  • Once window or tab is closed stored data is deleted
  • Data will be only available on same origin

Example:

// Set
sessionStorage.setItem("name", "gokul");

// Get sessionStorage.getItem("name"); // gokul

// Delete sessionStorage.removeItem("name");

// Delete All sessionStorage.clear();

Local Storage

  • Storage space is 5 mb / ~5120 kb
  • Storage space may vary a little based on the browser
  • Only allow to store data as strings
  • Data will be only available on same origin
  • Data is persistant (untill explicitly deleted)
  • API is similar to session storage

Example:

// Set
localStorage.setItem("name", "gokul");

// Get localStorage.getItem("name"); // gokul

// Delete localStorage.removeItem("name");

// Delete All localStorage.clear();

Source:ย github.com/FuelFrontendย  ย 


๐Ÿ”น 24. What are some differences that XHTML has compared to HTML?

Answer:

Some of the key differences are:

  • An XHTML element must have an XHTML <DOCTYPE>
  • Attributes values must be enclosed in quotes
  • Attribute minimization is forbidden (e.g. one has to use checked="checked" instead of checked)
  • Elements must always be properly nested
  • Elements must always be closed
  • Special characters must be escaped
Source:ย w3schools.comย  ย 


๐Ÿ”น 25. What are Web Workers?

Answer:

  • Web Workers helps us to run javascript code in the background without blocking application.
  • Web Workers runs in an isolated (new) thread for executing our javascript code.
  • Web Workers are usually used for large tasks.
  • Web Workers needs a seperate file for our javascript code.
  • Web Workers files are downloaded asynchronously.
  • Web Workers are supported in all latest browser.

Example:

Our client side js file below:

var myWebWorker = new Worker("task.js"); // Creating a worker

// Listen to task.js worker messages worker.addEventListener("message", function(event) { console.log("Worker said: ", event.data); }, false);

worker.postMessage("From web worker file"); // Will start the worker

task.js (worker file) file below:

// Listen to client js file post messages
self.addEventListener("message", function(event) {
self.postMessage(event.data); // Send processed data to listening client js file.
}, false);
Source:ย github.com/FuelFrontendย  ย 


๐Ÿ”น 26. What is WebSQL?

Answer:

  • WebSQL is database API for client (browser) database using SQL.
  • Similar to SQL, API are pretty simple.
  • Not all the browser supports WebSQL.
  • As of now WebSQL is deprecated.
Source:ย github.com/FuelFrontendย  ย 


๐Ÿ”น 27. What is the purpose of cache busting and how can you achieve it?

Answer:

Browsers have a cache to temporarily store files on websites so they don't need to be re-downloaded again when switching between pages or reloading the same page. The server is set up to send headers that tell the browser to store the file for a given amount of time. This greatly increases website speed and preserves bandwidth.

However, it can cause problems when the website has been changed by developers because the user's cache still references old files. This can either leave them with old functionality or break a website if the cached CSS and JavaScript files are referencing elements that no longer exist, have moved or have been renamed.

Cache busting is the process of forcing the browser to download the new files. This is done by naming the file something different to the old file.

A common technique to force the browser to re-download the file is to append a query string to the end of the file.

  • src="js/script.js" => src="js/script.js?v=2"

The browser considers it a different file but prevents the need to change the file name.

Source:ย css-tricks.comย  ย 


๐Ÿ”น 28. Discuss the differences between an HTML specification and a browserโ€™s implementation thereof.

Answer:

HTML specifications such as HTML5 define a set of rules that a document must adhere to in order to be โ€œvalidโ€ according to that specification. In addition, a specification provides instructions on how a browser must interpret and render such a document.

A browser is said to โ€œsupportโ€ a specification if it handles valid documents according to the rules of the specification. As of yet, no browser supports all aspects of the HTML5 specification (although all of the major browser support most of it), and as a result, it is necessary for the developer to confirm whether the aspect they are making use of will be supported by all of the browsers on which they hope to display their content. This is why cross-browser support continues to be a headache for developers, despite the improved specificiations.

  • HTML5 defines some rules to follow for an invalid HTML5 document (i.e., one that contains syntactical errors)
  • However, invalid documents may contain anything, so it's impossible for the specification to handle all possibilities comprehensively.
  • Thus, many decisions about how to handle malformed documents are left up to the browser.
Source:ย w3.orgย  ย 


๐Ÿ”น 29. Describe the difference between a 'cookie', 'sessionStorage' and 'localStorage'.

Answer:

All the above-mentioned technologies are key-value storage mechanisms on the client side. They are only able to store values as strings.

cookielocalStoragesessionStorage
InitiatorClient or server. Server can use Set-Cookie headerClientClient
ExpiryManually setForeverOn tab close
Persistent across browser sessionsDepends on whether expiration is setYesNo
Sent to server with every HTTP requestCookies are automatically being sent via Cookie headerNoNo
Capacity (per domain)4kb5MB5MB
AccessibilityAny windowAny windowSame tab
Source:ย developer.mozilla.orgย  ย 


๐Ÿ”น 30. What does a DOCTYPE do?

Answer:

DOCTYPE is an abbreviation for โ€œdocument typeโ€. It is a declaration used in HTML to distinguish between standards mode and quirks mode. Its presence tells the browser to render the web page in standards mode.

Moral of the story - just add <!DOCTYPE html> at the start of your page.

Source:ย stackoverflow.comย  ย 


๐Ÿ”น 31. Explain almost standard, full standard and quirks mode

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 32. Explain the difference between block elements and inline elements

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 33. How do you set IE compatibility mode?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 34. What is an optional tag?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 35. How do you change the direction of html text?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 36. What are defer and async attributes on a <script> tag?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 37. Describe the difference between , and .

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 38. What is progressive rendering?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 39. Why you would use a srcset attribute in an image tag? Explain the process the browser uses when evaluating the content of this attribute.

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 40. What is the purpose of 'main' element?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 41. What is an HTML preprocessor and are you using it?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 42. What are the building blocks of HTML5?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 43. Why to use HTML5 semantic tags?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 44. How would you select svg or canvas for your site?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 45. What kind of things must you be wary of when designing or developing for multilingual sites?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 46. What is WebP?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 47. Why do I need a doctype and what does it do?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 48. What's the difference between Full Standard, Almost Standard and Quirks Mode?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 49. Could you generate a public key in HTML?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 50. Why is it generally a good idea to position CSS s between and JS s just before ? Do you know any exceptions?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 51. What are Web Components?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 52. What is an IndexedDB?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 53. What is accessibility & ARIA role means in a web application?

๐Ÿ‘‰๐Ÿผ Check all 54 answers


๐Ÿ”น 54. Check HTML Markup Validity

๐Ÿ‘‰๐Ÿผ Check all 54 answers



Thanks ๐Ÿ™Œ for reading and good luck on your next tech interview!
Explore 3800+ dev interview question here ๐Ÿ‘‰ Devinterview.io

About

๐ŸŸฃ HTML5 coding interview questions and answers for web developers.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published