HTML5 Interview Questions
HTML5 Interview Questions
by www.questpond.com (One stop place for .Net and C# interview question videos)
Contents
Introduction
I am AS .N!" #$C developer and recently w%en I was loo&in' for a (ob lot of questions were as&ed connected to )"#* + and its new features. So below are ,- important questions w%ic% would %elp you brus% up your &nowled'e on )"#* +. "%ese questions are not silver bullet to 'et a (ob but yes t%ey are %elpful w%en you want to quic&ly brus% up t%e topic. )appy (ob %untin'.
Courtesy. / www.questpond.com
Now parsin' S0#* was a pain so t%ey created 7#* to ma&e t%in's better. 7#* uses S0#*. 8or e9ample in S0#* you %ave to start and end ta's but in 7#* you can %ave closin' ta's w%ic% close automatically (4:;customer<6). 7)"#* was created from 7#* w%ic% was used in )"#* ,.-. So for e9ample in S0#* derived )"#* 4:;br<6 is not valid but in 7)"#* it2s valid. 5ou can refer 7#* 3"3 as s%own in t%e below code snippet.
<!DOCTYPE html PUBLIC "-//W3C//DTD +HTML 1.0 T#,-&'t'"-,l//EN" "http //!!!.!3."#$/T%/.html1/DTD/.html1-t#,-&'t'"-,l.)t)"*
In s%ort S0#* is t%e parent of every one. Older )"#* utili1es S0#* and )"#* ,.- uses 7)"#* w%ic% derived from 7#*.
What is HTML 5?
)"#* + is a new standard for )"#* w%ose main tar'et is to deliver everyt%in' wit%out need to any additional plu'ins li&e flas%= Silverli'%t etc. It %as everyt%in' from animations= videos= ric% 0>I etc. )"#*+ is cooperation output between ?orld ?ide ?eb Consortium (?@C) and t%e ?eb )yperte9t Application "ec%nolo'y ?or&in' 0roup (?)A"?0).
How is the pa+e structure o HTML 5 di erent ro( HTML , or pre-ious HTML?
A typical web pa'e %as %eaders= footers= navi'ation= central area and side bars. Now if we want to represent t%e same in )"#* , wit% proper names to t%e )"#* section we would probably use a 3I$ ta'. Aut in )"#* + t%ey %ave made it more clear by creatin' element names for t%ose sections w%ic% ma&es your )"#* more readable.
Aelow are more details of t%e )"#* + elements w%ic% form t%e pa'e structure. :%eader<. Bepresents %eader data of )"#*. :footer<. 8ooter section of t%e pa'e. :nav<. Navi'ation elements in t%e pa'e. :article<. Self/contained content. :section<. >sed inside article to define sections or 'roup content in to sections. :aside<. Bepresent side bar contents of a pa'e.
If you want to create a )"#* te9t wit% email validation we can set t%e type as 4email6.
<'-p/t t1p30"3m,'l" -,m30"3m,'l"*
8or >B* validation set t%e type as 4url6 as s%own in t%e below )"#* code.
8or >B* validation set t%e type as 4url6 as s%own in t%e below )"#* code. If you want to display te9tbo9 wit% number ran'e you can set type to number.
<'-p/t t1p30"-/m53#" -,m30"6/,-t't1" m'-0"1" m,.0"7"*
If you want to display a ran'e control you can use type as ran'e.
Aelow 'oes t%e code of %ow to use output element wit% )"#* +.
<4"#m "-&/5m't0"#3t/#- 4,l&3" "-'-p/t0"".2,l/3 0 p,#&3I-t;,.2,l/3< = p,#&3I-t;5.2,l/3<"* <'-p/t -,m30"," t1p30"-/m53#"* = <'-p/t -,m30"5" t1p30"-/m53#"* 0 <"/tp/t -,m30"""*</"/tp/t* </4"#m*
5ou can also replace 4parseInt6 wit% 4valueAsNumber6 for simplicity. 5ou can also use 4for6 in t%e output element for more readability.
What is S.G?
S$0 stands for scalable vector 'rap%ics. It2s a te9t based 'rap%ic lan'ua'e w%ic% draws ima'es usin' te9t= lines= dots etc. "%is ma&es it li'%twei'%t and renders faster.
Aelow is %ow t%e code of )"#* +. 5ou can see t%e S$0 ta' w%ic% encloses t%e poly'on ta' for displayin' t%e star ima'e.
<&2$ ')0"&2$3l3m" h3'$ht0"800" .ml-&0"http //!!!.!3."#$/8000/&2$"* <l'-3 .10"0" 110"0" .80"800" 180"100" &t1l30"&t#">3 #3)?&t#">3-!')th 8"/* </&2$*
So to define canvas area you need to use t%e below )"#* code. "%is defines t%e area on w%ic% you can draw.
<(,-2,& ')0"m1(,-2,&" !')th0"900" h3'$ht0"700" &t1l30"5"#)3# 1p. &"l') @000000?"*</(,-2,&*
Get access to canvas area "o draw on t%e canvas area we need to first 'et reference of t%e conte9t section. Aelow is t%e code for canvas section.
2,# (0)"(/m3-t.$3tEl3m3-tB1I);"m1(,-2,&"<? 2,# (t.0(.$3tC"-t3.t;"8)"<?
Draw the graphic Now once you %ave access to t%e conte9t ob(ect we can start drawin' on t%e conte9t. So first call t%e 4move6 met%od and start from a point = use line met%od and draw t%e line and t%en apply stro&e over it.
(t..m"23T";10A10<? (t..l'-3T";800A100<? (t..&t#">3;<?
<5")1 "-l",)0"D#,!M3;<?"* <(,-2,& ')0"m1(,-2,&" !')th0"900" h3'$ht0"700" &t1l30"5"#)3# 1p. &"l') @000000?"*</(,-2,&* </5")1* <&(#'pt* 4/-(t'"- D#,!M3;< B 2,# (0)"(/m3-t.$3tEl3m3-tB1I);"m1(,-2,&"<? 2,# (t.0(.$3tC"-t3.t;"8)"<? (t..m"23T";10A10<? (t..l'-3T";800A100<? (t..&t#">3;<? C
<&2$ .ml-&0"http //!!!.!3."#$/8000/&2$" 23#&'"-0"1.1"* <('#(l3 (.0"100" (10"70" #0"40" &t#">30"5l,(>" &t#">3-!')th0"8" 4'll0"#3)"/* </&2$*
2,# (,-2,& 0 )"(/m3-t.$3tEl3m3-tB1I);Gm1C,-2,&G<? 2,# ("-t3.t 0 (,-2,&.$3tC"-t3.t;G8)G<? 2,# (3-t3#+ 0 (,-2,&.!')th / 8? 2,# (3-t3#Y 0 (,-2,&.h3'$ht / 8? 2,# #,)'/& 0 H0? ("-t3.t.53$'-P,th;<? ("-t3.t.,#(;(3-t3#+A (3-t3#YA #,)'/&A 0A 8 I M,th.PIA 4,l&3<? ("-t3.t.4'llDt1l3 0 G$#33-G? ("-t3.t.4'll;<? ("-t3.t.l'-3W')th 0 7? ("-t3.t.&t#">3Dt1l3 0 G@003300G? ("-t3.t.&t#">3;<?
<!DOCTYPE html* <html* <5")1 "-l",)0"D#,!M3;<?"* <&2$ !')th0"700" h3'$ht0"100"* <('#(l3 ')0"('#(l31" (.0"80" (10"80" #0"10" &t1l30"&t#">3 </&2$* -"-3? 4'll @440000?"/*
</5")1* <&(#'pt* 2,# t'm3#J/-(t'"- 0 &3tI-t3#2,l;D#,!M3A 80<? ,l3#t;")))"<? 4/-(t'"- D#,!M3;< B 2,# ('#(l3 0 )"(/m3-t.$3tEl3m3-tB1I);"('#(l31"<? 2,# . 0 ('#(l3.$3tKtt#'5/t3;"(."<? 2,# -3!+ 0 8 = p,#&3I-t;.<? '4;-3!+ * 700< B -3!+ 0 80? C ('#(l3.&3tKtt#'5/t3;"(."A -3!+<? C </&(#'pt* </html*
What are selectors in CSS? Selectors %elp to select an element to w%ic% you want to apply a style. 8or e9ample below is a simple style called as Iintro6 w%ic% applies red color to bac&'round of a )"#* element.
<&t1l3* .'-t#" B 5,(>$#"/-)-("l"# #3)? C </&t1l3*
"o apply t%e above 4intro6 style to div we can use t%e 4class6 selector as s%own in t%e below fi'ure.
<)'2 (l,&&0"'-t#""*
<p*M1 -,m3 '& Dh'2p#,&,) >"'#,l,.</p* <p*I !#'t3 '-t3#2'3! 6/3&t'"-&.</p* </)'2*
How can you apply CSS style using ID value? So let2s say you %ave a )"#* para'rap% ta' wit% id 4myte9t6 as s%own in t%e below snippet.
<p ')0"m1t3.t"*Th'& '& HTML '-t3#2'3! 6/3&t'"-&.</p*
5ou can create a style usin' 4#6 selector wit% t%e 4id6 name and apply t%e CSS value to t%e para'rap% ta'. So to apply style to 4myte9t6 element we can use 4#myte9t6 as s%own in t%e below CSS code.
<&t1l3* @m1t3.t B 5,(>$#"/-)-("l"# 13ll"!? C </&t1l3*
Quick revision of some important selectors Set all para'rap% ta's bac& 'round color to yellow.
PAh1 B 5,(>$#"/-)-("l"# 13ll"!? C
"o implement column layout we need to specify t%e followin'./ )ow many columns we want to divide t%e te9t in to J "o specify number of columns we need to us column/count. 4web&it6 and 4mo1/column6 are needed for c%rome and firefo9 respectively.
-m"N-("l/m--("/-t 3? /I J'#34". I/ -!35>'t-("l/m--("/-t 3? /I D,4,#' ,-) Ch#"m3 I/ ("l/m--("/-t 3?
3o you want to draw a line between t%ose columns = if yes %ow muc% t%ic& J
-m"N-("l/m--#/l3 4p. "/t&3t @440044? /I J'#34". I/ -!35>'t-("l/m--#/l3 4p. "/t&3t @440044? /I D,4,#' ,-) Ch#"m3 I/ ("l/m--#/l3 9p. "/t&3t @440044?
<&t1l3* .m,$,N'-3 B -m"N-("l/m--("/-t 3? /I J'#34". I/ -!35>'t-("l/m--("/-t 3? /I D,4,#' ,-) Ch#"m3 I/ ("l/m--("/-t 3? -m"N-("l/m--$,p 40p.? /I J'#34". I/ -!35>'t-("l/m--$,p 40p.? /I D,4,#' ,-) Ch#"m3 I/ ("l/m--$,p 80p.? -m"N-("l/m--#/l3 4p. "/t&3t @440044? /I J'#34". I/ -!35>'t-("l/m--#/l3 4p. "/t&3t @440044? /I D,4,#' ,-) Ch#"m3 I/ ("l/m--#/l3 9p. "/t&3t @440044? C </&t1l3*
5ou can t%en apply t%e style to t%e te9t by usin' t%e class attribute.
<)'2 (l,&&0"m,$,N'-3"* Y"/# t3.t $"3& h3#3 !h'(h 1"/ !,-t t" )'2')3 '- t" 3 ("l/m-&. </)'2*
#ar'in. / "%is defines t%e spacin' between border and any nei'%borin' elements.
8or instance below is a simple CSS code w%ic% defines a bo9 wit% border = paddin' and mar'in values.
.5". B !')th 5"#)3# p,))'-$ m,#$'C 800p.? 10p. &"l') @OO(? 80p.? 70p.?
Now if we apply t%e above CSS to a 3I$ ta' as s%own in t%e below code = your output would be as s%own in t%e fi'ure below. I %ave created two test 4Some te9t6 and 4Some ot%er te9t6 so t%at we can see %ow mar'in property functions.
<)'2 ,l'$-0"m'))l3" (l,&&0"5"."* D"m3 t3.t </)'2* D"m3 "th3# t3.t
*et2s say t%e above for loop code is e9ecuted on a )"#* button clic&. Now t%is met%od e9ecution is sync%ronous. In ot%er words t%e complete browser will wait until t%e for loop completes.
<'-p/t t1p30"5/tt"-" "-(l'(>0"D"m3H3,21J/-(t'"-;<?" /*
"%is can furt%er lead to browser 'ettin' free1ed and unresponsive wit% an error messa'e as s%own in t%e screen below.
So if we can move t%is %eavy for loop in a KavaScript file and run it async%ronously t%at means t%e browser does need to wait for t%e loop t%en we can %ave a more responsive browser. "%at2s w%at web wor&er are for. ?eb wor&er %elps to e9ecute KavaScript file async%ronously.
"o send messa'e to t%e wor&er ob(ect we need to use 4 ost#essa'e6 = below is t%e code for t%e same.
!"#>3#.p"&tM3&&,$3;<?
?%en t%e wor&er t%read sends data we 'et it in t%e 4On#essa'e6 event on t%e callers end.
!"#>3#."-m3&&,$3 0 4/-(t'"- ;3< B
)"(/m3-t.$3tEl3m3-tB1I);"t.t1"<.2,l/3 0 3.),t,? C?
"%e %eavy loop is in t%e 4#y)eavy rocess.(s6 (avascript file = below is t%e code for t%e same. ?%en t%e KavaScript file wants to send messa'e %e uses 4postmessa'e6 and any messa'e sent from t%e caller is received in t%e 4onmessa'e6 event.
2,# . 00 &3l4."-m3&&,$3 0 4/-(t'"- ;3< B 4"# ;' 0 0? ' < 1000000000? '==< B . 0 ' = .? C &3l4.p"&tM3&&,$3;.<? C?
Now to implement t%is &ind of requirement developers normally write some &ind of >** code w%ic% 'oes to t%e server and fetc%es data in certain interval. Now >** solution is 'ood but it ma&es t%e networ& c%atty wit% lot of calls and also it adds load on t%e server. So rat%er t%an >** it would be 'reat if we can %ave some &ind of >S) solution. In simple words w%en t%e server %as updates it will send updates to t%e browser client. "%at can be ac%ieved by usin' 4S!B$!B S!N" !$!N"S6. So t%e first t%in' t%e browser needs to do is connect to t%e server source w%ic% will send updates. *et2s say we %ave pa'e 4stoc&.asp96 w%ic% sends stoc& updates. So to connect to t%e pa'e we need to use attac% to t%e event source ob(ect as s%own in t%e below code.
2,# &"/#(3 0 -3! E23-tD"/#(3;"&t"(>.,&p."<?
?e also need to attac% t%e function w%ere we will receive messa'es w%en server sends update. 8or t%an we need to attac% function to t%e 4onmessa'e6 event as s%own in t%e below code.
&"/#(3."-m3&&,$3 0 4/-(t'"- ;323-t< B )"(/m3-t.$3tEl3m3-tB1I);"#3&/lt"<.'--3#HTML =0 323-t.),t, = "<5#*"? C?
Now from t%e server side we need to send events. Aelow are some lists of important events wit% command t%at needs to be sent from t%e server side.
!vent Send data to t%e client. "ell client to retry in Cseconds Baise a specific event wit% data Comman" data . %ello retry . C---event . success data . 5ou are lo''ed in.
So for e9ample if we want to send data below is t%e AS .N!" code for t%e same. lease note t%e content type is set to te9t;event.
If you want to attac% an event we need to use t%e 4add!vent*istener6 event as s%own in t%e below code.
&"/#(3.,))E23-tL'&t3-3#;Gm3&&,$3GA 4/-(t'"-;3< B ("-&"l3.l"$;3.),t,<? CA 4,l&3<?
8rom t%e server side t%e below messa'e will tri''er t%e 4messa'e6 function of (avascript.
323-t ),t,
m3&&,$3 h3ll"
"o retrieve data from local stora'e we need to use 4'etItem6 providin' t%e &ey name.
2,# ("/-t#1 0 l"(,lDt"#,$3.$3tIt3m;QR31001S<?
5ou can also store KavaScript ob(ect2s in t%e local stora'e usin' t%e below code.
2,# ("/-t#1 0 BC? ("/-t#1.-,m3 0 QI-)',S? ("/-t#1.(")3 0 QI001S? l"(,lDt"#,$3.&3tIt3m;QI001SA ("/-t#1<? 2,# ("/-t#11 0 l"(,lDt"#,$3.$3tIt3m;QI001S<?
If you want to store in KSON format you can use 4KSON.strin'ify6 function as s%own in t%e below code.
l"(,lDt"#,$3.&3tIt3m;QI001SATDON.&t#'-$'41;("/-t#1<<?
Si%e !&piration
"o create a session stora'e you need to use 4sessionStora'e.variablename6 . In t%e below code we %ave a created a variable called as 4clic&count6. If you refres% t%e browser t%e count increases. Aut if you close t%e browser and start a'ain t%e 4clic&count6 variable starts from 1ero.
'4;&3&&'"-Dt"#,$3.(l'(>("/-t< B &3&&'"-Dt"#,$3.(l'(>("/-t0N/m53#;&3&&'"-Dt"#,$3.(l'(>("/-t<=1? C 3l&3 B &3&&'"-Dt"#,$3.(l'(>("/-t 0 0? C
What is WebS3L?
?ebSM* is a structured relational database at t%e client browser side. It2s a local B3A#S inside t%e browser on w%ic% you can fire SM* queries.
"o e9ecute SM* we t%en need to use 4transaction6 function and call 4e9ecuteSql6 function to fire SM*.
)5.t#,-&,(t'"-;4/-(t'"- ;t.< B t..3.3(/t3D6l;GC%EKTE TKBLE IJ NOT E+IDTD t5lC/&t;') /-'6/3A (/&t"m3#-,m3<G<? t..3.3(/t3D6l;GINDE%T INTO t5l(/&t ;')A (/&t"m3#-,m3< EKLUED;1A "&h'2"<G<? t..3.3(/t3D6l;GINDE%T INTO t5l(/&t ;')A (/&t"m3#-,m3< EKLUED ;8A "#,P/"<G<? C
In case you are firin' 4select6 query you will 'et data is 4results6 collection w%ic% we can loop and display in t%e )"#* >I.
)5.t#,-&,(t'"-;4/-(t'"- ;t.< B t..3.3(/t3D6l;GDELECT I J%OM t5l(/&tGA LMA 4/-(t'"- ;t.A #3&/lt&< B 4"# ;' 0 0? ' < l3-? '==< B m&$ 0 "<p*<5*" = #3&/lt&.#"!&.'t3m;'<.l"$ = "</5*</p*"? )"(/m3-t.6/3#1D3l3(t"#;G@(/&t"m3#<.'--3#HTML =0 C CA -/ll<? C<? m&$?
All manifest file starts wit% CAC)! #ANI8!S" statement. #( %as% ta') %elps to provide t%e version of t%e cac%e file. CAC)! command specifies w%ic% files needs to be cac%ed. "%e content type of t%e manifest file s%ould be 4te9t;cac%e/manifest6.
Aelow is %ow cac%e manifest %as been provided usin' AS .N!" C#.
%3&p"-&3.C"-t3-tT1p3 0 "t3.t/(,(h3-m,-'43&t"? %3&p"-&3.W#'t3;"CKCHE MKNIJEDT V-"<? %3&p"-&3.W#'t3;"@ 8018-08-81 21.0.0 V-"<? %3&p"-&3.W#'t3;"CKCHE %3&p"-&3.Jl/&h;<? %3&p"-&3.E-);<? V-"<? %3&p"-&3.W#'t3;"L"$'-.,&p. V-"<?
One t%e cac%e manifest file is created t%e ne9t t%in' is to provide t%e lin& of t%e manifest file in t%e )"#* pa'e as s%own below.
<html m,-'43&t0"(,(h3.,&p."*
?%en t%e above file runs first time it 'ets added in t%e browser application cac%e and in case server 'oes down t%e pa'e is served from t%e application cac%e.
P,$3&.,&p.