With the growing interest in HTML 5 coding many browser manufactures are preparing HTML 5 compatible browsers, currently only Apples Safari is fully HTML 5 ready, Mozilla Firefox 3.5 “supports” the new coding but is not 100% compatible as of yet and as for our friends over at Microsoft their internet explorer still does not reconize HTML 5 reference as of yet.
It shouldn’t be long before all browsers are 100% compatible as HTML 5 has been designed to make things easier for browsers to render a web page, powerful applications, rich multimedia, stunning designs are all on their way to a computer screen near you.
HTML5 is fast approaching and getting wide spread usage. Most are familiar with the new tags like header, section and footer and everybody is aware of the new video tags thanks to Apple vs Adobe. However, there is a lot more to HTML5 those just those two aspects.
I want to focus on localStorage() this time. localStorage is a client-side key-value database, meaning it is stored in the users browser. This means the users data is saved on their machine inside their browser. This also means that their data is only available to them when on that machine and in that browser. Remember that localStorage is per browser not per computer.
Browser support is always a huge topic when discussing new html5 or even css3 aspects. This is due to such a wide spread of support from the big browsers right now. In the case of localStorage, it is supported by Safari 4+, Mobile Safari (iPhone/iPad), Firefox 3.5+, Internet Explorer 8+ and Chrome 4+. This only leaves out Opera who currently does not support this storage. Depending on your target audience browser support may be an issue for you.
HTML5 localStorage() is a four part series of articles where I will show you how to create a simple html5 time tracking web app using localStorage as the sole database. The series will walk you through the basics of localStorage to advanced techniques to leverage the power of this new html5 database. We won’t stop at just the functionality of the app but in part four we will cover styling the app with html5 and css3 to create an iPhone(ish) web app.
Here is a quick example of what the javascript looks like to access localStorage();
if (typeof(localStorage) == ‘undefined’ ) {
alert(‘Your browser does not support HTML5 localStorage. Try upgrading.’);
} else {
try {
localStorage.setItem(“name”, “Hello World!”); //saves to the database, “key”, “value”
} catch (e) {
if (e == QUOTA_EXCEEDED_ERR) {
alert(‘Quota exceeded!’); //data wasn’t successfully saved due to quota exceed so throw an error
}
}
document.write(localStorage.getItem(“name”)); //Hello World!
localStorage.removeItem(“name”); //deletes the matching item from the database
}
In the code snippet above we are doing several things including checking if your browser supports localStorage, saving a new item to the database, retrieving that item and displaying it and then removing the item. The above is your typical Hello World example but shows you just how easy it is to use. The time tracking app we will create will be storing a unique id as the key and joining multiple values into one string, as localStorage only supports storing of strings. I will be making the source code available at the end of each article along with the full source and the working app at the end of the series, which you can follow here.
” Written for HTML5Tutorial.net by James Fleeting, a web designer and developer obsessed with the future of the web working at Crane | West Advertising Agency in Wichita Falls, Texas. “
We’ve discussed a lot of new elements here at HTML5Doctor, but the article element has somehow escaped the microscope… until now! article is one of the new sectioning elements. It is often confused with section and div but don’t worry we’ll explain the difference between them.
What the spec says
Thankfully, the spec is short and sweet:
The article element represents a component of a page that consists of a self-contained composition in a document, page, application, or site and that is intended to be independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content.
W3C Specification
In addition to it’s content, an element typically has a heading (often in a header element), and sometimes a footer. The easiest way to conceptualise is to think of it’s use in a weblog, as mentioned in the spec’s examples “a blog entry” and “user-submitted comments.” Here at HTML5 Doctor, we wrap each weblog entry inside an element. We also use on ‘static’ content pages, like the About and Contact pages, as can be used for “any other independent item of content.” The tricky part is, what exactly is an independent item of content?
The smell test for going independent
An independent piece of content, one suitable for putting in an element, is content that makes sense on it’s own. This yardstick is up to your interpretation, but an easy smell test is would this make sense in an RSS feed? Of course weblog articles and static pages would make sense in a feed reader, and some sites have weblog comment feeds. On the other hand, a feed with each paragraph of this article as a separate post wouldn’t be very useful. The key point here is that the content has to make sense independent of its context, i.e. when all the surrounding content is stripped away.
Examples of in use
A bare-bones
We only have a title and some content, but it’s enough to make sense on it’s own (assume there’s a lot more content about apples
Apple
The apple is the pomaceous fruit of the apple tree…
…
A weblog-style
A published date leads us to add a , and there’s also content that would be suitable in a
Apple
Published:
The apple is the pomaceous fruit of the apple tree…
…
An with comments as nested s
This example shows a weblog entry with comments. Each comment can be marked up as an within the containing .
Apple
Published:
The apple is the pomaceous fruit of the apple tree…
…
Comments
Posted by: Apple Lover
I love apples, my favourite kind are Granny Smiths
Posted by: Oranges are king
Urgh, apples!? you should write about ORANGES instead!!1!
An with s
You can use the element to split the article into logical groups of content with headings:
Apple varieties
The apple is the pomaceous fruit of the apple tree…
Red Delicious
These bright red apples are the most common found in many supermarkets…
Granny Smith
These juicy, green apples make a great filling for apple pies…
A containing s
Where appropriate a element can contain elements. We already saw this in the comment section example above, and other common examples are the homepage or category pages of a weblog:
Articles on: Fruit
Apple
The apple is the pomaceous fruit of the apple tree…
Orange
The orange is a hybrid of ancient cultivated origin, possibly between pomelo and tangerine…
Banana
Bananas come in a variety of sizes and colors when ripe, including yellow, purple, and red…
Using for a widget
The specification also mentions that an interactive widget can also be an . The example below shows how the markup might look for an embedded widget from somewhere like Widgetbox.
My Fruit Spinner
The pubdate attribute
You may have noticed the pubdate attribute in these examples. pubdate is an optional boolean attribute that may be added to one time element within the . If present it indicates that the
pubdate
pubdate=”pubdate”
You could think of these as HTML and XHTML-style — the end result is the same so use the style you like. Note that pubdate applies only to the parent element, or to the document as a whole.
The difference between and
There’s been a lot of confusion over the difference (or perceived lack of a difference) between the and elements in HTML5. The element is a specialised kind of ; it has a more specific semantic meaning than in that it is an independent, self-contained block of related content. We could use , but using gives more semantic meaning to the content.
By contrast is only a block of related content, and
is only a block of content. Also as mentioned above the pubdate attribute doesn’t apply to . To decide which of these three elements is appropriate, choose the first suitable option:
1. Would the content would make sense on it’s own in a feed reader? If so use
2. Is the content related? If so use
3. Finally if there’s no semantic relationship use
Dr Bruce has written HTML5 s and s, what’s the difference?, so we recommend reading that if you are still fuzzy on when to use .
Summary
Hopefully this post has given you some insight into the correct use of the element. Do you have any other examples that you can share for using in your HTML5 markup?
I’m also keen to hear your thoughts on the confusion between the and elements. Do you think the distinction between the two is clear?
This article was first submitted on www.html5doctor.com
What would the WWW be without links? Links represent the essence of the WWW, linking millions and millions of pages from around the world together…what are we waiting for? Lets start linking!
Links are created using the <a> tag. The <a> tag requires a href attribute which specifies the target URL it should follow when the link is clicked on. Here is a text link that goes to Yahoo:
The above link links to an external document on the WWW. You can easily create links that link to a local document within your site. Just supply the complete path of the target document, with the current document the starting point. Here’s are some examples:
The first link assumes that section3.htm is in the same directory as the current page, whereas the second assumes section3.htm is stored in the directory “subdir”, a sub directory of the current directory.
Adding Image links
Once you understand how to create links in general, creating image links are a snap. Just substitute the text with the <img> tag. Why don’t we let our paper boy take us to Yahoo when clicked on?
Notice the blue line surrounding the image- this is how an image link appears by default. We can easily get rid of the border by setting the border attribute to 0:
The first thing most beginner webmasters want to do with their web page is to add a background to it, whether it be a background color or image. By default, a document with no background appears gray (or white in newer browsers) in the background. That’s easy to fix. Lets begin by adding a background color. To add a splash of color to your document, add the following code inside the tag itself:
where xxxxxx is the hex code for the color you want. “Why can’t I just use the name of the color”, you ask. Well, ask the creators of HTML that question! Anyhow, here’s a small chart of the hex code for some common colors:
black
#000000
white
#FFFFFF
blue
#0000FF
yellow
#FFFF00
red
#FF0000
green
#008000
lime
#00FF00
silver
#C0C0C0
For example, the below gives our document a background of black:
Now that you know how to give your doc a background color, lets move on to learn how to give it an image as well. For illustration, lets first bring in a nice image we’ll be using:
To utilize the above image as the background, use the following syntax:
Many authors like to give their document BOTH a background color, and an image as well. This way, while the image has yet to come through from the server, surfers will see a background color in the meantime:
Now that you have a vague idea of what tags are, you’re ready to learn about the basic tags that make up a basic web page. Are you ready to create your very first web page?
The below lists the complete syntax used in creating a very basic web page, with only the text “Welcome to my first homepage” on it:
Welcome to my first homepage!
Go ahead. Open up your text editor, type the above, and see what it looks like in your browser. You’ll see a blank page with the title “Welcome!” on the title bar, and the simple line of text “Welcome to my first homepage” sitting in the main browser area. The parts in bold are the tags used in this page. Notice their structure and position in the document. Lets now describe their role in a document:
Specifies that this is an HTML document. All html documents begin and end with this tag.
Creates a container for meta information, such as the document’s title, keywords and description info for search engine crawling, etc to be added to the document.
Creates a “title” for the document. Anything you add inside this tag, the browser displays it in the title bar.
Creates a container for the document’s content (text, images etc). This is where all the “viewable” content will be inserted.
99% of web documents on the web, small or large, simple or complicated, all contain at least the above tags. They make up the framework of any document. Take another look at the definition of the
tag- most of the action in html will take place inside it, since the tag contains all of the document’s viewable content.
HTML is a markup language used by all web browsers in determining how to display a web page. It consists of simple text (content), plus tags. Tags represents the essence of HTML; whenever you want to make your text bold, insert an image or table, add music to your page, you use tags. Tags are special codes that wrap around various content to affect the content. Lets see an example of a tag:
The above is the bold tag, and when wrapped around text, makes the text appear bold!
This text is bold!
Notice that there is a tag attached at the end of the content. This is the bold tag’s closing tag, and it tells the browser- “Hay, I want bold text only up to that point!” Most tags have a complimentary closing tag, as you will see as we trottle along.
HTML is essentially a bunch of tags with even more text. Once you learn the syntax of these tags, you can call yourself a HTML expert!