Chapter 2.part 2
Chapter 2.part 2
Introduction to HTML5
Structure and Formatting
HTML Forms
The best known form on the web is probably the search box that
sits right in the middle of Google's homepage
Text, such as
• Text input (single-line)
• Password
• Text area (multi-line)
Choices, such as
• Radio buttons
• Checkboxes
• Drop-down lists
Buttons
• Submit button
• Clear button
• Reset button
• File upload
Text – single line
<input> tag
• The <input> element is used to
create several different form
controls.
• The value of the type attribute
determines what kind of input
they will be creating.
Notice that the value of the "First name" field will not be submitted, because the input element
does not have a name attribute
Password
<input> tag
• type="submit"
1. The submit button is used to send a
form to the server/form-handler (this
is its default behaviour/action)
• The form-handler is specified in
the form's action attribute
• If action attribute is not defined in
the form tag, then by default the
form handler is your current page.
This explains the refresh behavior
of the page you notice when click
the submit button.
• users can click on either the form control or the label to select. The expanded
clickable area makes the form easier to use. The position of the label is very
important. If users do not know where to enter information or what
information to enter, they are less likely to use the form correctly.
2. Be kept separate from the form control and use the for attribute to indicate
which form control it is a label for.
The for attribute states which form control the label belongs to
The value of the for attribute matches that of the id attribute on the form control it is
labelling
Grouping form elements
There
are many reasons why you might want to add an image to a
web page:
You might want to include a logo, photograph, illustration, diagram, or
chart.
A picture can say a thousand words, and great images help make the
difference between an average-looking site and a really engaging one.
The right size: If the image is smaller than the width or height
that you have specified, the image can be distorted and
stretched.
But, you can use the width and height attributes to specify the image size. Here, the
values are specified in pixels by default:
Toensure most people can play your video content, it is considered best
practice to use the HTML5 <video> element for browsers that support it
Key issues
You can also use multiple <source> elements to specify that the video is available in
different formats.
Type: You should use this attribute to tell the browser what format the video is.
Otherwise, it will download some of the video to see if it can play the file (which will take time and
bandwidth)
If the browser does not support the element or the format of video used, it will display
whatever is between the opening and closing tags.
HTML5 Video
Audios
<audio> , <source>
HTML5 Audio
Before HTML5, audio files could only be played in a browser with a plug-in (like
flash).
The HTML5 <audio> element specifies a standard way to embed audio in a
web page.
To play an audio file in HTML, use the <audio> element.
Web supported formats for audio:
<audio>
Adding audio - <audio>
HTML5 introduced the <audio> element to include audio files
in your pages. As with HTML5 video, browsers expect different formats
for the audio.
Src: This attribute specifies the path to the audio file
Controls: This attribute indicates whether the player should display controls.
Autoplay: The presence of this attribute indicates that the audio should start
playing automatically.
Multiple audio source
<source> It is possible to specify more than one audio file using the
element between the opening and closing tags.
Embed Objects
<object> ….. </object>
Embed objects- <object>
An external resource can be embedded
into an HTML document using
<object> </object> tags to define the
resource.
When the resource is an image, it will
be treated much like those specified by
<img> element, otherwise a plugin
may be sought to process the resource.
The <object> element can specify the
resource’s URL to its data attribute, and
the resource type to its type attribute.
The resource type must be a valid MIME
type describing the resource.
Summary
After you define a table, you need to add some rows. Each
row is indicated by a <tr> </tr> pair.
The number of <tr> </tr> pairs define the of table rows.
HTML Tables - <td>
Inside the <tr> </tr> set, you need some table data.
Each table row can consist of a number of table data <td> or
table header <th> tags.
Place the data elements inside the <td> </td> segments
and you’re ready to go.
Table headings - <th>
• <th> element is used just like the <td>
element but its purpose is to represent the
heading for either a column or a row.
1.77 85
1.6 65