Book Image

HTML5 Boilerplate Web Development

By : Divya Manian
Book Image

HTML5 Boilerplate Web Development

By: Divya Manian

Overview of this book

<p>HTML5 Boilerplate is the number one choice for many web developers to get their projects going. It provides a comprehensive set of starting templates to get your developments going, ensuring you don&rsquo;t forget any important elements of a typical web project while also ensuring you are writing quality code and mark up. Learning how to use this framework of page and code templates will allow you to kick-start your projects quickly without losing out on quality.<br /><br />"HTML5 Boilerplate Web Development" will enable you to build new projects effectively with minimal effort. HTML5 Boilerplate allows you to deploy quality websites successfully and quickly while also ensuring robust cross-browser performance. It takes you through the step-by-step process of creating a website and teaches you to take full advantage of the html layouts provided within HTML5 Boilerplate; be it styles, mark up, or code so you can accomplish your goals.<br /><br />This book will guide you through the process of building a music festival website, as an applicable example, using HTML5 Boilerplate. You will install, set up HTML5 Boilerplate and deploy production sites. <br /><br />First, we will look at how to install HTML5 Boilerplate so you can use it repeatedly to jumpstart your projects, then we will look at structuring your website using the base files. We will use Modernizr and feature detection to dynamically serve different styles and scripts based on support of certain features. We will discover how to best configure our server to provide high performance and security for our website. Finally, we employ the Build Tool to combine files, remove comments and make the site ready for production use.<br /><br />"HTML5 Boilerplate Web Development" offers a well-rounded tutorial in expert web development; not just a starting place for web projects. It develops code snippets, links to further resources for and in addition to makes you understand the nuances of HTML5 Boilerplate.</p>
Table of Contents (15 chapters)
HTML5 Boilerplate Web Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Features of HTML5 Boilerplate


Before we dive deep into the internals of HTML5 Boilerplate, let us look at some of its features that would help you in your next project. HTML5 Boilerplate is available for download from html5boilerplate.com and is licensed under MIT license for use in any free or commercial product. The source code is available on Github's URL, which is github.com/h5bp/html5-boilerplate/.

Cross-browser compatibility

HTML5 Boilerplate comes with a set of files that make it easy to do cross-browser development.

Doctype

The single most significant cause of cross-browser compatibilities is the use of incorrect doctype declarations. By using the HTML5 doctype declaration, you are assured that your browsers will render your site in a standard mode.

Note

If you are interested in learning more about doctypes, I wrote about it in detail at nimbupani.com/the-truth-about-doctypes.html.

Normalize.css

Browsers apply their default styles on elements whose properties you do not specify. The trouble is, the kind of styles that each browser applies are different. However, Normalize.css makes sure that these default styles are consistent across all browsers.

Note

Nicolas Gallagher writes in detail about the motivation behind Normalize.css at necolas.github.com/normalize.css/.

Clearfix

Clearfix has been a popular way of clearing floats. In HTML5 Boilerplate, this has been streamlined to use the micro-clearfix solution, a smaller set of selectors to accomplish the same goal, tested and verified to work on Opera 9 and higher, Safari 4 and higher, IE6 and higher, Firefox 3.5 and higher, and Chrome.

Note

Nicolas Gallagher, the inventor of the micro-clearfix solution, writes more about the choices behind the declarations used at nicolasgallagher.com/micro-clearfix-hack/.

Search box styling

When you set the type of an input element to search, all WebKit browsers like Safari, Chrome, Mobile Safari, and soon, add UI chrome, which is difficult to style. HTML5 Boilerplate comes with a set of styles that normalize the look and feel of the search box across all browsers while also making it easy to style.

Conditional classes

The index.html page comes with a set of classes on the HTML element that makes it easy to tweak your styles for IE versions below 9.

Modernizr

Modernizr is a JavaScript library that tests for the existence of HTML5 technologies and outputs a set of classes on the HTML element based on their presence or absence in the browser that is loading your website. For example, if a browser lacks support for border radius, Modernizr outputs the class no-borderradius , while on browsers that support border radius, it will output the class borderradius . A custom build of Modernizr is included within Boilerplate.

Note

Learn more about developing with Modernizr from their documentation at http://modernizr.com/docs/ and this slide deck at http://www.slideshare.net/michaelenslow/its-a-mod-world-a-practical-guide-to-rocking-modernizr is a good introduction to using Modernizr.

No console.log errors

Oftentimes, when working in modern browsers, you tend to use the console.log function to debug your JavaScript code. How many times have you forgotten to remove them or comment them out in production, only to find them throwing errors in Internet Explorer or other browsers that do not support the use of this function? You can safely use the log function included within the plugin.js file to log statements only in browsers with tools that support it.

Helper classes

Ever had to hide text to show images? How about making extra text available for those who use screen readers or hide from all browsers? HTML5 Boilerplate provides classes for both and more, which have been field-tested to work across edge cases and across all browsers.

Performance optimizations

The .htaccess file includes the best out-of-the-box defaults for caching, which makes your pages load significantly faster when they are served by the Apache Web Server. There are also configuration files for other web servers available to provide similar functionality.

Progressive enhancement

The HTML element has a no-js class that can be used to provide alternative styles for browsers that do not support JavaScript. With Modernizr, this class name is replaced when used in a browser that does support JavaScript to js.

Accessible focus styles

All browsers provide a default focus style for links when clicked. HTML5 Boilerplate ensures that these styles are only applied when the elements are in focus while using keyboard navigation.

Print styles

A good default print stylesheet is something most of us fail to think of when we create web pages. However, HTML5 Boilerplate already does this for you by providing best-performing defaults for print styles.