Click here to Skip to main content
15,396,032 members
Articles / Web Development / HTML5
Posted 25 Dec 2013


200 bookmarked

40 important HTML 5 Interview questions with answers

Rate me:
Please Sign up or sign in to vote.
4.86/5 (112 votes)
24 Sep 2014CPOL13 min read
In this article we will quickly brushup 40 important HTML 5 interview questions with answers , Happy job hunting.



What is the difference between Canvas and SVG graphics?

How to draw rectangle using Canvas and SVG using HTML 5 ?

What are selectors in CSS?

How can you apply CSS style using ID value?

What is the use of column layout in CSS?

Can you explain CSS box model?

Can you explain some text effects in CSS 3?

What are web workers and why do we need them ?

How can we add and remove data from local storage?

What is the lifetime of local storage?

What is the difference between local storage and cookies?

What is difference between session storage and local storage?

What is WebSQL?

Is WebSQL a part of HTML 5 specification?

So how can we use WebSQL ?

So how do we implement application cache in HTML 5 ?

What is fallback in Application cache?

References for other interview question articles


I am ASP.NET MVC developer and recently when I was looking for a job lot of questions were asked connected to HTML 5 and its new features. So below are 40 important questions which would help you brush up your knowledge on HTML 5.

These questions are not silver bullet to get a job but yes they are helpful when you want to quickly brush up the topic.

Happy job hunting.

Image 1


What is the relationship between SGML,HTML , XML and XHTML?

SGML (Standard generalized markup language) is a standard which tells how to specify document markup. It’s only a Meta language which describes how a document markup should be. HTML is a markup language which is described using SGML.

So by SGML they created DTD which the HTML refers and needs to adhere to the same. So you will always find “DOCTYPE” attribute at the top of HTML page which defines which DTD is used for parsing purpose.


Now parsing SGML was a pain so they created XML to make things better. XML uses SGML. For example in SGML you have to start and end tags but in XML you can have closing tags which close automatically (“”).

XHTML was created from XML which was used in HTML 4.0. So for example in SGML derived HTML “
” is not valid but in XHTML it’s valid. You can refer XML DTD as shown in the below code snippet.


What is HTML 5?

HTML 5 is a new standard for HTML whose main target is to deliver everything without need to any additional plugins like flash, Silverlight etc. It has everything from animations, videos, rich GUI etc.
HTML5 is cooperation output between World Wide Web Consortium (W3C) and the Web Hypertext Application Technology Working Group (WHATWG).

If I do not put <! DOCTYPE html> will HTML 5 work?

No, browser will not be able to identify that it’s a HTML document and HTML 5 tags will not function properly.

Which browsers support HTML 5?

Almost all browsers i.e. Safari, Chrome, Firefox, Opera, Internet Explorer support HTML 5.

How is the page structure of HTML 5 different from HTML 4 or previous HTML?

A typical web page has headers, footers, navigation, central area and side bars. Now if we want to represent the same in HTML 4 with proper names to the HTML section we would probably use a DIV tag.
But in HTML 5 they have made it more clear by creating element names for those sections which makes your HTML more readable.

Image 2

Below are more details of the HTML 5 elements which form the page structure.

  • <header>: Represents header data of HTML.
  • <footer>: Footer section of the page.
  • <nav>: Navigation elements in the page.
  • <article>: Self-contained content.
  • <section>: Used inside article to define sections or group content in to sections.

What is datalist in HTML 5?

Datalist element in HTML 5 helps to provide autocomplete feature in a textbox as shown below.

Image 3

Below is the HTML code for DataList feature:-

<input list="Country">
<datalist id="Country">
<option value="India">
<option value="Italy">
<option value="Iran">
<option value="Israel">
<option value="Indonesia">

What are the different new form element types in HTML 5?

There are 10 important new form elements introduced in HTML 5:-

  1. Color.
  2. Date
  3. Datetime-local
  4. Email
  5. Time
  6. Url
  7. Range
  8. Telephone
  9. Number
  10. Search

Let’s understand these elements step by step.

If you want to show color picker dialog box.

<input type="color" name="favcolor">  

Image 4

If you want to show calendar dialog box.

<input type="date" name="bday">  

Image 5

If you want to show calendar with local time.

<input type="datetime-local" name="bdaytime">  

Image 6

If you want to create a HTML text with email validation we can set the type as “email”.

<input type="email" name="email"> 

Image 7

For URL validation set the type as “url” as shown in the below HTML code.

<input type="url" name="sitename">  

Image 8

For URL validation set the type as “url” as shown in the below HTML code.

If you want to display textbox with number range you can set type to number.

<input type="number" name="quantity" min="1" max="5">  

Image 9

If you want to display a range control you can use type as range.

<input type="range" min="0" max="10" step="2" value="6">

Image 10

Want to make text box as search engine box.

<input type="search" name="googleengine">  

What to only take time input.

<input type="time" name="usr_time">  

If you want to make text box to accept telephone numbers.

<input type="tel" name="mytel">  

What is output element in HTML 5?

Output element is needed when you need calculation from two inputs to be summarized in to a label. For instance you have two textboxes( see the below figure) and you want to add numbers from these textboxes and send them to a label.

Image 11

Below goes the code of how to use output element with HTML 5.

<form onsubmit="return false"  öninput="o.value = parseInt(a.value) + parseInt(b.value)">
<input name="a" type="number"> +
<input name="b" type="number"> =
<output name="o" />

You can also replace “parseInt” with “valueAsNumber” for simplicity. You can also use “for” in the output element for more readability.

<output name="o" for="a b"></output>  

What is SVG?

SVG stands for scalable vector graphics. It’s a text based graphic language which draws images using text, lines, dots etc. This makes it lightweight and renders faster.

Can we see a simple example of SVG using HTML 5?

Let’s say we want to display the below simple line using HTML 5 SVG.

Image 12

Below is how the code of HTML 5. You can see the SVG tag which encloses the polygon tag for displaying the star image.

<svg id="svgelem" height="[object SVGAnimatedLength]" xmlns="">
<line style="stroke: rgb(255, 0, 0); stroke-width: 2px;" y2="[object SVGAnimatedLength]" x2="[object SVGAnimatedLength]" y1="[object SVGAnimatedLength]" x1="[object SVGAnimatedLength]">

What is canvas in HTML 5?

Canvas is an HTML area on which you can draw graphics.


Get access to canvas area

To draw on the canvas area we need to first get reference of the context section. Below is the code for canvas section.

<a a="" below="" body="" c="document.getElementById("mycanvas");" canvas="" complete="" ctx="c.getC>So how can we draw a simple line on Canvas? </a></h2>

	<li>Define the Canvas area.</li>
	<li>Get access to canvas context area.</li>
	<li>Draw the graphic.</li>

<p><strong>Define the canvas area </strong></p>

<p>So to define canvas area you need to use the below HTML code. This defines the area on which you can draw.</p>


<canvas height=">

var c=document.getElementById("mycanvas");
var ctx=c.getContext("2d"); </a>

Draw the graphic

Now once you have access to the context object we can start drawing on the context. So first call the “move” method and start from a point , use line method and draw the line and then apply stroke over it.

<a a="" below="" body="" c="document.getElementById("mycanvas");" canvas="" complete="" ctx="c.getC>So how can we draw a simple line on Canvas? </a></h2>

	<li>Define the Canvas area.</li>
	<li>Get access to canvas context area.</li>
	<li>Draw the graphic.</li>

<p><strong>Define the canvas area </strong></p>

<p>So to define canvas area you need to use the below HTML code. This defines the area on which you can draw.</p>


<canvas height=">
</a><a name="WhatisthedifferencebetweenCanvasandSVGgraphics">What is the difference between Canvas and SVG graphics? </a>

Note: - If you see the previous two questions both canvas and SVG can draw graphics on the browser. So in this question interviewer wants to know when will you use what.




Here’s it’s like draw and remember. In other words any shape drawn by using SVG can be remembered and manipulated and browser can render it again. Canvas is like draw and forget. Once something is drawn you cannot access that pixel and manipulate it.
SVG is good for creating graphics like CAD software’s where once something is drawn the user wants to manipulate it. Canvas is good for draw and forget scenarios like animation and games.
This is slow as it needs to remember the co-ordinates for later manipulations. This is faster as there is no intention of remembering things later.
We can have event handler associated with the drawing object. Here we cannot associate event handlers with drawing objects as we do not have reference of them.
Resolution independent. Resolution dependent.

How to draw rectangle using Canvas and SVG using HTML 5?

HTML 5 code Rectangle code using SVG.

<svg xmlns="" version="1.1">
<rect style="fill: rgb(0, 0, 255); stroke-width: 1px; stroke: rgb(0, 0, 0);" height="[object SVGAnimatedLength]" width="[object SVGAnimatedLength]">

HTML 5 Rectangle code using canvas.

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
<svg xmlns="" version="1.1">
  <circle fill="red" stroke-width="2" stroke="black" r="[object SVGAnimatedLength]" cy="[object SVGAnimatedLength]" cx="[object SVGAnimatedLength]">

var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var centerX = canvas.width / 2;
var centerY = canvas.height / 2;
var radius = 70;

context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
context.fillStyle = 'green';
context.lineWidth = 5;
context.strokeStyle = '#003300';

<!DOCTYPE html>
<body  önload="DrawMe();">
<svg height="[object SVGAnimatedLength]" width="[object SVGAnimatedLength]">
<circle id="circle1" cx="[object SVGAnimatedLength]" cy="[object SVGAnimatedLength]" r="[object SVGAnimatedLength]" style="stroke: none; fill: rgb(255, 0, 0);">


 var timerFunction = setInterval(DrawMe, 20);

function DrawMe()
var circle = document.getElementById("circle1");
var x = circle.getAttribute("cx");
var newX = 2 + parseInt(x);
if(newX > 500) 
            newX = 20;
        circle.setAttribute("cx", newX);


What are selectors in CSS?

Selectors help to select an element to which you want to apply a style. For example below is a simple style called as ‘intro” which applies red color to background of a HTML element.


To apply the above “intro” style to div we can use the “class” selector as shown in the below figure.

<div class="intro">
<p>My name is Shivprasad koirala.</p>
<p>I write interview questions.</p>

How can you apply CSS style using ID value?

So let’s say you have a HTML paragraph tag with id “mytext” as shown in the below snippet.

<p id="mytext">This is HTML interview questions.</p> 

You can create a style using “#” selector with the “id” name and apply the CSS value to the paragraph tag. So to apply style to “mytext” element we can use “#mytext” as shown in the below CSS code.


Quick revision of some important selectors.

Set all paragraph tags back ground color to yellow.


Sets all paragraph tags inside div tag to yellow background.

div p

Sets all paragraph tags following div tags to yellow background.


Sets all attribute with “target” to yellow background.


<a href="">ASP.NET interview questions</a>
<a href="" target="_blank">c# interview questions</a>
<a href="" target="_top">.NET interview questions with answers</a> 

Set all elements to yellow background when control gets focus.


Set hyperlinks according to action on links.

a:link    {color:green;}
a:visited {color:green;}
a:hover   {color:red;}
a:active  {color:yellow;} 

What is the use of column layout in CSS?

CSS column layout helps you to divide your text in to columns. For example consider the below magazine news which is one big text but we need to divide the same in to 3 columns with a border in between. That’s where HTML 5 column layout comes to help.

Image 13

To implement column layout we need to specify the following:-

  • How many columns we want to divide the text in to ?

To specify number of columns we need to us column-count. “webkit” and “moz-column” are needed for chrome and firefox respectively.

-moz-column-count:3; /* Firefox */
-webkit-column-count:3; /* Safari and Chrome */
  • How much gap we want to give between those columns ?
-moz-column-gap:40px; /* Firefox */
-webkit-column-gap:40px; /* Safari and Chrome */
  • Do you want to draw a line between those columns , if yes how much thick ?
-moz-column-rule:4px outset #ff00ff; /* Firefox */
-webkit-column-rule:4px outset #ff00ff; /* Safari and Chrome */
column-rule:6px outset #ff00ff; 

Below is the complete code for the same.

-moz-column-count:3; /* Firefox */
-webkit-column-count:3; /* Safari and Chrome */

-moz-column-gap:40px; /* Firefox */
-webkit-column-gap:40px; /* Safari and Chrome */

-moz-column-rule:4px outset #ff00ff; /* Firefox */
-webkit-column-rule:4px outset #ff00ff; /* Safari and Chrome */
column-rule:6px outset #ff00ff;

You can then apply the style to the text by using the class attribute.

<div class="magazine">

Your text goes here which you want to divide in to 3 columns.


Can you explain CSS box model?

CSS box model is a rectangular space around a HTML element which defines border, padding and margin.

Border: - This defines the maximum area in which the element will be contained. We can make the border visible, invisible, define height and width etc.

Padding: - This defines the spacing between border and element.

Margin: - This defines the spacing between border and any neighboring elements.

Image 14

For instance below is a simple CSS code which defines a box with border , padding and margin values.

.box {
    width: 200px;
    border: 10px solid #99c;
    padding: 20px;
    margin: 50px;

Now if we apply the above CSS to a DIV tag as shown in the below code , your output would be as shown in the figure below. I have created two test “Some text” and “Some other text” so that we can see how margin property functions.

<div align="middle" class="box">
Some text

Some other text 
Image 15


Can you explain some text effects in CSS 3?

Here the interviewer is expecting you to answer one of two text effects by CSS.Below are two effects which are worth noting.

Shadow text effect

text-shadow: 5px 5px 5px #FF0000;

Image 16

Word wrap effect


Image 17

What are web workers and why do we need them ?

Consider the below heavy for loop code which runs above million times.

function  SomeHeavyFunction()
for (i = 0; i < 10000000000000; i++)
x = i + x;

Let’s say the above for loop code is executed on a HTML button click. Now this method execution is synchronous. In other words the complete browser will wait until the for loop completes.

<input type="button" onclick="SomeHeavyFunction();" />  

This can further lead to browser getting freezed and unresponsive with an error message as shown in the screen below.

Image 18

So if we can move this heavy for loop in a JavaScript file and run it asynchronously that means the browser does need to wait for the loop then we can have a more responsive browser. That’s what web worker are for.

Web worker helps to execute JavaScript file asynchronously.

What is local storage concept in HTML 5?

Many times we would like to store information about the user locally in the computer. For example let’s say user has half-filled a long form and suddenly the internet connection breaks off. So the user would like you to store this information locally and when the internet comes back.He would like to get that information and send it to the server for storage.

Modern browsers have storage called as “Local storage” in which you can store this information.

How can we add and remove data from local storage?

Data is added to local storage using “key” and “value”. Below sample code shows country data “India” added with key value “Key001”.


To retrieve data from local storage we need to use “getItem” providing the key name.

var country = localStorage.getItem("Key001"); 

You can also store JavaScript object’s in the local storage using the below code.

var country = {}; = "India";
country.code = "I001";
localStorage.setItem("I001", country);
var country1 = localStorage.getItem("I001"); 

If you want to store in JSON format you can use “JSON.stringify” function as shown in the below code.


What is the lifetime of local storage?

Local storage does not have a life time it will stay until either the user clear it from the browser or you remove it using JavaScript code.

What is the difference between local storage and cookies?

  Cookies Local storage
Client side / Server side. Data accessible both at client side and server side. Cookie data is sent to the server side with every request. Data is accessible only at the local browser side. Server cannot access local storage until deliberately sent to the server via POST or GET.
Size 4095 bytes per cookie. 5 MB per domain.
Expiration Cookies have expiration attached to it. So after that expiration the cookie and the cookie data get’s deleted. There is no expiration data. Either the end user needs to delete it from the browser or programmatically using JavaScript we need to remove the same.

What is WebSQL?

WebSQL is a structured relational database at the client browser side. It’s a local RDBMS inside the browser on which you can fire SQL queries.

Is WebSQL a part of HTML 5 specification?

No, many people label it as HTML 5 but it’s not part of HTML 5 specification. The specification is based around SQLite.

So how can we use WebSQL?

The first step we need to do is open the database by using “OpenDatabase” function as shown below. The first argument is the name of the database, the next is the version, then a simple textual title and finally the size of the database.

var db=openDatabase('dbCustomer','1.0','Customer app’, 2 * 1024 * 1024); 

To execute SQL we then need to use “transaction” function and call “executeSql” function to fire SQL.

db.transaction(function (tx) 
tx.executeSql('CREATE TABLE IF NOT EXISTS tblCust(id unique, customername)');
tx.executeSql('INSERT INTO tblcust (id, customername) VALUES(1, "shiv")');
tx.executeSql('INSERT INTO tblcust (id, customername) VALUES (2, "raju")');

In case you are firing “select” query you will get data is “results” collection which we can loop and display in the HTML UI.

db.transaction(function (tx) 
  tx.executeSql('SELECT * FROM tblcust', [], function (tx, results) {
   for (i = 0; i < len; i++)
     msg = "<p><b>" + results.rows.item(i).log + "</b></p>";
     document.querySelector('#customer).innerHTML +=  msg;
 }, null);

What is fallback in Application cache?

<a name="WhatisfallbackinApplicati>FALLBACK:
/home/ /homeoffline.html </a></pre>

<h2><a name=" whatisfallbackinapplicati=""></a>

MVC Interview questions with answers: -

Entity framework interview questions with answers: -

.NET interview questions preparation video series

What kind of questions are asked to .NET developers

This is a sample .NET mock interview video

My site updated with interview questions every day

For further reading do watch the below interview preparation videos and step by step video series.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Comments and Discussions

QuestionMessage Closed Pin
19-Jul-20 21:51
MemberSharmaRitu19-Jul-20 21:51 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey31-Jan-17 20:10
professionalManoj Kumar Choubey31-Jan-17 20:10 
GeneralMessage Closed Pin
25-Dec-16 18:30
MemberMember 1292169425-Dec-16 18:30 
Generalfantastic Pin
hope_amal2-Sep-15 9:37
Memberhope_amal2-Sep-15 9:37 
QuestionGreat article Pin
StanleyJHubert3-Dec-14 23:54
MemberStanleyJHubert3-Dec-14 23:54 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun25-Sep-14 0:20
MemberHumayun Kabir Mamun25-Sep-14 0:20 
QuestionVery good! Pin
Cheung Tat Ming24-Sep-14 20:41
MemberCheung Tat Ming24-Sep-14 20:41 
AnswerRe: Very good! Pin
vaynenick1-Aug-16 18:43
Membervaynenick1-Aug-16 18:43 
QuestionVery Good article Pin
newton.saber24-Sep-14 7:29
Membernewton.saber24-Sep-14 7:29 
QuestionFor dotnet developers... Pin
devvvy24-Sep-14 5:49
Memberdevvvy24-Sep-14 5:49 
QuestionGreat article Pin
Imran Abdul Ghani3-Sep-14 1:40
MemberImran Abdul Ghani3-Sep-14 1:40 
QuestionArticle Pin
Member 1049639012-Aug-14 4:55
MemberMember 1049639012-Aug-14 4:55 
SuggestionHow can we add and remove data from local storage? Pin
Member 1099699611-Aug-14 20:51
MemberMember 1099699611-Aug-14 20:51 
QuestionNice article Sir Pin
Rahul VB3-May-14 1:01
professionalRahul VB3-May-14 1:01 
BugSVG example mentions polygon/star but shows line Pin
Member 96925308-Apr-14 22:13
MemberMember 96925308-Apr-14 22:13 
Bug<aside> or <sidebar> Pin
Member 96925308-Apr-14 22:09
MemberMember 96925308-Apr-14 22:09 
BugWeb version has some omitted text. Pin
Member 96925308-Apr-14 22:02
MemberMember 96925308-Apr-14 22:02 
GeneralThanks for your valuable info Pin
Member 105939488-Apr-14 20:19
MemberMember 105939488-Apr-14 20:19 
Generalgood one Pin
Mehreen-Badat7-Apr-14 21:08
MemberMehreen-Badat7-Apr-14 21:08 
GeneralMy vote of 5 Pin
ruda_k7-Apr-14 1:41
Memberruda_k7-Apr-14 1:41 
GeneralMy vote of 5 Pin
khurram ali lashari5-Mar-14 9:12
professionalkhurram ali lashari5-Mar-14 9:12 
Questioncomment Pin
Member 1053286118-Jan-14 9:16
MemberMember 1053286118-Jan-14 9:16 
GeneralMy Vote of 5 Pin
RaviRanjanKr9-Jan-14 1:04
professionalRaviRanjanKr9-Jan-14 1:04 
GeneralMy vote of 5 Pin
Raul Iloc7-Jan-14 21:39
MemberRaul Iloc7-Jan-14 21:39 
QuestionNice article Pin
Madhanlal JM5-Jan-14 20:20
MemberMadhanlal JM5-Jan-14 20:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.