Can
an <article> contain <section>elements? Provide usage examples.
Hide answer
The answer to both questions is yes; i.e., a <section> can contain <article> elements, and
an <article> can contain <section> elements.
For example, a personal dashboard page might contain a <section> for social network interactions as
well as a <section> for the latest news articles, the latter of which could contain
several <article> elements.
Conversely, an <article> might contain a <section> at the end for reader comments.
Comment
<header>
purposes in relation to whatever their parent section may be. So not only can the
page <body> contain a header and a footer, but so can every <article> and <section> element. In fact,
a <header> should be present for all of these, although a <footer> is not always necessary.
Comment
charset
<!DOCTYPE html>
<html>
<head>
...
<meta charset="UTF-8">
...
</head>
...
</html>
This is a slightly simpler syntax from older HTML standards, which did not have the
For example, an HTML 4.01 document would use the <meta> tag as follows:
charset
attribute.
Comment
Write the code necessary to create a 300 pixel by 300 pixel <canvas>.
Within it, paint a blue 100 pixel by 100 pixel square with the top-left corner
of the square located 50 pixels from both the top and left edges of the
canvas.
Hide answer
<script>
var canvas = document.getElementById( "c" );
var drawing_context = canvas.getContext( "2d" );
drawing_context.fillStyle = "blue";
drawing_context.fillRect( 50, 50, 100, 100 );
</script>
Comment
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.
2
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.
In addition, while HTML5 defines some rules to follow for an invalid HTML5 document (i.e., one that
contains syntactical errors), invalid documents may contain anything, and it is impossible for the
specification to handle all possibilities comprehensively. Thus, many decisions about how to handle
malformed documents are left up to the browser.
Comment
The <header> element is used to contain introductory and navigational information about a section of
the page. This can include the section heading, the authors name, time and date of publication, table
of contents, or other navigational information.
The <article> element is meant to house a self-contained composition that can logically be
independently recreated outside of the page without losing its meaining. Individual blog posts or
news stories are good examples.
The <section> element is a flexible container for holding content that shares a common informational
theme or purpose.
The <footer> element is used to hold information that should appear at the end of a section of content
and contain additional information about the section. Authors name, copyright information, and
related links are typical examples of such content.
Comment
Describe the relationship between the <header> and <h1> tags in HTML5.
Hide answer
In previous specifications of HTML, only one <h1> element was typically present on a page, used for
the heading of the entire page. HTML5 specifies that <h1> represents the top-level heading of a
section, whether that be the page <body>, or an <article> or <section> element. In fact,
every <header> element should at least contain an <h1>element. If there is no natural heading for the
section, it is a good indication it should not use an <article> or <section> tag.
Comment
Improved support for embedding graphics, audio, and video content via the
new <canvas>, <audio>, and <video> tags.
Extensions to the JavaScript API such as geolocation and drag-and-drop as well
for storage and caching.
Introduction of web workers.
Several new semantic tags were also added to complement the structural logic of modern web
applications. These include the <main>, <nav>, <article>, <section>, <header>, <footer>,
and <aside> tags.
New form controls, such as <calendar>, <date>, <time>, <email>, <url>, and <search>.
Comment
What were some of the key goals and motivations for the HTML5
specification?
Hide answer
HTML5 was designed to replace both HTML 4, XHTML, and the HTML DOM Level 2.
Major goals of the HTML specification were to:
Deliver rich content (graphics, movies, etc.) without the need for additional plugins (e.g.,
Flash).
Provide better semantic support for web page structure through the introduction of new
structural element tags.
Provide a stricter parsing standard to simplify error handling, ensure more consistent crossbrowser behavior, and simplify backward compatibility with documents written to older
standards.
Provide better cross-platform support (i.e., to work well whether running on a PC, Tablet, or
Smartphone).
Comment
<source>
tag inside
<source src="http://www.example.com/amazing_video.mp4">
</video>
Comment
With HTML5, web pages can store data locally within the users browser.
Earlier, this was done with cookies. However, Web Storage is more secure and faster. The data is not
included with every server request, but used ONLY when asked for.
The data is stored in name/value pairs, and a web page can only access data stored by itself. Unlike
cookies, the storage limit is far larger (at least 5MB) and information is never transferred to the server.
The difference between localStorage and sessionStorage involves the lifetime and scope of the
storage.
Data stored through localStorage is permanent: it does not expire and remains stored on the users
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 script that stored it is running.
When the window or tab is permanently closed, any data stored through sessionStorage is deleted.
Both forms of storage are scoped to the document origin so that documents with different origins will
never share the stored objects. But sessionStorage is also scoped on a per-window basis. If a user
has two browser tabs displaying documents from the same origin, those two tabs have separate
sessionStorage data: the scripts running in one tab cannot read or overwrite the data written by
scripts in the other tab, even if both tabs are visiting exactly the same page and are running exactly
the same scripts.
Comment
* There is more to interviewing than tricky technical questions, so these are intended merely as a guide. Not every
A candidate worth hiring will be able to answer them all, nor does answering them all guarantee an A candidate.
At the end of the day, hiring remains an art, a science and a lot of work.
http://www.toptal.com/html5/interview-questions
Previous
Next Chapter
Browser Support
The numbers in the table specify the first browser version that fully supports Local Storage.
API
Web Storage
4.0
8.0
3.5
4.0
window.sessionStorage - stores data for one session (data is lost when the tab is
closed)
Before using local storage, check browser support for localStorage and sessionStorage:
if(typeof(Storage) !== "undefined") {
// Code for localStorage/sessionStorage.
} else {
// Sorry! No Web Storage support..
}
Example
// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("lastname");
Example explained:
Retrieve the value of "lastname" and insert it into the element with id="result"
Note: Name/value pairs are always stored as strings. Remember to convert them to another
format when needed!
The following example counts the number of times a user has clicked a button. In this code
the value string is converted to a number to be able to increase the counter:
Example
if (localStorage.clickcount) {
localStorage.clickcount = Number(localStorage.clickcount) + 1;
} else {
localStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = "You have clicked the button " +
localStorage.clickcount + " time(s).";
Example
if (sessionStorage.clickcount) {
sessionStorage.clickcount = Number(sessionStorage.clickcount) + 1;
} else {
sessionStorage.clickcount = 1;
}
document.getElementById("result").innerHTML = "You have clicked the button " +
sessionStorage.clickcount + " time(s) in this session.";
Contents
Introduction
What is the difference between Canvas and SVG graphics?
How to draw rectangle using Canvas and SVG using HTML 5 ?
8
Introduction
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.
Courtesy: -www.questpond.com
<!--!doctype-->
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 its valid. You can refer XML DTD as shown in the below code snippet.
Hide Copy Code
<!--!doctype--><!--!doctype-->
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.
10
HTML5 is cooperation output between World Wide Web Consortium (W3C) and the Web Hypertext
Application Technology Working Group (WHATWG).
Below are more details of the HTML 5 elements which form the page structure.
<input list="Country">
<datalist id="Country">
<option value="India">
<option value="Italy">
<option value="Iran">
<option value="Israel">
<option value="Indonesia">
</datalist>
Color.
Date
Datetime-local
Email
Time
Url
Range
Telephone
Number
Search
12
13
If you want to create a HTML text with email validation we can set the type as email.
Hide Copy Code
For URL validation set the type as url as shown in the below HTML code.
Hide Copy Code
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.
Hide Copy Code
If you want to display a range control you can use type as range.
Hide Copy Code
14
Below goes the code of how to use output element with HTML 5.
Hide Copy Code
You can also replace parseInt with valueAsNumber for simplicity. You can also use for in the
output element for more readability.
Hide Copy Code
What is SVG?
SVG stands for scalable vector graphics. Its a text based graphic language which draws images
using text, lines, dots etc. This makes it lightweight and renders faster.
15
Below is how the code of HTML 5. You can see the SVG tag which encloses the polygon tag for
displaying the star image.
Hide Copy Code
var c=document.getElementById("mycanvas");
var ctx=c.getContext("2d");
16
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.
Canvas
SVG
Heres its like draw and remember. In other words any shape
drawn by using SVG can be remembered and manipulated and
browser can render it again.
SVG is good for creating graphics like CAD softwares where once
something is drawn the user wants to manipulate it.
This is slow as it needs to remember the co-ordinates for later
manipulations.
We can have event handler associated with the drawing object.
Resolution independent.
Copy Code
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.rect(20,20,150,100);
ctx.stroke();
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<circle fill="red" stroke-width="2" stroke="black" r="[object SVGAnimatedLength]" cy="[object
SVGAnimatedLength]" cx="[object SVGAnimatedLength]">
var
var
var
var
var
canvas = document.getElementById('myCanvas');
context = canvas.getContext('2d');
centerX = canvas.width / 2;
centerY = canvas.height / 2;
radius = 70;
context.beginPath();
context.arc(centerX, centerY, radius, 0, 2 * Math.PI, false);
context.fillStyle = 'green';
context.fill();
17
context.lineWidth = 5;
context.strokeStyle = '#003300';
context.stroke();
<!DOCTYPE html>
<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);">
</body>
<script>
var timerFunction = setInterval(DrawMe, 20);
alert("ddd");
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);
}
</script>
</html></circle>
<style>
.intro
{
background-color:red;
}
</style>
To apply the above intro style to div we can use the class selector as shown in the below
figure.
Hide Copy Code
<div class="intro">
<p>My name is Shivprasad koirala.</p>
<p>I write interview questions.</p>
</div>
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.
Hide Copy Code
<style>
#mytext
{
background-color:yellow;
}
</style>
P,h1
{
background-color:yellow;
}
div p
{
background-color:yellow;
}
div+p
{
background-color:yellow;
}
a[target]
{
background-color:yellow;
}
<a href="http://www.questpond.com">ASP.NET interview questions</a>
<a href="http://www.questpond.com" target="_blank">c# interview questions</a>
<a href="http://www.questpond.org" target="_top">.NET interview questions with answers</a>
19
input:focus
{
background-color:yellow;
}
a:link {color:green;}
a:visited {color:green;}
a:hover {color:red;}
a:active {color:yellow;}
-moz-column-count:3; /* Firefox */
-webkit-column-count:3; /* Safari and Chrome */
column-count:3;
-moz-column-gap:40px; /* Firefox */
-webkit-column-gap:40px; /* Safari and Chrome */
column-gap:20px;
Do you want to draw a line between those columns , if yes how much thick ?
20
<style>
.magazine
{
-moz-column-count:3; /* Firefox */
-webkit-column-count:3; /* Safari and Chrome */
column-count:3;
-moz-column-gap:40px; /* Firefox */
-webkit-column-gap:40px; /* Safari and Chrome */
column-gap:20px;
-moz-column-rule:4px outset #ff00ff; /* Firefox */
-webkit-column-rule:4px outset #ff00ff; /* Safari and Chrome */
column-rule:6px outset #ff00ff;
}
</style>
You can then apply the style to the text by using the class attribute.
Hide Copy Code
<div class="magazine">
Your text goes here which you want to divide in to 3 columns.
</div>
21
For instance below is a simple CSS code which defines a box with border , padding and margin values.
Hide Copy Code
.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.
Hide Copy Code
22
.specialtext
{
text-shadow: 5px 5px 5px #FF0000;
}
<style>
.breakword
{word-wrap:break-word;}
</style>
23
function SomeHeavyFunction()
{
for (i = 0; i < 10000000000000; i++)
{
x = i + x;
}
}
Lets 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.
Hide Copy Code
This can further lead to browser getting freezed and unresponsive with an error message as shown in
the screen below.
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. Thats what web
worker are for.
24
localStorage.setItem(“Key001”,”India”);
To retrieve data from local storage we need to use getItem providing the key name.
Hide Copy Code
You can also store JavaScript objects in the local storage using the below code.
Hide Copy Code
If you want to store in JSON format you can use JSON.stringify function as shown in the below code.
Hide Copy Code
localStorage.setItem(“I001”,JSON.stringify(country));
Cookies
Data accessible both at client side
Client side
and server side. Cookie data is sent
/ Server
to the server side with every
side.
request.
Size
4095 bytes per cookie.
Local storage
Data is accessible only at the local browser side.
Server cannot access local storage until
deliberately sent to the server via POST or GET.
5 MB per domain.
There is no expiration data. Either the end user
Cookies have expiration attached to
needs to delete it from the browser or
Expiration it. So after that expiration the cookie
programmatically using JavaScript we need to
and the cookie data gets deleted.
remove the same.
A.
Inline CSS: HTML elements may have CSS applied to them via the STYLE
attribute.For Example: If You have <p> element into webpage, you can apply
inline style likeshows in example.<p style=font-size: 12px; color:
#000000;>Test </p>
You can always check HTML, CSS and JavaScript code impact using Online HTML
Javascript editor.
Embedded CSS: CSS may be embedded in a Web page by placing the code
in a STYLE element within the HEAD element.For Example: If You have <h2>
element into webpage, you can apply embedded style like shows in example.
<head>
<style type=text/css>
h2 {
font-size: 16px;
color: #2d2d2d;
font-weight: 900;
}
</style>
</head>
Linked CSS: CSS can be placed in an external file (a simple text file containing
CSS) and linked via the link element.You can apply style to webpage using external
file as shown in example.
<link rel=stylesheet href=custom/custom.css type=text/css media=screen,
projection />
Imported CSS: Another way to utilize external CSS files via @import.<style>
@import url(/css/styles.css);
</style>
Put then your styles.css document can contain calls to any number of additional
style sheets:
@import url(/css/typography.css);
@import url(/css/layout.css);
@import url(/css/color.css);
CSS style rules cascade in the sense that they follow an order of precedence. Global style
rules apply first to HTML elements, and local style rules override them. For example, a style
defined in a style element in a webpage overrides a style defined in an external style sheet.
Similarly, an inline style that is defined in an HTML element in the page overrides any styles
that are defined for that same element elsewhere.
The !important rule is a way to make your CSS cascade but also have the rules you feel are
most crucial always be applied. A rule that has the !important property will always be
applied no matter where that rule appears in the CSS document. So if you wanted to make
sure that a property always applied, you would add the !important property to the tag. So,
to make the paragraph text always red, in the above example, you would write:
p { color: #ff0000 !important; }
p { color: #000000; }
28
The following snippet shows the CSS example1 defined followed by the use of an HTML
elements ID attribute, which pairs it with the CSS selector.
#example1: {background: blue;}
<div id=example1></div>
4. What is the difference between an ID selector and CLASS?
An ID selector identifies and sets style to only one occurrence of an element, while CLASS
can be attached to any number of elements.
5. What is Contextual Selector?
Contextual selector addresses specific occurrence of an element. It is a string of individual
selectors separated by white space (search pattern), where only the last element in the
pattern is addressed providing it matches the specified contex
6. What is Grouping?
When more than one selector shares the same declaration, they may be grouped together
via a comma-separated list; this allows you to reduce the size of the CSS (every bit and
byte is important) and makes it more readable. The following snippet applies the same
background to the first three heading elements.
h1, h2, h3 {background: red;}
7. What are Child Selectors?
A child selector is used when you want to match an element that is the child of another
specific element. The parent and child selectors are separated by spaces. The following
selector locates an unordered list element within a paragraph element and makes a text
within that element bold.
p > ul {font-weight: bold;}
29
Pseudo classes allow you to identify HTML elements on characteristics (as opposed to their
name or attributes). The classes are specified using a colon to separate the element name
and pseudo class. A good example is the :link and :visited pseudo classes for the HTML A
element. Another good example is first-child, which finds an elements first child element.
The following CSS makes all visited links red and green, the actual link text becomes yellow
when the mouse pointer is positioned over it, and the text of the first element of a
paragraph is bold.
a:link {font-color: red;}
a:visited {font-color: green;}
a:hover {font-color: yellow;}
p.first-child {font-weight: bold;}
10. Whats the difference between an inline element and a block element?
A block-level element is an element that creates large blocks of content like paragraphs or
page divisions. They start new lines of text when you use them, and can contain other
blocks as well as inline elements and text or data.
An inline element is an element that define text or data in the document like STRONG makes
the enclosed text strongly emphasized and Q says the enclosed text is a quotation. They
dont start new lines when you use them, and they generally only contain other inline tags
and text or data. Or they include nothing at all, like the BR tag.
Some properties that inline elements ignore include:
The CSS property display lets you change an inline property to block or a block to inline or
either of them to not display at all.
display: block;
display:inline;
display:none;
30
Horizontal list menus - Lists are block-level elements, but if you want your menu to
display horizontally, you need to convert the list to an inline element, so that newlines
11. Explain how the CSS box model works. Draw a box and then explain what the
border is, what the margin is, what the padding is, etc.? If you assign a width: or
height: to something, what specifically does that refer to?
All HTML elements can be considered as boxes. In CSS, the term box model is used when
talking about design and layout.
The CSS box model is essentially a box that wraps around HTML elements, and it consists
of: margins, borders, padding, and the actual content.
The box model allows us to place a border around elements and space elements in relation
to other elements.
Margin - Clears an area around the border. The margin does not have a background
color, it is completely transparent
31
Border - A border that goes around the padding and content. The border is affected
also
250px.</div>
</body>
12. Explain vertical margin collapsing.
Top and bottom margins of blocks are sometimes combined (collapsed) into a single margin
whose size is the largest of the margins combined into it, a behavior known as margin
collapsing.
Margin collapsing occurs in three basic cases:
Adjacent siblings
The margins of adjacent siblings are collapsed (except when the later sibling needs
to be cleared past floats).
32
CSS CODE
1
2
3
BRO WSER RE SU LT
33
inline-block elements
elements with overflow set to anything other than visible (They do not collapse
13. How do you float an element, and what does that mean? Whats Clearing?
With CSS float, an element can be pushed to the left or right, allowing other elements to
wrap around it.
Float is very often used for images, but it is also useful when working with layouts.
Elements are floated horizontally, this means that an element can only be floated left or
right, not up or down.
A floated element will move as far to the left or right as it can. Usually this means all the
way to the left or right of the containing element.
Below is the example, which shows using css float property you can set image to the right of
your web page.
<head>
<style>
img
{
float:right;
}
34
</style>
</head>
<body>
<p>
<img src=logocss.gif width=95 height=84 />
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</p>
</body>
14. Whats the difference between position: relative, position: fixed & position:
absolute?
Here, Ive listed basic difference between css positioning properties.
Position-Relative. This type of positioning is probably the most confusing and misused.
What it really means is relative to itself. If you set position: relative;on an element but no
other positioning attributes (top, left, bottom or right), it will no effect on its positioning at
all, it will be exactly as it would be if you left it as position: static; But if you DO give it some
other positioning attribute, say, top: 10px;, it will shift its position 10 pixels DOWN from
where it would NORMALLY be.
Position-Absolute. This is a very powerful type of positioning that allows you to literally
place any page element exactly where you want it. You use the positioning attributes top,
left bottom and right to set the location. Remember that these values will be relative to the
next parent element. If there is no such parent, it will default all the way back up to the
<html> element itself meaning it will be placed relatively to the page itself.
35
Position-Fixed. This type of positioning is fairly rare but certainly has its uses. A fixed
position element is positioned relative to the viewport, or the browser window itself. The
viewport doesnt change when the window is scrolled, so a fixed positioned element will stay
right where it is when the page is scrolled.
15. What does z-index do?
The z-index property specifies the stack order of an element.
An element with greater stack order is always in front of an element with a lower stack
order.
Here is the Example, where using z-index property you can display in front of image.
<head>
<style>
img
{
position:absolute;
left:0px;
top:0px;
z-index:-1;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<img src=w3css.gif width=100 height=140 />
<p>Because the image has a z-index of -1, it will be placed behind the text.</p>
</body>
(4) Define and explain : what is CSS opacity and transparency? How it works?
You can use opacity property to make the original image displayed transparent / semi
transparent on your web page.
I have an example as to how you can use the property :
36
<style>
img {
opacity: 0.5;
filter: alpha(opacity=50); /* For IE8 and earlier */
}
</style>
37