Download Attribute: HTML5

In this video tutorial we’ll show you how we can add download attribute and make the UX(User Experience) little better!

Related Read: HTML5 and CSS3 Video Tutorial List

We’ve seen so many times that a PDF file available for download opens up in the browser once the link is clicked. Same way the rar files, zip files, image files etc. We could add download attribute and fix this simple issue.

HTML5: Download Attribute with Value

1
2
3
 <a href="Picture1.jpg" download="book.jpg">
    Download Book Cover
 </a>

Once we add download attribute to the anchor tag, once someone clicks on the link, the linked resource starts to download, instead of opening in the browser.

The value, if present, to download attribute will be used to replace the original name of the resource file linked in the anchor tag.

Download Attribute: HTML5


[youtube https://www.youtube.com/watch?v=Wg6bMQ9leMQ]

YouTube Link: https://www.youtube.com/watch?v=Wg6bMQ9leMQ [Watch the Video In Full Screen.]



Full Free Code: HTML5 Download Attribute with Value

1
2
3
4
5
6
7
8
9
10
11
12
13
< !doctype html>
<html>
<head>
<title>Download Attribute</title>
</head>
<body>
 
 <a href="Picture1.jpg" download="book.jpg">
    Download Book Cover
 </a>
 
</body>
</html>

Make sure you have the doctype of html5(First line in above code).

progress Element: HTML5

Lets look at the progress element of HTML5.

progress-element-html5-progress-bar

You could implement this progress element of HTML5 with the file upload or the user form filling etc, to indicate the amount of upload or the profile completion.

HTML file
index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
< !DOCTYPE html>
<html>
<head>
<title>progress Element: HTML5</title>
<link href="myStyle.css" rel="stylesheet"/>
</head>
<body>
 
<form>
<label>Progress: </label>
 <progress value="50" max="100">50%</progress>
</form>
 
</body>
</html>

Here we have a progress element, with 100 as max and 50 as it’s value. This way, the progress bar indicates that the progress is 50% complete. Also there is a text between the progress tag, which is used as a fall back text for browsers which do not yet support progress element of HTML5.

CSS file associated with this is same as present at pattern and title Attribute of Form Field: HTML5

progress element – progress bar: HTML5


[youtube https://www.youtube.com/watch?v=s1tfYfCpZx8]

YouTube Link: https://www.youtube.com/watch?v=s1tfYfCpZx8 [Watch the Video In Full Screen.]



Change the number present in value and max attribute and look at the visual effect/indication of the progress on the browser.

Note: In real time application development, you could fetch the numbers for value and max attribute dynamically using JavaScript. This way, the effects will be real and it creates the illusion that the progress is being made!

color Input Type: HTML5

color input type fields expect the user to pick the color from the color palette. Once the user selects the color its corresponding hexadecimal value is being stored in the input field.

form-input-type-color-type-html5

Demo

There are jQuery plugins to accomplish this task, but with HTML5 we need not use any plugins to accomplish this!

HTML file
index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
< !DOCTYPE html>
<html>
<head>
<title>color Input Type: HTML5</title>
<link href="myStyle.css" rel="stylesheet" />
<script src="myScript.js"></script>
</head>
<body onload="fetch()">
 
<div>
<label for="color">Color pick: </label>
 <input name="color" type="color" id="get" onchange="fetch()"/><br />
<label for="hexa">Hex Code: </label>
 <input name="hexa" type="text" id="put"/><br />
</div>
 
</body>
</html>

Here we have 2 input fields of type color and text respectively. Once the user selects a color from the color palette, the corresponding hexadecimal value is shown in the text input type field.

JavaScript file
myScript.js

1
2
3
4
5
function fetch()
{
var get = document.getElementById("get").value;
document.getElementById("put").value = get;
}

Once the fetch method is called: it fetches the value present in the (color)input field and assigns it to text input field.

CSS file associated with this is same as present at pattern and title Attribute of Form Field: HTML5

Form Input Type – color: HTML5


[youtube https://www.youtube.com/watch?v=MiCOVDrVH44]

YouTube Link: https://www.youtube.com/watch?v=MiCOVDrVH44 [Watch the Video In Full Screen.]



Note: In real production server, you need not use two input fields as shown in this video tutorial. You can simply make use of the color input type and once you submit the form, you’ll get hexadecimal code value in place of the color input field. If you have a large audience still using Internet Explorer or other older browsers, then you can use jQuery plugin to accomplish the same task across all major browsers.

date time Input Type: HTML5

Today lets learn some very important input types of HTML5:

datetime
datetime-local
date
time
week
month

form-input-type-date-time-type-html5

datetime input type is supported by Opera browser, but as of now(2013), Google Chrome doesn’t support it. All other input date time related input types are supported by Google Chrome.

HTML file: month input type
index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
< !DOCTYPE html>
<html>
<head>
<title>date picker: HTML5</title>
<link href="myStyle.css" rel="stylesheet" />
</head>
<body>
 
<form>
<label for="dt">Date: </label>
 <input name="dt" type="month" min="2013-01" max="2013-09"/>
 <input type="submit"/>
</form>
 
</body>
</html>

Here we have a month type input field which has a minimum allowed month as 2013-01 and a maximum allowed month as 2013-09.

HTML file: date input type
index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
< !DOCTYPE html>
<html>
<head>
<title>date picker: HTML5</title>
<link href="myStyle.css" rel="stylesheet" />
</head>
<body>
 
<form>
<label for="dt">Date: </label>
 <input name="dt" type="date"/>
 <input type="submit"/>
</form>
 
</body>
</html>

Here we have a date input type, which shows a date picker in the UI.

HTML file: time input type
index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
< !DOCTYPE html>
<html>
<head>
<title>date picker: HTML5</title>
<link href="myStyle.css" rel="stylesheet" />
</head>
<body>
 
<form>
<label for="dt">Date: </label>
 <input name="dt" type="time"/>
 <input type="submit"/>
</form>
 
</body>
</html>

Here we have a time input type, we could even specify the fractional seconds. Look for the syntax at the end of this post.

HTML file: datetime input type
index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
< !DOCTYPE html>
<html>
<head>
<title>date picker: HTML5</title>
<link href="myStyle.css" rel="stylesheet" />
</head>
<body>
 
<form>
<label for="dt">Date: </label>
 <input name="dt" type="datetime"/>
 <input type="submit"/>
</form>
 
</body>
</html>

datetime input type which signifies Universal Time Convention(UTC).

HTML file: datetime-local input type
index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
< !DOCTYPE html>
<html>
<head>
<title>date picker: HTML5</title>
<link href="myStyle.css" rel="stylesheet" />
</head>
<body>
 
<form>
<label for="dt">Date: </label>
 <input name="dt" type="datetime-local"/>
 <input type="submit"/>
</form>
 
</body>
</html>

Here we have a datetime-local input type, which takes the input based on the local time zone of the user’s machine.

HTML file: week input type
index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
< !DOCTYPE html>
<html>
<head>
<title>date picker: HTML5</title>
<link href="myStyle.css" rel="stylesheet" />
</head>
<body>
 
<form>
<label for="dt">Date: </label>
 <input name="dt" type="week"/>
 <input type="submit"/>
</form>
 
</body>
</html>

week input type gives date picker UI and allows user to select the entire date.

Form Input Type – date time: HTML5


[youtube https://www.youtube.com/watch?v=VKRuSryBaNk]

YouTube Link: https://www.youtube.com/watch?v=VKRuSryBaNk [Watch the Video In Full Screen.]



Related Read: Format Date and Insert Into Database Table: PHP

Note:
We can specify value, min, max and step attributes for all these input types. And the format for it is as shown below:

date YYYY-MM-DD default step 60 seconds

time HH:MM:SS.FF default step 1 Day (SS.FF means seconds and fractional seconds)

datetime YYYY-MM-DDTHH:MM:SS.FFZ default step 60 seconds (T and Z means the TimeZone, these alphabets/characters must be literally present in the format)

datetime-local YYYY-MM-DDTHH:MM:SS.FF default step 60 seconds (albhabet/character/letter T must be literally present in the format)

week YYYY-WNN default step of 1 week (letter W means the week, this alphabet/characters must be literally present in the format)

month YYYY-MM default step of 1 month

range Input Type: HTML5

Browsers which support range input type know that the field is used for entering a number with in a given range.

form-input-type-range-type-html5

User Interface(UI) enhancement wise, you may get a slider control to select a range of number. You can even use min, max and step attributes to provide additional control for the field – for setting the range.

HTML file
index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
< !DOCTYPE html>
<html>
<head>
<title>range Input Type: HTML5</title>
<link href="myStyle.css" rel="stylesheet" />
<script src="myScript.js"></script>
</head>
<body>
 
<form>
<label>Range(2 to 10): </label>
 <input type="range" min="2" max="10" id="get" step="0.2" onchange="fetch()"/>
 <input type="number" min="2" max="10" step="0.2" id="put" />
 <input type="submit"/>
</form>
 
</body>
</html>

Here we have 2 input fields of type range and number respectively. Both having minimum allowed value as 2 and maximum allowed value as 10, and a step of 0.2 (fractional value). The number input field is taken for the sake of illustrating the value selected by the user using the range input field – by using(sliding) the slider.

JavaScript file
myScript.js

1
2
3
4
5
function fetch()
{
var get  = document.getElementById("get").value;
document.getElementById("put").value = get;
}

Here we fetch the value selected by the user using the slider and assign the value to the number input field.

CSS file associated with this is same as present at pattern and title Attribute of Form Field: HTML5

Form Input Type – range: HTML5


[youtube https://www.youtube.com/watch?v=YecwKiFBt0s]

YouTube Link: https://www.youtube.com/watch?v=YecwKiFBt0s [Watch the Video In Full Screen.]



Note: Browsers which do not support range input type, simply fall back to text input type. However, you need to validate the user entered data at server-side for more security. Client side validation is done mainly for the sake of creating the illustration of speed of validating the data and for a better user experience.