learn HTML
Learn HTML.With HTML you can create your own Web site. This tutorial teaches you everything about HTML. This HTML tutorial contains hundreds of HTML examples. HTML is easy to learn - You will enjoy it.
Wednesday, November 2, 2011
HTML5 Tutorial START
HTML5 Tutorial
HTML5 is the next generation of HTML.
This tutorial teaches you about the new features in HTML5.
This tutorial teaches you about the new features in HTML5.
Examples in Each Chapter
With our HTML editor, you can edit the HTML, and click on a button to view the result.Example
<!DOCTYPE HTML><html>
<body>
<video width="320" height="240" controls="controls">
<source src="movie.mp4" type="video/mp4" />
<source src="movie.ogg" type="video/ogg" />
<source src="movie.webm" type="video/webm" />
Your browser does not support the video tag.
</video>
</body>
HTML5 introduction
HTML5 is the next generation of HTML.
What is HTML5?
HTML5 will be the new standard for HTML, XHTML, and the HTML DOM.The previous version of HTML came in 1999. The web has changed a lot since then.
HTML5 is still a work in progress. However, most modern browsers have some HTML5 support.
How Did HTML5 Get Started?
HTML5 is a cooperation between the World Wide Web Consortium (W3C) and the Web Hypertext Application Technology Working Group (WHATWG).WHATWG was working with web forms and applications, and W3C was working with XHTML 2.0. In 2006, they decided to cooperate and create a new version of HTML.
Some rules for HTML5 were established:
- New features should be based on HTML, CSS, DOM, and JavaScript
- Reduce the need for external plugins (like Flash)
- Better error handling
- More markup to replace scripting
- HTML5 should be device independent
- The development process should be visible to the public
New Features
Some of the most interesting new features in HTML5:- The canvas element for drawing
- The video and audio elements for media playback
- Better support for local offline storage
- New content specific elements, like article, footer, header, nav, section
- New form controls, like calendar, date, time, email, url, search
Browser Support
HTML5 is not yet an official standard, and no browsers have full HTML5 support.But all major browsers (Safari, Chrome, Firefox, Opera, Internet Explorer) continue to add new HTML5 features to their latest versions.
HTML5 New Elements
HTML5 New Elements
New Elements in HTML5
The internet has changed a lot since HTML 4.01 became a standard in 1999.Today, some elements in HTML 4.01 are obsolete, never used, or not used the way they were intended to. These elements are deleted or re-written in HTML5.
To better handle today's internet use, HTML5 also includes new elements for better structure, drawing, media content, and better form handling.
New Markup Elements
New elements for better structure:| Tag | Description |
|---|---|
| <article> | Specifies independent, self-contained content, could be a news-article, blog post, forum post, or other articles which can be distributed independently from the rest of the site. |
| <aside> | For content aside from the content it is placed in. The aside content should be related to the surrounding content |
| <bdi> | For text that should not be bound to the text-direction of its parent elements |
| <command> | A button, or a radiobutton, or a checkbox |
| <details> | For describing details about a document, or parts of a document |
| <summary> | A caption, or summary, inside the details element |
| <figure> | For grouping a section of stand-alone content, could be a video |
| <figcaption> | The caption of the figure section |
| <footer> | For a footer of a document or section, could include the name of the author, the date of the document, contact information, or copyright information |
| <header> | For an introduction of a document or section, could include navigation |
| <hgroup> | For a section of headings, using <h1> to <h6>, where the largest is the main heading of the section, and the others are sub-headings |
| <mark> | For text that should be highlighted |
| <meter> | For a measurement, used only if the maximum and minimum values are known |
| <nav> | For a section of navigation |
| <progress> | The state of a work in progress |
| <ruby> | For ruby annotation (Chinese notes or characters) |
| <rt> | For explanation of the ruby annotation |
| <rp> | What to show browsers that do not support the ruby element |
| <section> | For a section in a document. Such as chapters, headers, footers, or any other sections of the document |
| <time> | For defining a time or a date, or both |
| <wbr> | Word break. For defining a line-break opportunity. |
New Media Elements
HTML5 provides a new standard for media content:| Tag | Description |
|---|---|
| <audio> | For multimedia content, sounds, music or other audio streams |
| <video> | For video content, such as a movie clip or other video streams |
| <source> | For media resources for media elements, defined inside video or audio elements |
| <embed> | For embedded content, such as a plug-in |
| <track> | For text tracks used in mediaplayers |
The Canvas Element
The canvas element uses JavaScript to make drawings on a web page.| Tag | Description |
|---|---|
| <canvas> | For making graphics with a script |
New Form Elements
HTML5 offers more form elements, with more functionality:| Tag | Description |
|---|---|
| <datalist> | A list of options for input values |
| <keygen> | Generate keys to authenticate users |
| <output> | For different types of output, such as output written by a script |
New Input Type Attribute Values
Also, the input element's type attribute has many new values, for better input control before sending it to the server:| Type | Description |
|---|---|
| tel | The input value is of type telephone number |
| search | The input field is a search field |
| url | The input value is a URL |
| The input value is one or more email addresses | |
| datetime | The input value is a date and/or time |
| date | The input value is a date |
| month | The input value is a month |
| week | The input value is a week |
| time | The input value is of type time |
| datetime-local | The input value is a local date/time |
| number | The input value is a number |
| range | The input value is a number in a given range |
| color | The input value is a hexadecimal color, like #FF8800 |
| placeholder | Specifies a short hint that describes the expected value of an input field |
HTML5 Video
HTML5 Video
Many modern websites show videos. HTML5 provides a standard for showing them.
Check if your browser supports HTML5 video
Videos on the Web
Until now, there has never been a standard for showing a video or movie on a web page.Today, most videos are shown through a plugin (like flash). However, different browsers may have different plugins.
HTML5 defines a new element which specifies a standard way to include video: the <video> element.
Video Formats
Currently, there are 3 supported video formats for the video element:| Format | IE | Firefox | Opera | Chrome | Safari |
|---|---|---|---|---|---|
| Ogg | No | 3.5+ | 10.5+ | 5.0+ | No |
| MPEG 4 | 9.0+ | No | No | 5.0+ | 3.0+ |
| WebM | No | 4.0+ | 10.6+ | 6.0+ | No |
- Ogg = Ogg files with Theora video codec and Vorbis audio codec
- MPEG4 = MPEG 4 files with H.264 video codec and AAC audio codec
- WebM = WebM files with VP8 video codec and Vorbis audio codec
How It Works
To show a video in HTML5, this is all you need:Example
<video width="320" height="240" controls="controls">
<source src="movie.mp4" type="video/mp4" />
<source src="movie.ogg" type="video/ogg" />
Your browser does not support the video tag.
</video>
<source src="movie.mp4" type="video/mp4" />
<source src="movie.ogg" type="video/ogg" />
Your browser does not support the video tag.
</video>
Try it yourself »
It is also a good idea to always include width and height attributes. If height and width are set, the space required for the video is reserved when the page is loaded. However, without these attributes, the browser does not know the size of the video, and cannot reserve the appropriate space to it. The effect will be that the page layout will change during loading (while the video load).
You should also insert text content between the <video> and </video> tags for browsers that do not support the <video> element.
The <video> element allows multiple <source> elements. <source> elements can link to different video files. The browser will use the first recognized format.
Today, Firefox, Opera, and Chrome support Ogg files. Internet Explorer, Chrome, and Safari support MPEG4 files.
To cover all the major browsers, use two <source> elements: One pointing to an MPEG4 file, and one pointing to an Ogg file.
HTML5 video Tags
| Tag | Description |
|---|---|
| <video> | Defines a video or movie |
| <source> | Defines multiple media resources for media elements, such as <video> and <audio> |
| <track> | Defines text tracks in mediaplayers |
HTML5 Audio
HTML5 Audio
HTML5 provides a standard for playing audio.
Audio on the Web
Until now, there has never been a standard for playing audio on a web page.Today, most audio are played through a plugin (like flash). However, not all browsers have the same plugins.
HTML5 specifies a standard way to include audio, with the audio element.
The audio element can play sound files, or an audio stream.
Audio Formats
Currently, there are 3 main formats for the audio element:| Format | IE 9 | Firefox 3.5 | Opera 10.5 | Chrome 3.0 | Safari 3.0 |
|---|---|---|---|---|---|
| Ogg Vorbis | No | Yes | Yes | Yes | No |
| MP3 | Yes | No | No | Yes | Yes |
| Wav | No | Yes | Yes | Yes | Yes |
How It Works
To play an audio file in HTML5, this is all you need: <audio src="song.ogg" controls="controls">
</audio>
</audio>
Insert content between the <audio> and </audio> tags for browsers that do not support the audio element:
Example
<audio src="song.ogg" controls="controls">
Your browser does not support the audio element.
</audio>
Your browser does not support the audio element.
</audio>
Try it yourself »
To make the audio work in Internet Explorer and Safari, add an audio file of the type MP3.
The audio element allows multiple source elements. Source elements can link to different audio files. The browser will use the first recognized format:
Example
<audio controls="controls">
<source src="song.ogg" type="audio/ogg" />
<source src="song.mp3" type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
<source src="song.ogg" type="audio/ogg" />
<source src="song.mp3" type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
Try it yourself »
HTML5 audio Tags
| Tag | Description |
|---|---|
| <audio> | Defines sound content |
| <source> | Defines multiple media resources for media elements, such as <video> and <audio> |
HTML5 Canvas
HTML5 Canvas
The canvas element is used to draw graphics on a web page.
Your browser does not support the canvas element. What is Canvas?
The HTML5 canvas element uses JavaScript to draw graphics on a web page.A canvas is a rectangular area, and you control every pixel of it.
The canvas element has several methods for drawing paths, boxes, circles, characters, and adding images.
Create a Canvas Element
Add a canvas element to the HTML5 page.Specify the id, width, and height of the element:
<canvas id="myCanvas" width="200" height="100"></canvas>
Draw With JavaScript
The canvas element has no drawing abilities of its own. All drawing must be done inside a JavaScript: <script type="text/javascript">
var c=document.getElementById("myCanvas");
var cxt=c.getContext("2d");
cxt.fillStyle="#FF0000";
cxt.fillRect(0,0,150,75);
</script>
var c=document.getElementById("myCanvas");
var cxt=c.getContext("2d");
cxt.fillStyle="#FF0000";
cxt.fillRect(0,0,150,75);
</script>
Try it yourself »
var c=document.getElementById("myCanvas");
var cxt=c.getContext("2d");
The next two lines draws a red rectangle:
cxt.fillStyle="#FF0000";
cxt.fillRect(0,0,150,75);
cxt.fillRect(0,0,150,75);
Understanding Coordinates
The fillRect method above had the parameters (0,0,150,75).This means: Draw a 150x75 rectangle on the canvas, starting at the top left corner (0,0).
The canvas' X and Y coordinates are used to position drawings on the canvas.
Mouse over the rectangle below to see the coordinates:
X
Y
More Canvas Examples
Below are more examples of drawing on the canvas element:Example - Line
Draw a line by specifying where to start, and where to stop: Your browser does not support the canvas element.
Try it yourself »
Example - Circle
Draw a circle by specifying the size, color, and position: Your browser does not support the canvas element.
Try it yourself »
Example - Gradient
Draw a gradient background with the colors you specify: Your browser does not support the canvas element.
Try it yourself »
Example - Image
Put an image on the canvas:Try it yourself »
HTML5 <canvas> Tag
| Tag | Description |
|---|---|
| <canvas> | Defines graphics |
Subscribe to:
Comments (Atom)