Monday 21 April 2014

HTML5 How To's


How To's
The following How To's show some basic steps for some of the more common tasks in HTML.
Frame a Basic Web Page
The following code can be used to frame a basic web page and includes the DOCTYPE, character encoding, title, and some content:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>title goes here</title> </head> <body> <p>content goes here</p> </body> </html>
HTML5 has simplified the DOCTYPE and character encoding, so a basic web page for HTML5 would look like the following:
<!DOCTYPE html> <html> <head> <title>title goes here</title> </head> <body> <p>content goes here</p> </body> </html>
Create a New Paragraph
The following example uses paragraph tags to start a new paragraph. Here are the steps:
1. Type <p> to start a new paragraph
2. Type the desired text
3. Type 
</p> to close the paragraph
<p>paragraph text</p>
This produces the following result:
paragraph text
Add a Line Break
1. Type <br /> in front of the line of text where the new line should appear
2. Type additional 
<br /> wherever a line break is desired
<p>paragraph<br />text</p>
This produces the following result:
paragraph
text
Insert a Blank Space
Blank spaces can be inserted with a line of text to indent or add emphasis to the text.
1. Type &nbsp; in the text where the blank space should appear
2. Type additional 
&nbsp; entities to add another space
<p>some&nbsp;&nbsp;text</p>
This produces the following result:
some   text
Insert Preformatted Text
Preformatted text can be inserted by using the <pre> and </pre> tags. This will allow the preservation of line breaks and spaces within the text.
1. Type <pre> above the text to keep intact
2. Type 
</pre> below the text
<pre>preformatted text line 3 with spaces </pre>
This produces the following result:
preformatted text line 3 with spaces
Create a New Heading
Headings can be used to help clarify information on a page, organize text, or create visual structure. There are six heading levels ranging from level 1 (<h1>), the largest, to level 6 (<h6>), the smallest. Here are the steps to insert a level 1 heading:
1. Type <h1> to start a new heading
2. Type the desired text for the heading
3. Type 
</h1> to close the heading
<h1>heading text</h1> <p>paragraph text</p>
This produces the following result:
heading text
paragraph text
Insert a Comment
Comments can be used to add notes within an HTML document, but do not display on the web page.
1. Type <!-- to start a new comment
2. Type the desired text
3. Type 
--> to close the comment
<!-- comment text --> <p>paragraph text</p>
This produces the following result:
paragraph text
Insert a Bulleted List
Use a bulleted list to set a list of items apart from the rest of the page of text.
1. Type <ul> above the text you want to turn into a bulleted list
2. Type 
<li> in front of each item in the list
3. Type 
</li> at the end of each item in the list
4. Type 
</ul> after the list text
<ul> <li>item 1</li> <li>item 2</li> </ul>
This produces the following result:
§  item 1
§  item 2

HTML5 Examples


HTML Examples
The following examples show some of the more commonly used tags in HTML.
Heading Elements
Headings are defined in HTML documents using the <h1> - <h6> tags.<h1> is the most significant heading, and<h6> is the least significant.
<h1>Heading 1</h1> <h2>Heading 2</h2> <h3>Heading 3</h3> <h4>Heading 4</h4> <h5>Heading 5</h5> <h6>Heading 6</h6>
This produces the following result:
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6


Headings may be styled using CSS to vary the font size, weight, color, etc.
Text Elements
Various tags define text elements and their styles. Here are few example:
<p>Paragraph Text</p> (line <br /> break) <hr /> (horizontal rule) <em>Emphasized Text</em>
<strong>Strong Text</strong> <pre>Preformatted Text</pre> <code>Computer Code</code>
This produces the following result:
Paragraph Text
(line
break)


(horizontal rule)
Emphasized Text
Strong Text

Preformatted Text
Computer Code
Lists
HTML supports two common types of lists, unordered (<ul>) and ordered (<ol>). By default, unordered list items are marked by a bullet (•) character, and ordered list items are marked by a number.
To define the list items, use the <li>tag.
<ul> <li>First Item</li> <li>Second Item</li> <li>Third Item</li> </ul> <ol> <li>First Item</li> <li>Second Item</li> <li>Third Item</li> </ol>
This produces the following result:
  • First Item
  • Second Item
  • Third Item
  1. First Item
  2. Second Item
  3. Third Item
Tables
Tables are defined with the <table>tag.
A table is divided into rows (with the<tr> tag), and each row is divided into data cells (with the <td> tag).
Optional table headers can be added by specifying the <th> tag.
<table border="1"> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>row 1, cell 1</td> <td>row 1, cell 2</td> </tr> <tr> <td>row 2, cell 1</td> <td>row 2, cell 2</td> </tr> </table>
This produces the following result:
Header 1
Header 2
row 1, cell 1
row 1, cell 2
row 2, cell 1
row 2, cell 2
Forms
HTML Forms are used to select different kinds of user input and pass that input to a server.
A form can contain input elements like text fields, checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists, textarea, fieldset, legend, and label elements.
The <form> tag is used to create an HTML form:
<form> First name: <input type="text" name="fname" /> Last name: <input type="text" name="lname" /> Password: <input type="password" name="pw" /> <input type="radio" name="otype" value="rent" />Rent <input type="radio" name="otype" value="own" />Own <input type="checkbox" name="opts" value="ac" />A/C <input type="checkbox" name="opts" value="pool" />Pool <input type="submit" value="Submit" /> </form>
This produces the following result:
Top of Form
First name: Last name: Password: 
Rent
Own

A/C
Pool
Bottom of Form
HTML Links
Links are defined in HTML documents using the <a> tag. The text between the opening and closing tags is styled as a link and clicking on the link forwards to the referenced link.
<a href="http://www.ebay.com"></a>

HTML Images

Images are defined in HTML documents using the <img> tag. It is important to note that images are not actually inserted into the HTML document, but instead are referenced using a link.
<img src="smiley.gif" alt="Smiley face" />
This produces the following result:

HTML5 Elements / APIs...


HTML5 Elements / APIs
HTML5 is the next generation of HTML and will become the new standard for HTML, XHTML, and the HTML DOM. In addition, HTML5 adds many new features.
Tag
Description
<!--...-->
Defines a comment
<!DOCTYPE> 
Defines the document type
<a>
Defines a hyperlink
<abbr>
Defines an abbreviation
<acronym>
Not supported in HTML5
<address>
Defines an address element
<applet>
Not supported in HTML5
<area>
Defines an area inside an image map
<article>
Defines an article
<aside>
Defines content aside from the page content
<audio>
Defines sound content
<b>
Defines bold text
<base>
Defines a base URL for all the links in a page
<basefont>
Not supported in HTML5
<bdi>
Defines a span of text that is isolated from its surroundings for the purposes of bidirectional text formatting
<bdo>
Defines the direction of text display
<big>
Not supported in HTML5
<blockquote>
Defines a long quotation
<body>
Defines the body element
<br>
Inserts a single line break
<button>
Defines a push button
<canvas>
Defines graphics
<caption>
Defines a table caption
<center>
Not supported in HTML5
<cite>
Defines a citation
<code>
Defines computer code text
<col>
Defines attributes for table columns 
<colgroup>
Defines groups of table columns
<command>
Defines a command button
<datalist>
Defines a dropdown list
<dd>
Defines a definition description
<del>
Defines deleted text
<details>
Defines details of an element
<dfn>
Defines a definition term
<dir>
Not supported in HTML5
<div>
Defines a section in a document
<dl>
Defines a definition list
<dt>
Defines a definition term
<em>
Defines emphasized text 
<embed>
Defines external interactive content or plugin
<fieldset>
Defines a fieldset
<figcaption>
Defines the caption of a figure element
<figure>
Defines a group of media content, and their caption
<font>
Not supported in HTML5
<footer>
Defines a footer for a section or page
<form>
Defines a form 
<frame>
Not supported in HTML5
<frameset>
Not supported in HTML5
<h1> to <h6>
Defines header 1 to header 6
<head>
Defines information about the document
<header>
Defines a header for a section or page
<hgroup>
Defines information about a section in a document
<hr>
Defines a horizontal rule
<html>
Defines an html document
<i>
Defines italic text
<iframe>
Defines an inline sub window (frame)
<img>
Defines an image
<input>
Defines an input field
<ins>
Defines inserted text
<keygen>
Defines a generated key in a form
<kbd>
Defines keyboard text
<label>
Defines a label for a form control
<legend>
Defines a title in a fieldset
<li>
Defines a list item
<link>
Defines a resource reference
<map>
Defines an image map 
<mark>
Defines marked text
<menu>
Defines a menu list
<meta>
Defines meta information
<meter>
Defines measurement within a predefined range
<nav>
Defines navigation links
<noframes>
Not supported in HTML5
<noscript>
Defines a noscript section
<object>
Defines an embedded object
<ol>
Defines an ordered list
<optgroup>
Defines an option group
<option>
Defines an option in a drop-down list
<output>
Defines some types of output
<p>
Defines a paragraph
<param>
Defines a parameter for an object
<pre>
Defines preformatted text
<progress>
Defines progress of a task of any kind
<q>
Defines a short quotation
<rp>
Used in ruby annotations to define what to show browsers that to not support the ruby element.
<rt>
Defines explanation to ruby annotations.
<ruby>
Defines ruby annotations.
<s>
Represents content that is no longer accurate or no longer relevant
<samp>
Defines sample computer code
<script>
Defines a script
<section>
Defines a section
<select>
Defines a selectable list
<small>
Defines small text
<source>
Defines media resources
<span>
Defines a section in a document
<strike>
Not supported in HTML5
<strong>
Defines strong text
<style>
Defines a style definition
<sub>
Defines subscripted text
<summary>
Defines the header of a "detail" element
<sup>
Defines superscripted text
<table>
Defines a table
<tbody>
Defines a table body
<td>
Defines a table cell
<textarea>
Defines a text area
<tfoot>
Defines a table footer
<th>
Defines a table header
<thead>
Defines a table header
<time>
Defines a date/time
<title>
Defines the document title
<tr>
Defines a table row
<track>
Enables supplementary media tracks such as subtitle tracks and caption tracks to be specified for audio and video elements.
<tt>
Not supported in HTML5
<u>
Defines a span of text offset from its surrounding content without conveying any extra emphasis or importance
<ul>
Defines an unordered list
<var>
Defines a variable
<video>
Defines a video
<wbr>
Defines a possible line-break
<xmp>
Not supported in HTML5


HTML5 Integrated APIs

HTML5 has incorporated several new APIs, including:
§  Video and Audio API
§  Inline Editing API
§  Offline Application API
§  History API
§  Web Protocol API
§  Drag & Drop API

HTML5 Associated APIs

HTML5 has several new associated APIs, including:
§  Geolocation API
§  2D Canvas Drawing API
§  Local Storage API
§  Web Workers API
§  Web Sockets API
§  Messaging API