In HTML5 you can play movie clip and other video streams using the new <video> tag. The src attribute specifies the URL of the video file. The controls attribute displays video controls which include:
Play
Pause
Seeking
Volume
Fullscreen toggle
Captions/Subtitles (when available)
Track (when available)
Internet Explorer 8 and earlier versions do not support the <video> tag. In order for users viewing your video through older or latest browsers you need to upload the video in at least two different formats as did in the example below. The <source> element inside the <video> element is used to run this video on all supported browsers. You specify alternative video/audio files which the browser may choose from, based on its media type or codec support. Use the <audio> tag to play audio files in HTML5.
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
Like every good website you can add search capabilities to your site. A search box allows users to search content that is not apparently visible to them. HTML5 has provided an input type called search to address search queries. Once again, the following code sends the search criteria to a page (abc.php) on the server to process the request.
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
There are some mandatory fields in a form that must not be left blank e.g. User ID, Password etc. Users are alerted to provide such information if they omit them. This process is called form validation. Usually, a scripting language (such as JavaScript - discussed in Chapter 3) is used by developers to validate a form on client machines prior to posting data to the server. But now, HTML5 is introducing client side validation to quickly identify problems in a form. Some of these are listed below with examples.
Required & Placeholder Attributes
The required attribute applies to all input fields, and specifies that an input field must be filled out before submitting the form. It is defined as <input required>. The placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample e-mail address in the expected format). The hint is displayed unless you type something in the input field.
Validate E-mail and URL
If your form has mandatory email and url fields, you can validate them using the new input type values as shown in the following examples. Browsers supporting HTML5 will check and validate the correct format.
<input type="email" name="email">
<input type="url" name="website">
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
In HTML5, a new date value is added to the type attribute which displays a calendar control on your web page from which users can select a desired date as demonstrated in the following example. As you can see this time we used a separate <label> tag to display a label for the calendar element. The for attribute of <label> element must be equal to the id attribute of the related element to bind them together.
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
To allow users to upload their documents, images, videos or other files to your web server you again use the <input> element with type="file" attribute. In such situations, you must set the method attribute value to POST. The accept attribute specifies the types of files that the server accepts. To specify more than one value, separate the values with a comma e.g. accept="audio/*,video/*,image/*".
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
If your form has different sections, you can separate them using the <fieldset> element which draws a box around the related form controls to group them. You add the <legend> tag immediately after the opening <fieldset> tag to define a caption that informs the purpose of that section.
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
Just like desktop application forms, you can create a push button on a web form as well using the markup <button type="button">text/image</button>. The main difference between this element and buttons created with the <input> element is that you can add text or image inside a button element which provides you more control over button's appearance.
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
After completing a web form you need something to inform the browser to send the information to the server. A submit button is used to accomplish this task and is the recommended way to submit HTML forms. It is defined using the tag <input type="submit"> and its value attribute acts as the button’s label. After clicking this button, the data is sent to the page specified in the form's action attribute which performs some actions with the received input. In the following exercise, the information is sent to a page "xyz.php" on the server. The server processes the input and returns the answer as shown in the output pane. For this purpose, we used the GET method which retrieves the inputted information from the server. Server processing is an advanced topic and will be discussed in Chapter 5 and Chapter 6. At this stage, if you click the submit button after running the example code, you'll get an error indicating that the browser could not find the file 'submit.php'. Besides SUBMIT you can use two other types, RESET and BUTTON. The RESET button sets all the form fields back to their default value, or blank. The BUTTON performs an action associated with a JavaScript event handler. If the user presses a Submit or a Reset button, you can detect it with the onSubmit or onReset event handlers. For generic buttons, you can use an onClick event handler.
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
Similar to radio buttons, a drop down list box also allows you to select a single option from the provided list. Usage depends on the scenario. For example, if the list has few options, use the radio buttons and to display a long list of products you must choose a drop down list box.
In HTML a dropdown list box is defined with the <select> tag in conjunction with two or more <option> elements. The <option> tags inside the <select> element define the available options in the list. An attribute called selected can be added to an option to mark it as the default selected option when the page loads.
Reading the value of a selected item is a two-step process. You first use the selectedIndex property, and then use the value property to find the value of the selected choice. Here's an example:
This uses the nIdx variable to store the selected index, and then assigns the value of the selected choice to the sCat variable. Things are a bit more complicated with a multiple selection where you need to test each option's selected attribute separately.
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
Defined using the tag <input type="checkbox">, checkboxes let a user select or de-select ONE or MORE options from the available choices. It has same attributes as radio buttons. It also has a single event, onClick, which occurs whenever the check box is clicked. This event examines the checked property to see whether the box was turned on or off.
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
Radio buttons let a user select ONLY ONE of a limited number of choices. It is defined as <input type="radio"> and has three main attributes - name, value, and checked. The name is sent along with the selected value to the server. The value attribute is the value passed to a script or a CGI program to indicate which button is selected. Be sure you assign a different value to each button. The checked attribute sets a default value when the page loads into the browser and is used with only one radio button in a group.
The entire group of radio buttons shares a single name and a single object. To access the individual buttons, you treat the radio object as an array. The buttons are indexed, starting with 0. You use the checked property of a radio button to check its current state. The following statement checks the first radio button in the ctype group on the contact form:
document.contact.ctype[0].checked == true;
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
If you’re acquainted with blogs, you must have seen a large text box under a blog post where users provide their comments. This box is a multi-line input control and is defined using its own tag called <textarea>. It can hold an unlimited number of characters and is specified by cols and rows attributes. The cols attribute, measured in numbers of characters, sets the width of the text area. The rows attribute indicates the height of the text area. The browser automatically adds a scroll bar when the text crosses the row attribute limit.
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
These are the most commonly used input fields defined with the <input> tag. This <input> tag is an empty tag without a closing tag and contains a TYPE attribute which determines what kind of input is being created. The <input type="text"> defines a one-line input field that a user can enter text into whereas, <input type="password"> creates a password field. The characters in a password field are masked - shown as asterisks or circles. The following table shows a couple of most utilized attributes associated with the <input> tag:
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
Forms are everywhere on the web. You might have interacted with HTML forms on web sites like Amazon, eBay, Yahoo!, and Google. The use of form on a page is a higher level phase of Web development to collect information from visitors. Whether it’s through registration forms, mailing lists, site searches, or online ordering, forms facilitate interaction between organizations / individuals with their clients or end users.
Let’s take Amazon as an example. You visit Amazon's website as a buyer and don’t verbally tell Amazon to find an item. Instead, you interact with a form containing form controls in the shape of a search text box and a Search button. You enter your search criteria into the text box, click the Search button, and get the results in a clean list format that you can quickly browse through.
From a seller’s perspective, the process is slightly more complex, but again, involves forms and form controls. When you want to sell an item on Amazon’s Web site, the first step is to register as a seller. During the registration process, you'll see a form with numerous form controls that collect different types of information from you.
In HTML you use the <form> tag to create a form; all form controls reside inside this tag. Every <form> tag requires an action attribute which specifies where to send the form-data when a form is submitted. You also use form's method attribute to send or retrieve data to or from server. This attribute can have either a GET or a POST value. The GET method is the default and is used when you want to retrieve something from the server, while the POST method is used to manipulate information on the server.
As per functionality both GET and POST methods are same with the following differences:
GET method shows the information to the users as it is sent appended to the URL. But in the case of POST method information will not be visible as it is sent encapsulated within the HTTP request body.
GET method has limitation in the size of data transmitted, but POST method hasn't.
Web browser can usually cache the response pages for GET requests, because they do not change. POST requests, however, cannot be cached, and the server is re-contacted each time the page is displayed.
GET requests should be used for pure queries that don’t affect anything on the server. POST requests are most suitable for queries where the response page will change over time – like a shopping cart.
The elements you can use in your web form include the following:
Text and password fields
Text area
Radio buttons
Checkbox
Drop-down list box
Button
File input to upload a file
Group box
Label
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
While surfing on the Internet you come across some very attractive websites and wonder how developers created those websites. All modern browsers allow you to see source code of websites. Just right-click an HTML page and select "View page source" (A) or similar option from the context menu. This will open a new tab or window showing the HTML source code of the page. In addition to this, you can also inspect an HTML element. Right-click on an element (B), and choose "Inspect" (C) or similar option from the context menu to see both the HTML and the CSS code of that element. Developers use Elements (D) and Styles panel (E) to modify both HTML and CSS on-the-fly.
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
A table is a set of data elements (values) that is organized using a model of vertical columns and horizontal rows, the cell being the unit where a row and column intersect. In HTML you use the following elements while defining a table:
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.
HTML lists are great for calling your reader's attention to specific information. It has been a popular tool even when writing business and technical documents. Lists draw attention to important information. Readers like them because they are visually appealing and make it easy to quickly find pertinent information. In HTML you can use three types of lists:
Ordered List: This list has items marked with numbers. It is defined using the tag <ol> and each item starts with the tag <li>.
Unordered List: Items in this list are marked with bullets. It is defined with the tag <ul>. Each list item is enclosed in the <li> tag.
Definition List: This list contains description of each item and is defined with the <dl> tag in conjunction with <dt> and <dd> to define list items and corresponding descriptions respectively.
You can use different Ordered and Unordered list on your web page by applying the following TYPE attributes:
You can also create nested listing as demonstrated below by putting a second list inside the existing one.
Learn the HTML5 language in this tutorial series. These tutorials are designed for new programmers to provide them thorough knowledge of full stack web development.