Like HowStuffWorks on Facebook!

How HTML5 Works

JavaScript as a Central Component

JavaScript is a language specifically designed for the Web. The syntax for writing functions and referencing objects in JavaScript is similar to Java and other object oriented languages. That's where the similarity ends, though. JavaScript is not compiled to create an executable file. Instead, JavaScript associated with a Web page is loaded in your Web browser when that page is loaded, and JavaScript functions are called based on the interactions you have with the page.

You could write the JavaScript code within the HTML code using tags around it, similar to using <style> tags for inline CSS. However, as with CSS styles, the best practice for script code is to put it in a separate file and reference that file from the HTML. This also gives you the flexibility to load the script only if the browser meets certain requirements. In HTML5, your Web browser will also cache JavaScript and other files that support a Web page, so the page will function properly in offline mode, too.

The following is an example of including a JavaScript file named "example.js" which is in a scripts directory one level above the referencing Web page:

<script language="javascript" type="text/javascript"


As with HTML and CSS, JavaScript basics are beyond the scope of this article, and you should pick up a good reference to use while you program. Be sure the reference covers JavaScript for HTML5 so you don't miss these HTML5 enhancements:

  • Reference elements by class name, tag name or a custom query selection.
  • Allocate and use up to 5 MB of local storage on the client system rather than setting and using cookies in the Web browser.
  • Create and use a WebSQL database as part of that local storage.
  • Make use of Web sockets, a new feature that maintains a live client-server connection between your browser and a Web server.
  • Retrieve geolocation data from the client computer via the browser, and use that data for other operations, such as displaying a map of that location.

So far, we've looked at the client-side part of HTML5. In other words, we've looked at the code your Web browser downloads from the Internet and processes on your local computer. HTML5 standards also reach to the other side of that connection, though. Next, let's look at the server-side technology behind HTML5.