LILLYROBOT.COM |
HTML 5 is the newer version of HTML. It has been updated with several new elements and some of the old elements from html 4.01 are being phased out.
The DOCTYPE declaration <!DOCTYPE html> in HTML5 is simple compared to HTML 4.01. It tells the browser which version of HTML you are using.
The following tags have also been simplified:
In the older version of HTML the <div></div> tags were used with the id attribute to create sections for the header, navigation, content and footer. e.g. <div id="header">. Now with HTML5 we can avoid the div tags and use the more meaningful tags.
The header element <header> </header> does exactly what it says. A header is added at the top of the document. It can also be added to sections and articles.
<header>
<h2>My Header</h2>
</header>
Displays
The nav element <nav> </nav> is used when we want to add links, so our viewers can navigate to other pages or to different parts of the the same webpage.
Displays
To display each link in a new line we use the display:block property of CSS.
Displays
The section element <section></section> reperesents a generic document. It is used in general with contents that are related to each other. You can have one or more articles inside the section or you can have a section inside an article; you can also use the headings h1 to h6 to help you structure the document.
<section>
<h1>Travel to Europe</h1>
<article>
<h2>France</h2>
<p>The best place to go...</p>
<article>
<article>
<h2>Italy</h2>
<p> The best place to go...</p>
</article>
</section>
Displays
The best place to go...
The best place to go...
The article element <article></article> is used when you have a piece of content that is independent from the rest of the content on the webpage. This could be a forum post, newspaper article, a blog entry or a piece of article you have written e.g. best restaurants.
<article>
<h2>Curry Dish </h2>
<p>
Today, I have decided to make a hot curry dish with loads of...
</p>
</article>
<article>
<h2>Safari Trip</h2>
<p>
The safari trip will start very early in the morning at...
</p>
</article>
Displays
Today, I have decided to make a hot curry dish with loads of...
The safari trip will start very early in the morning at...
The aside element <aside></aside> is used when you want to add information that is indirectly related to the content around the aside element e.g pull out quotes from an article.
Displays
In this section we are going to look at the mediterranean history on almonds...
The footer element <footer></footer> contains information such as the author, copyright, etc. The footer is placed at the end of the document. You can also add a footer to any of your articles and sections.
Displays
Have a look at the example below on the layout of a web page, using the above semantics.
Element | Description |
---|---|
<figure> | groups embedded content such as images or diagrams with <figcaption> |
<figcaption> | the caption gives an explanation of the embedded content such as an image or diagram |
<time> | Defines a date/time (represents time on a 24 hour clock). |
<hrgroup> | Groups the heading tags <h1> to <h6>. |
<mark> | Defines marked/highlighted text. |
<details> | The details element is used to hide or view additional details from the user. |
<datalist> | Specifies a list of pre-defined options, each one is inside an option element <option>. |
<address> | Specifies contact information about the author of the article/document. |
Attributes | Description |
---|---|
autocomplete | The form's autocomplete attribute specifies if the form should have the autocomplete on or off. If on then it will autocomplete the form and if off then the user completes the form. |
novalidate | The data in the form field is not validated when the form is sbumitted. |
The required attribute is used when you want the user to fill in the field before they submit the form.
Displays
Click the Send button and see what happens.
Displays a brief hint to help the user understand what data should be entered inside the field.
Displays
The pattern attribute with the predefined regular expression checks that the correct data format is entered inside the field.
It can be used with text, url, search, tele, email and password input type.
Displays
The Course input field must contain 5 numbers from 0 to 9.
The Name input field must contain 10 characters in capital.
The list attribute works with the datalist element. The datalist is a list of options.
The list attribute allows the user to input one of the options into the input field.
The id attribute of the datalist must have the same name as the list attribute.
Displays
The readonly attribute is similar to the disabled attribute; it does not allow the user to enter data into the input field. The only difference is that when the form is submitted the disabled attribute value is not submitted.
Displays
The Job Refs text box is read only so you will not able to enter or delete any text. Why don't you try it!
Attributes | Description |
---|---|
autocomplete | The autocomplete attribute specifies if the input field should have the autocomplete on or off. If on, it will autocomplete
the field
and if off then the user will have to complete the field. It can be used with text, url, search, tel, color, datepickers and password input type. |
step | The step attribute is used for the accurancy of data collection; it is used with an input type such as the number,
range or time. The min and max attribute can also be used along with the step attribute. |
autofocus | The autofocus attribute is used to automatically focus on an input element, when the page loads. |
formaction | The formaction attribute specifies the URL page that the data is to be sent to when the form is submitted. It can only be used with submit and image. The formaction attribute overides the form's action attribute. |
formenctype | The formenctype attributes specifies how the form data should be encoded. It can only be used with submit and image. |
formmethod | The formmethod attribute specifies the HTTP or URL method of sending data to the server. It can only be used with submit and image type. The formmethod attribute overides the form's method attribute. |
formnovalidate | The formnovalidate attribute specifies which input element is not to be validated when form is submitted. It overides the novalidate attribute of the form and is used with the submit button. |
formtarget | The formtarget attribute specifies the window page where the form results are to be displayed when the form is submitted. It overides the target attribute of the form and is used with the submit and image type. |
min and max | The min and max specifies a minimum and maximum value of an input field. It is used with number, range, date, datetime, datetime-local, month, time and week input type. |
The search input type is used as a search field.
Displays
The color input type lets the user pick a color from the color picker.
Note: Does not work in all browsers.
Displays
The date input type is used for entering a date by the user.
Note: Does not work in all browsers.
Displays
Input TYPE | Description |
---|---|
<input type="email"> | The input email field is used for entering an email address. |
<input type="month"> | The input month field is used for entering a month. |
<input type="number"> | The input number field is used for entering a number - the min and max attributes are used to specify the min and max numbers allowed. |
<input type="tel"> | The input tel field is used for entering a telephone number. |
<input type="range"> | The input range displays a slider control - the min and max attributes is used to specify the min and max ranges. |
<input type="time"> | The input time lets the user select a time. |
<input type="week"> | The input week lets the user select a week and year. |
<input type="datetime"> | The input datetime field is for entering a date and time. |
<input type="datetime-local"> | The input datetime-local field is for entering a date and time - it omits the time zone. |
<input type="datetime-local"> | The input datetime-local field is for entering a date and time - it omits the time zone. |
The <canvas> element is used with JavaScript for drawing graphics.
Inside the start canvas tag, we have the width and height attribute, which sizes the canvas; it also has an id attribute, which refers to the JavaScript codes.
You can add a border to an empty canvas.
Note: The id attribute is canvas1.
The coding for JavaScript goes inside the <script></script> tags.
document.getElementById("canvas1")
We are instructing this method to find our id <canvas> called canvas1.
getContext(2d)
This method returns the drawing context; the parameter passed is "2d", which is the dimension. It is a built in HTML object, with all the drawing properties and methods.
fillStyle This property sets the colour to fill the drawing.
fillRect (left,top width,height)
This method draws a filled rectangle. The x,y are the coordinates. If the values for left and top are (0,0) then the drawing starts at the top left-hand corner.
Now let us see the big picture using the above properties and methods.
Note: The second canvas fillRect has been changed to fillRect(40,40,200,100).
Displays
fillRect(0,0,200,100)
Displays
fillRect(40,40,200,100)
There are several properties and methods you can use on your canvas, which are not covered here. However, have a look at the examples below, where we have added a rectangle and some text.
Displays
Displays
We can draw any shape using the beginPath() and closePath() methods.
Displays
Below is a table showing some of the properties and methods of the canvas.
PROPERTY |
---|
Text |
font - sets the font style e.g. font=" 20 Arial" |
textAlign - sets the alignment of the text e.g. textAlign="left" or "top, middle, alphabetic, ideographic, bottom" | textBaseline - sets the baseline where text sits e.g textBaseline="hanging" or "start, end, right, center" |
Colours, Styles and Shadows |
strokeStyle - sets the outline color for the shape e.g. strokeStyle="red" the default colour is black |
shadowColor - sets a shadow colour e.g shadowColor="blue" |
shadowBlur - sets a blurred shadow e.g shadowBlur=10 the level of the blur can be increased or decreased |
shadowOffsetX - sets or returns the horizontal of a shadow from the shape e.g. shadowOffsetX=30 the value can be positive or negative |
shadowOffsetY - sets or returns the vertical distance of a shadow from the shape e.g. shadowOffsetY=30 the value can be positive or negative |
METHOD |
---|
Rectangle |
strokeRect() - draws a rectangle e.g strokeRect(10,10,200,100) |
fillRect() - fills the rectangle e.g fillRect(10,10,200,100) |
Text |
strokeText() - draws text e.g strokeText("Hello World", 20,40) | Image |
drawImage() - draws an image |
Transformation |
rotate() - rotates the shape at an angle e.g. rotate(10*Math.PI/180) means rotated by 10 degrees |
scale() - scales the drawing by making it bigger or smaller e.g. scale(30) |
SVG stands for Scalable Vector Graphics. It is a language for describing 2D-graphics in XML, which stands for eXtensible Markup Language.
It is easeir to draw shapes using the SVG graphics. We use the <svg> element with the width and height.
Displays
we use the <circle> element for a circle; the cx and cy are the x and y coordinates of the center of the circle, and the r is the radius of the circle. You can fill the circle with any colour of your choice.
Displays
Displays
x1 and y1 - the start of the line on the x and y axis
x2 and y2 - the end of the line on the x and y axis
Displays
Syntax <video src="video.mp4"></video>
The video element includes width and height attributes; it also has controls attribute that allows the user to stop, pause, play and control the volume.
<video src="video.mp4" width="300" height="50" controls ></video>
If you include an autoplay attribute then the video comes on automatically, which can be annoying.
<video
src="video.mp4" width="300" height="50" controls autoplay>
</video>
The loop attribute can be included if you want the video to be played more than once or infinitively.
<video
src="video.mp4" width="300" height="50" controls autoplay loop>
</video>
The poster attribute is used if you want an image to be shown on the screen whilst the video is being loaded. Otherwise, you just see the frame of the video.
<video
src="video.mp4" width="300" height="50" controls poster="pic.jpg">
</video>
The muted attribute is used if you do not want the video to play. It takes a boolean value true or false.
HTML5 supports mp4, webM and ogg video formats. All 3 video formats should be included incase the user's browser does does not support one of them - the <source> element is used.
<video
src="myVideo.mp4" width="300" height="50" controls" >
< source src="myVideo.webm" type="video/webm">
< source src="myVideo.ogg" type="video/ogg">
</video>
In HTML5 the <audio> element supports mp3, wav and ogg formats. All 3 audio formats should be included incase the user's browser does does not support one of them - the <source> element is used.
<audio
width="300" height="50" controls" >
< source src="myAudio.wav" type="audio/wav">
< source src="myAudio.mp3" type="audio/mp4">
< source src="myAudio.ogg" type="audio/ogg">
</audio>
Set the attribute draggable to "true" inside the element, which is going to be dragged and dropped.
<img src="images/star.jpg" width="200" height="100" alt="star" id="img1" draggable="true"/>
Step 2:
Add the attribute ondragstart inside the element, which calls the function
drag (this, e), which will start the drag operation.
<img src=images/star.jpg" width="60" height="30" alt="star" id="img1" draggable="true" ondragstart=drag(this,e)/>
Using the data transfer object, we set and get data objects that we want to drag with the help of javascript.
<script>
function drag(target,e)
{
e.dataTransfer.setData('Text',target.id);}
</script>
Step 3:
The ondrop attribute calls on the function drop(this,e), which will make the drop. It listens to 3 events before making the drop:
The image drop is going to be made inside the div box.
<div id="boxA">
onedragenter="return false"
ondragover="return false"
ondrop="drop(this,event)"
</div>
<script>
function drop(target,e)
{
var id = e.dataTransfer.getData('Text');
target.appendChild(document.getElementById(id));
e.preventDefault();
}
</script>
Now drop the star inside the box.