HTML & CSS for beginners

Setting up HTML5 Boilerplate: A Guide for Modern Websites

All videos of the tutorial HTML & CSS for beginners
Pascal Bajorat
By Pascal Bajorat Last updated on

If you want to build your first HTML5 and CSS3 pages, you don't have to start from scratch. The HTML5 Boilerplate gives you a ready-made basic framework with proven code, browser fixes, and helpful tools. This guide takes you step by step through the template, from installation to the browser testing phase.

HTML5 boilerplate - the best template for HTML and CSS3 websites

The video is only loaded from YouTube when you play it – data (including your IP address) is then transmitted to YouTube/Google. More in the privacy policy

Introduction

Imagine you're starting a new web project and first have to figure out which files you need, how to design error pages, what the page looks like in old Internet Explorer versions, and how to control search engines. The HTML5 Boilerplate takes this work off your hands. It is a free template under an open-source license that you may also use in commercial projects. It contains best-practice code for HTML, CSS, and JavaScript and ensures that your page looks the same in as many browsers as possible.

The guide is based on a video tutorial that goes through all the components of the template. You will learn which files and folders are included, what they are for, and how to adapt them for your own page.

Key Takeaways

  • The HTML5 Boilerplate is a free open-source template for HTML5 and CSS3 web pages with a focus on cross-browser compatibility.
  • You should download the full version with documentation while you are still getting started, and use the minified version without comments for production projects.
  • Many files, such as crossdomain.xml, humans.txt, or robots.txt, serve special purposes and can be adapted or removed as needed.
  • The index.html file contains conditional comments for older Internet Explorer versions, Chrome Frame, and an optimized script order.
  • With Modernizr you can detect which features a browser supports and provide targeted alternatives via CSS.

Step 1: Find and Download the Template

The starting point is the website css3box.com. There, in the "HTML5 Tools" section, you will find the entry for the HTML5 Boilerplate. Alternatively, you can go directly to the official site html5boilerplate.com. Several download variants are available there.

To begin with, the full version with documentation is recommended. It contains numerous comments that explain why each piece of code is there. Once you are familiar with the structure, you can later use the lean variant without comments.

Setting Up HTML5 Boilerplate: A Guide for Modern Websites
Setting up HTML5 Boilerplate: A Guide for Modern Websites
Setting Up HTML5 Boilerplate: A Guide for Modern Websites

Step 2: Unpack the Files and Understand the Structure

After the download, drag the archive onto your desktop and unpack it. You will immediately see several files and folders. It's best to create your own project directory and copy everything into it before you start working. That way you keep the original state in view.

Setting up HTML5 Boilerplate: A Guide for Modern Websites

Step 3: Test the 404 Error Page

The template contains a ready-made error page called 404.html. Open it in the browser to see what it looks like. Of particular note is the integrated Google search, a widget provided directly by Google. The widget detects the language of the search field automatically. For a German page, you only have to translate the text of the error message. You can freely adapt the code below it to your needs.

Setting up HTML5 Boilerplate: A Guide for Modern Websites
Setting up HTML5 Boilerplate: A Guide for Modern Websites

Step 4: Understand the Icons for Mobile Devices

In the icons folder you will find templates for Apple devices. These include icons in the sizes 57 x 57 pixels for the original iPhone and iPod touch, 114 x 114 pixels for devices with a Retina display, and 72 x 72 pixels for the iPad. You can load these files into your graphics program and replace them with your own symbols. The files stay tied to their names so that the integration in the page is preserved.

Setting up HTML5 Boilerplate: A Guide for Modern Websites

Step 5: Understanding and Securing the crossdomain.xml File

The crossdomain.xml file controls whether AJAX requests across domains are allowed. Normally, scripts may only retrieve files on the same domain. With this file, you can specifically define which external domains may access your content. If you do not need this, it is best to delete the file. Most sections are already commented out in the template, but it is still safer to remove it.

Setting up HTML5 Boilerplate: A Guide for Modern Websites

Step 6: Setting Up the Favicon, humans.txt, and More

The favicon is a small 16 x 16 pixel graphic that appears in the browser tabs. Replace it with your own logo.

The humans.txt file is the counterpart to robots.txt. While the robots.txt is aimed at search engines, the humans.txt informs visitors about the team behind the site. Here you can name developers and designers, list the technologies used such as HTML5, CSS3, Modernizr, or jQuery, and thank supporters.

Setting up HTML5 Boilerplate: A Guide for Modern Websites

Step 7: Using the Folder for Images and the JavaScript Libraries

The folder for images is empty in the template. Whether you call it img or images is up to you; the template does not prescribe a name. Place your graphics there and include them in the HTML code.

In the JavaScript folder, you will find the subfolder libs with the current jQuery library. It comes in two versions: the full, easily readable version and the minified version for live operation. The folder also contains the Modernizr script. The subfolder my-libs is empty and is meant for your own libraries.

Setting up HTML5 Boilerplate: A Guide for Modern Websites

Step 8: Using the Plugins File and Your Own Script File

The plugins.js file is intended for your own jQuery plugins. It already contains an extension of the console.log function. This gives you better error messages, and all messages are logged, which makes troubleshooting much easier.

The script.js file is almost empty. At the top there is a comment section where you can enter the author. You then write your own scripts in this file.

Setting up HTML5 Boilerplate: A Guide for Modern Websites

Step 9: Controlling Search Engines with robots.txt

The robots.txt file determines which areas of a site search engines may crawl. The template refers to the robots.txt generator on the HTML5 CSS3 Toolbox site in the Webmaster Tools section. There you choose whether all pages should be crawled or whether you want to block certain areas.

An example: With User-agent: *, the rule applies to all search engines. With Disallow: /wp-admin/, you block the administration area of a WordPress system. Additionally, you can point to your XML sitemap with Sitemap:.

Setting up HTML5 Boilerplate: A Guide for Modern Websites

Step 10: Creating an XML Sitemap

A sitemap helps search engines find all pages of your website. With a generator such as xml-sitemaps.com, you create it in a few steps. You enter the address of your site, set the frequency of changes and the priority, and start the process. The generator crawls the links automatically.

You save the resulting file as sitemap.xml in the root directory of your project. For each page there is a separate url entry with the address, date of last modification, change frequency, and priority. The home page changes often and therefore gets a higher priority than a contact page.

Setting Up HTML5 Boilerplate: A Guide for Modern Websites

Step 11: Understanding the index.html

The index.html file is the heart of the template. It begins with conditional comments for Internet Explorer. With these, you can create classes such as ie6, ie7, or ie8 on the html element and write separate styles for each version.

Adjust the lang attribute. For a German site, you set de everywhere. Next comes the meta tag for Chrome Frame. It causes Internet Explorer to use the rendering engine of Google Chrome, provided the plugin is installed. After that come the title, description, and author. Keywords are deliberately missing because search engines hardly evaluate them anymore. The viewport declaration ensures on iOS devices that the page adopts the width of the display.

Setting Up HTML5 Boilerplate: A Guide for Modern Websites
Setting up HTML5 Boilerplate: A Guide for Modern Websites
Setting Up HTML5 Boilerplate: A Guide for Modern Websites

Step 12: Including the Stylesheets and Modernizr

After the meta tags, you include the style.css file. The Modernizr script follows next. The container area in the body is a suggestion for structuring a page with a header, main area, and footer. You can rename the container or replace it with your own structure.

Setting up HTML5 Boilerplate: A Guide for Modern Websites
Setting up HTML5 Boilerplate: A Guide for Modern Websites

Step 13: Loading Scripts at the End of the Body

The template includes JavaScript at the end of the body. This way, the visible HTML content is loaded first, before the scripts follow. The visitor therefore sees the page faster, and cannot interact with elements that haven't finished loading yet.

jQuery comes via Google's Content Delivery Network. This network is widely used, so many visitors already have the library in their cache. If the network fails, a small script checks whether jQuery was loaded. If that is not the case, it includes the local file from your project folder.

Next come plugins.js and script.js. At the very end, you will find the place for the Google Analytics code. If you don't need statistics, you simply remove the block. The last section concerns Chrome Frame. It shows users of Internet Explorer 6 a notice about installing the plugin.

Setting up HTML5 Boilerplate: A Guide for Modern Websites

Step 14: Understanding the CSS File

The style.css file begins with a normalization. Different browsers have different default values, for example for spacing, fonts, and headings. The normalization harmonizes them so that your page looks similar everywhere.

Next come settings for text selection. With CSS3, you can set the background color of highlighted text. Default values for links, lists, and images are also included. For example, the border around images is removed, even if they are inside a link.

In the "primary styles" section, you write your own rules. Below that are helper classes that often prove useful. The hidden class hides elements completely, even from search engines. The visuallyhidden class hides text from visitors, while search engines still pick it up. The invisible class makes elements invisible, but they retain their size and therefore their spacing. The clearfix clears floating elements. In addition, there are media queries for devices from 480 and 768 pixels width as well as print styles, so that the page also looks good on paper.

Setting up HTML5 Boilerplate: A Guide for Modern Websites
Setting up HTML5 Boilerplate: A Guide for Modern Websites
Setting up HTML5 Boilerplate: A Guide for Modern Websites
Setting up HTML5 Boilerplate: A Guide for Modern Websites
Setting up HTML5 Boilerplate: A Guide for Modern Websites

Step 15: Trying Out the Highlight Color and a Test Text

To experience the functions in practice, you insert an article with dummy text into the index.html. Save the file and open it in the browser. Select the text and observe the background color. Then you change the color value in the CSS, for example to a bold red, and reload the page. The highlight now appears in the new color.

Setting up HTML5 Boilerplate: A Guide for Modern Websites

Step 16: Browser Profiling with Modernizr

Modernizr adds classes to the html element that reveal which features the browser supports. To see them, open your browser's developer tools. In Firefox you use Firebug; in Chrome you reach the tools via Ctrl+Shift+C or Cmd+Shift+C on the Mac. You will then see the classes in the HTML section.

The js class indicates that JavaScript is available. If it is missing, no-js is there instead, and all other Modernizr classes are missing as well. Other classes such as canvas, touch, textshadow, or opacity show which features the browser supports. If a feature is missing, the prefix no- appears, for example no-textshadow. On this basis, you can write your own CSS alternatives for older browsers.

Setting Up HTML5 Boilerplate: A Guide for Modern Websites

Step 17: Testing Browser-Dependent Styles

To show the difference, you create three classes in the "primary styles" section: .ie6 with a red, .ie7 with a blue, and .ie8 with a green background color. You place the body selector in front so that the color applies to the entire page.

Setting up HTML5 Boilerplate: A Guide for Modern Websites

Then upload the files to a server, because Adobe BrowserLab only works with online pages. Enter the address into the tool and have it generate screenshots for different browsers. You will see that Internet Explorer 6 displays the red color and additionally the notice about Chrome Frame. In Internet Explorer 7 the page appears blue, in Internet Explorer 8 green.

Setting up HTML5 Boilerplate: A Guide for Modern Websites
Setting up HTML5 Boilerplate: A Guide for Modern Websites

Summary ??? Setting Up HTML5 Boilerplate: How to Use the Template for Modern Websites

The HTML5 Boilerplate is a well-thought-out foundation for your web projects. You have gotten to know the files and now know what the error page, the icons, the crossdomain.xml, the humans.txt, the robots.txt, and the sitemap are for. You have also understood why the scripts are at the end of the body, how the Content Delivery Network works together with a local fallback, and how to work with Modernizr and conditional comments for different browsers. For production use, the lean version without comments is recommended, while the documented version helps when learning.

FAQ

Is the HTML5 Boilerplate free to use?Yes, the template is available under an open-source license and may also be used in commercial projects.

Which version should I download as a beginner?Preferably the complete version with documentation and tips, because it contains the explanations directly in the code.

Do I have to keep all the files of the template?No, the template is a starting point. You can remove files such as crossdomain.xml or the test folder with QUnit if you don't need them.

Why are the JavaScript files at the end of the body?The visible content is loaded first, so the page appears faster and the visitor doesn't have to wait for scripts.

What happens if the Google Content Delivery Network goes down?A small script checks whether jQuery was loaded. If not, it includes the local copy from your project folder.

What is Modernizr?Modernizr is a script that adds classes to the HTML element. This lets you recognize which features the browser supports and provide alternatives via CSS for missing features.

How can I style the page for older versions of Internet Explorer?With conditional comments, you add classes such as ie6, ie7, or ie8 to the html element and write separate styles for each version.

1256,1220,274
Pascal Bajorat
Trainer About Pascal Bajorat Pascal Bajorat is a trained media designer and works as a web developer from Berlin. He manages various online platforms and open source projects, including several WordPress plug-ins. All courses by Pascal Bajorat