Professional Documents
Culture Documents
1 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
home
articles
quick answers
discussions
Member 11342613
features
community
459
Sign out
help
Article
Info
Browse Code
Stats
Rate:
First Posted
9 Oct 2014
Views
8,063
Downloads
8,308
Bookmarked
308 times
Comments (82)
Vote!
Revisions (8)
Alternatives
CPOL
ASP.NET
Download OfflineApp.zip - 21 KB
HTML
Beginner
Application
validation
Research
Introduction
Securing Cloud
Apps with a
Distributed Web...
Error monitoring:
The Key to
Innovative...
Cache
VS2013
HTML5/CSS3
Related Articles
A Professional HTML
Renderer You Will
Use
If you dont know anything about HTML then this article is not for you. We wont talk about break (<br>), Bold
(<b>) tags here, rather we will look into new concepts in HTML 5.
Complete List
Day 1
Day 2 Part 1
Day 2 Part 2 (coming soon)
Day 3 Part 3 (coming soon)
Agenda
Introduction to HTML 5
What is difference between SGML, HTML and XML?
What is Doc type?
How HTML 5 is different from previous versions?
HTML 5 New features
Lab 1 Understanding new Page structure semantics
Lab 2 Demo with New Input attributes
New type values
Some useful attributes
Lab 3 Understanding HTML 5 Datalist control
Lab 4 Output element
Lab 5, 6 and 7 Understanding HTML 5 validation feature
3/28/2015 1:04 PM
2 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
Introduction to HTML 5
Lets start with understainding some basic, intriguing and unaware terminologies and concepts.
What is difference between SGML, HTML and XML?
What is Doc type?
How HTML 5 is different?
Understand HTML
Now as per the w3.org DOCTYPEs is required in top of every HTML document despite of its HTML4 or HTML 5.
When omitted, browsers tend to use a different rendering mode that is incompatible with some specifications.
Including the DOCTYPE in a document ensures that the browser makes a best-effort attempt at following the
relevant specifications.
3/28/2015 1:04 PM
3 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
Earlier HTML didnt had standard tags or elements for defining different visible sections of a document such
as header of document, footer of a document, content of a document etc. Some people were using div
decorated with some css styles and some were using tabletrtd. Problem with this approach was
inconsistency.
Now with HTML 5 we have support for standard tags such as Header, Footer, nav, FigCaption (figure
caption) etc., each of which will represent some special section.
These tags makes our markup a semantic markup.
Note: - This tag doesnt provide any special advantages in rendering. They only makes our HTML structure
meaningful.
3/28/2015 1:04 PM
4 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
Range
<input type="range" name="MyRangeElement" id="MyRangeElement"/>
Color
<input type="color" id="MyColorElement" name="MyColorElement" />
Date
<input type="date" id="MyDateElement" name="MyDateElement" />
Time
<input type="time" id="MyTimeElement" name="MyTimeElement"/>
Datetime-local
<input type="datetimelocal" id="MyDateTimeLElement" name="MyDateTimeLElement" />
3/28/2015 1:04 PM
5 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
Month
<input type="month" id="MyMonthElement" name="MyMonthElement" />
Week
<input type="week" id="MyWeekElement" name="MyWeekElement" />
This code makes focus to be set on MyMonthElement control element by default when page loads for the first
time.
Note: In case autofocus is attached to multiple controls focus will be set on first control.
Placeholder
3/28/2015 1:04 PM
6 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
Click here if you are interested in learning how to make datalist dynamic using Asp.net MVC.
Note: Just like to lab2 markups, Output element wont provide any special advantage other than adding
semantic meaning to our UI.
3/28/2015 1:04 PM
7 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
But now validation code will become a standard code with the help of new HTML 5 validation support.
<label>URL:</label>
<input type="url" id="url" name="url" />
<label>Telephone</label>
<input type="tel" id="phone" name="phone" />
<label>Number Demo:</label>
<input type="number" name="MyNumberElement" id="MyNumberElement" />
<label>Range Demo:</label>
<input type="range" name="MyRangeElement" id="MyRangeElement" />
<label>Color Demo</label>
<input type="color" id="MyColorElement" name="MyColorElement" />
</td>
<td>
<label>Date Demo</label>
<input type="date" id="MyDateElement" name="MyDateElement" />
<label>Time Demo</label>
<input type="time" id="MyTimeElement" name="MyTimeElement" />
<label>Month Demo</label>
<input type="month" id="month" name="month" />
<label>Week Demo</label>
<input type="week" id="MyWeekElement" name="MyWeekElement" />
<div style="textalign:right">
<input type="submit" value="validate" />
</div>
</td>
</tr>
</table>
</form>
Note: In the code you can see that we have introduced some new input types like email, url, tel etc. These types
will only serves validation. As per rendering is concerned they will simply generates textbox.
Step 2 Execute and test the application
3/28/2015 1:04 PM
8 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
As you can see values in the input controls are validated and a predefined error message is shown (in a popup)
automatically in case of validation fail.
Note: In the image I have shown demo for only three input controls. You can download the source attached and
check for other
<label>User Name</label>
<input type="text" name="username"
id="username" pattern="[azAZ]{5,}" />
<label>Age</label>
<input type="number" name="TxtAge"
id="TxtAge" min="10" max="50" />
Explanation:
Required attributes makes textbox a compulsory field
Pattern attribute is set to a regular expression indicating that it should contain minimum 5 and maximum
10 character
Min and Max attribute works with number input control and force control to contain values within that
range.
Output:
3/28/2015 1:04 PM
9 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
required/>
<label>User Name</label>
<input type="text" name="username"
id="username" pattern="[azAZ]{5,10}"
/>
<label>Age</label>
<input type="number" name="TxtAge"
id="TxtAge" min="10" max="50" />
<span class="AgeIsNotInRangeSpan invalid">Age must be be between 10 and 50</span>
<span class="InvalidAgeSpan invalid">Invalid Age</span>
Step 2 Add a style tag and create css to hide error messages initially
<style>
.invalid {
display: none;
}
</style>
3/28/2015 1:04 PM
10 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
event.preventDefault(); - It will prevent the default behavior. Show error message as popup.
event.srcElement - Control to which contain invalid value. In this case email textbox.
element.validity Contains the validation information about control. Important attributes are
valueMissing will be true when required attribute is attached to control and current value is
blank.
typeMismatch will be true when type mismatches with current value of control.
badInput will be true when value in the control is invalid. Example Its a number textbox and
alphatic character is added.
rangeOverflow and rangeUnderflow will be true when control is number textbox and values are
not within the range
Step 5 Execute and Test the application
You can download the attached source code for complete demonstration.
CACHE:
/Styles/Style.css
<!DOCTYPE html>
3/28/2015 1:04 PM
11 of 18
<html
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
manifest="MyCache.txt">
<head runat="server">
<title></title>
<link href="Styles/Style.css" rel="stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div class="DivStyle" id="MyDiv">
Hi, Execution count is 1
</div>
</form>
</body>
</html>
Step 6 Go offline
CACHE:
/Styles/Style.css
3/28/2015 1:04 PM
12 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
MyPage.aspx to run properly in offline mode. All of these files will be cached along with MyPage.aspx.
4. End user will get the latest contents during the first request and then they get cached. All the subsequent
requests will get cached version.
5. Cache will get updated when something get changed inside manifest file hence in manifest file just after
CACHE MANIFEST keyword one comment line is added. In this example we mentioned it as ver 2 but it
can be anything.
6. When end user makes a request if requesting contents are cached browser will return the cached version
of the content but in the same time in the background browser will make a request for manifest and see if
manifest is changed in the server. In case it is changed Cache will be updated. But as I said it will be done
in the background hence the current request will get the old content. Hence we have to make double
refresh
3/28/2015 1:04 PM
13 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
when it goes offline. Example when its online everything should be red but when offline everything
should be green.
Fallback let us define those settings.
Lets have a demo and understand it.
Step 1 Create a new Asp.net Web Forms application
Open visual studio and create a new empty asp.net web forms application
Step 2 Create stylesheet Files
Right click the project. Add new folder and name it Styles
Right click the styles folder >> Add >> New Item. Select style sheet and name it style.css
Add following css block inside style.css
.Div1 {
backgroundcolor:silver;
}
Right click the styles folder >> Add >> New Item. Select style sheet and name it style2.css
Add following css block inside style2.css
.Div3 {
backgroundcolor:silver;
}
Right click the project. Add new folder and name it OnlineStyles
Right click the OnlineStyles folder >> Add >> New Item. Select style sheet and name it Style3.css
Add following css block inside style.css
.Div3 {
backgroundcolor:silver;
}
Right click the project. Add new folder and name it OfflineStyles
Right click the OfflineStyles folder >> Add >> New Item. Select style sheet and name it Style4.css
Add following css block inside style.css
.Div3 {
backgroundcolor:lightbue;
}
CACHE:
/Styles/Style.css
# Comment – Style.css will be cached with page
NETWORK:
/Styles/Style2.css
# Comment – Style2.css will be available only online
FALLBACK:
OnlineStyles\Style3.css OfflineStyles\Style4.css
# Comment – Style3.css will be used when online and style4.css will be cached and used when
application is offline
3/28/2015 1:04 PM
14 of 18
<html
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
manifest="MyCache.txt">
<head runat="server">
<title></title>
<link href="Styles/Style.css" rel="stylesheet" />
<link href="Styles/Style2.css" rel="stylesheet" />
<link href="OnlineStyles/Style3.css" rel="stylesheet" />
<script>
window.applicationCache.onupdateready = function (e) {
applicationCache.swapCache();
location.reload();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="Div1" id="MyDiv1">
Hi, Execution count is 1
</div>
<div class="Div2" id="MyDiv2">
Hi, Execution count is 1
</div>
<div class="Div3" id="MyDiv3">
Hi, Execution count is 1
</div>
</form>
</body>
</html>
Step 6 Go offline
As you can style2.css didnt cached and style3.css is replaced with style4.css
3/28/2015 1:04 PM
15 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
You are online but still style2.css formatting is not applying because only application get cached it will always
loaded from the cache.
When you specify Style2.css in NETWORK section it will always load that file from online location. If you are
online it will work, if you are offline they wont get loaded.
Summary
So thats it for Day 1.
For 500+ videos on MSBI, .NET, SharePoint, Architecture, SQL, WPF, WCF, MVC, ASP.NET etc click
@ www.questpond.com
References
http://www.codeproject.com/Articles/702051/important-HTML-Interview-questions-with-answe
License
This article, along with any associated source code and files, is licensed under The Code Project Open License
(CPOL)
3/28/2015 1:04 PM
16 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
Share
EMAIL
My sites
justcompile.com
www.sukesh-marla.com
@Twitter
@Facebook
Follow on
Spacing
Relaxed
Noise Medium
Layout Normal
Go
Per page 50
Update
Nice information
sandeepkumarvemula
24-Mar-15 3:38
Marla Sukesh
24-Mar-15 5:47
Sangunni
28-Jan-15 9:48
My vote of 5
M Rayhan
5-Dec-14 4:19
Re: My vote of 5
Where I can get DAY 2 and Day 3?
Re: Where I can get DAY 2 and Day 3?
My vote of 5
Re: My vote of 5
Quality article...we need more true HTML5 tutorials
Marla Sukesh
6-Dec-14 12:43
abhishekdec1
4-Dec-14 8:18
Marla Sukesh
4-Dec-14 11:20
StanleyJHubert
Marla Sukesh
Member 11067341
4-Dec-14 5:09
4-Dec-14 11:20
3-Dec-14 9:06
3/28/2015 1:04 PM
17 of 18
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
Marla Sukesh
4-Dec-14 2:50
Member 11067341
4-Dec-14 8:51
Member 10375744
17-Nov-14 3:45
excellent
Re: excellent
My vote of 5
Re: My vote of 5
How can I validate the input that uses the datalist?
Re: How can I validate the input that uses the datalist?
Good job, Thanks!
Re: Good job, Thanks!
Good job
Re: Good job
My vote of 5
Re: My vote of 5
Good Work!!
Re: Good Work!!
Where is day 2 and day 3
Re: Where is day 2 and day 3
Very nice!
Re: Very nice!
My vote of 5
Re: My vote of 5
about html5
Re: about html5
My vote of 5
Re: My vote of 5
Thanks!
Re: Thanks!
About day 2
Re: About day 2
My vote of 3
Re: My vote of 3
Re: My vote of 3
Re: My vote of 3
Re: My vote of 3
Re: My vote of 3
I'd give it a 4, also
Re: I'd give it a 4, also
Re: I'd give it a 4, also
Marla Sukesh
VaibhavKamble
Marla Sukesh
Member 8773468
Marla Sukesh
SOSPC
Marla Sukesh
BaharDev
3-Dec-14 12:42
3-Dec-14 12:43
17-Nov-14 2:19
3-Dec-14 12:43
16-Nov-14 11:38
3-Dec-14 12:45
11-Nov-14 8:35
3-Dec-14 12:45
11-Nov-14 3:22
Marla Sukesh
3-Dec-14 12:45
Mahsa Hassankashi
9-Nov-14 8:05
Marla Sukesh
3-Dec-14 12:46
2-Nov-14 14:33
3-Dec-14 12:46
28-Oct-14 21:35
Marla Sukesh
3-Dec-14 12:46
Member 3483641
28-Oct-14 3:31
Marla Sukesh
3-Dec-14 12:47
24-Oct-14 5:16
Marla Sukesh
24-Oct-14 6:47
Member 11171047
23-Oct-14 2:23
Marla Sukesh
24-Oct-14 6:47
JCahyaatnttearjee
20-Oct-14 23:59
Marla Sukesh
21-Oct-14 11:34
Martin Berger
18-Oct-14 21:14
Marla Sukesh
21-Oct-14 11:33
Member 8651121
18-Oct-14 12:49
Marla Sukesh
18-Oct-14 14:44
Member 10419815
17-Oct-14 14:09
Marla Sukesh
17-Oct-14 14:14
Member 10419815
17-Oct-14 14:19
Marla Sukesh
17-Oct-14 14:53
Member 9666728
17-Oct-14 17:06
Heriberto Lugo
18-Oct-14 20:24
chuckles_net
17-Oct-14 13:42
Marla Sukesh
17-Oct-14 14:13
chuckles_net
17-Oct-14 17:51
3/28/2015 1:04 PM
18 of 18
General
News
http://www.codeproject.com/Articles/827673/Learn-HTML-in-days-Day
Suggestion
Question
Refresh
Bug
Answer
Joke
Rant
1 2 Next
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
3/28/2015 1:04 PM