HTML5 Template: A Basic Boilerplate for Any Project

HTML5 Template: A Basic Boilerplate for Any Project – SitePointSkip to main contentHTML5 Games: Novice to Ninja🎮 Design and build cool games that work in any modern browserAs you learn HTML5 and add new techniques to your toolbox, you’re likely going to want to build yourself an HTML boilerplate to start off all future projects. This is definitely worth doing, and there are many starting points online to help you build your own HTML5 template.
In this article, we’ll look at how to get started with building your own HTML5 boilerplate. We’ll walk through the essential elements of an HTML template, ending with a basic template that you can take with you and build upon.
If you’d rather just grab the code now and read this article later, here’s our finished HTML5 template.
The Anatomy of an HTML5 Template
An HTML template typically includes the following parts:
The document type declaration (or doctype)
The Element
The character encoding
The viewport meta element
, description, and author
Open Graph meta elements for social cards
Favicons and touch icons
Links to stylesheets and scripts
Other than the document type declaration and element, the elements listed above will mostly be found inside the section of the HTML template.
The HTML5 Doctype
Your HTML5 template needs to start with a document type declaration, or doctype. A doctype is simply a way to tell the browser — or any other parser — what type of document it’s looking at. In the case of HTML files, it means the specific version and flavor of HTML. The doctype should always be the first item at the top of any HTML file. Many years ago, the doctype declaration was an ugly and hard-to-remember mess, often specified as “XHTML Strict” or “HTML Transitional”.
With the advent of HTML5, those indecipherable eyesores are gone and now all you need is this:
doctype html >

Simple, and to the point. The doctype can be written in uppercase, lowercase, or mixed case. You’ll notice that the “5” is conspicuously missing from the declaration. Although the current iteration of web markup is known as “HTML5”, it really is just an evolution of previous HTML standards — and future specifications will simply be a development of what we have today. There’s never going to be an “HTML6”, so it’s common to refer to the current state of web markup as simply “HTML”.
Because browsers are required to support older content on the Web, there’s no reliance on the doctype to tell browsers which features should be supported in a given document. In other words, the doctype alone isn’t going to make your pages compliant with modern HTML features. It’s really up to the browser to determine feature support on a case-by-case basis, regardless of the doctype used. In fact, you can use one of the older doctypes with new HTML5 elements on a page and the page will render the same as it would if you used the new doctype.
The Element
Following the doctype in any HTML document is the element:

This hasn’t undergone any significant change since the advent of HTML5. In the code snippet above, we’ve included the lang attribute with a value of en, which specifies that the document is in English. This isn’t required for a page to validate, but you’ll get a warning from most validators if you don’t include it.
The element is divided into two parts, the and sections. The section contains important information about the document that isn’t displayed to the end user — such as the character encoding, and links to CSS files and possibly JavaScript. The section contains everything that’s displayed in the browser — text, images, and so on.
HTML Document Character Encoding
The first line inside the section of an HTML document is the one that defines the character encoding for the document. This is an optional feature and won’t cause any warnings in validators, but it’s recommended for most HTML pages:

In nearly all cases, utf-8 is the value you’ll be using in your documents. A full explanation of character encoding is beyond the scope of this article, and it probably won’t be that interesting to you, either. Nonetheless, if you want to delve a little deeper, you can read about character encoding in the HTML specification.
Note: to ensure that certain older browsers read the character encoding correctly, the entire character encoding declaration must be included somewhere within the first 512 characters of your document. It should also appear before any content-based elements (like the element that appears later in our example).
There’s much more we could write about this subject, but for now, we’re content to accept this simplified declaration and move on to the next part of our document.

The viewport meta element is a feature you’ll see in just about every HTML5 template. It’s important for responsive web design and mobile-first design:

This element includes two attributes that work together as a name/value set. In this case, the name is set to viwport and the value is width=device-width, initial-scale=1. This is used by mobile devices only. You’ll notice the value has two parts to it, described here:
width=device-width: the pixel width of the viewport that you want the website to be rendered at.
initial-scale: this should be a positive number between 0.0 and 10.0. A value of “1” indicates that there’s a 1:1 ratio between the device width and the viewport size.
You can read up a little more on these meta element features on MDN, but for now just know that, in most cases, this meta element with these settings is best for mobile-first, responsive websites.
The , description, and author
The next section of the HTML template contains the following three lines:
A Basic HTML5 Template

These elements have been part of HTML for a long time, so there’s nothing too new here. The is what’s displayed in the browser’s title bar (such as when you hover over a browser tab). This element is the only mandatory element inside the .
The other two are optional elements defining a description for SEO purposes along with an author. All elements inside are optional with the exception of . In fact, you can put as many valid elements in the as you like.

As mentioned, all meta elements are optional but many have benefits for SEO and social media marketing. The next section in our HTML5 boilerplate includes some of those meta element options:

These elements take advantage of something called the Open Graph protocol, and there are many others you can use. These are the ones you’re likely to use most often. You can view a full list of available Open Graph meta options on the Open Graph website.
The ones we’re including here will enhance the appearance of the web page when it’s linked in a social media post. For example, the five elements included here will appear in social cards embedding the following data:
a title for the content
the type of content being delivered
the canonical URL for the content
a description of the content
an image to associate with the content
When you see a post shared on social media, you’ll often see these bits of data automatically added to the social media post. For example, below is what would appear in a tweet if you included a link to GitHub’s home page:

Image source: GitHub
Favicons and Touch Icons
The next section in the HTML5 template includes elements that indicate resources to include as a favicon and apple touch icon:

The favicon.ico file is for legacy browsers and doesn’t have to be included in the code. As long as your favicon.ico file is included in the root of your project, the browser will automatically find it. The favicon.svg file is for modern browsers that support SVG icons. The last element references the icon that’s used on Apple devices when the page is added to the user’s home screen.
There are other options you can include here, including a web app manifest file that references other icons. For a full discussion, we recommend Andrey Sitnik’s post on the subject. But the ones included here will suffice for a simple starter template.
Including a Stylesheet and Scripts
The last two significant portions of our HTML template are the reference to a stylesheet and script. Both are optional, of course:

The stylesheet is included using the element with an appropriate rel attribute. A stylesheet can be included anywhere in a document, but you’ll customarily see it inside the . And unlike older versions of HTML, there’s no need to include a type attribute (which was never needed in the first place).
Likewise with script elements, you’ll see them almost anywhere in a document, but they’re usually at the bottom (just before the closing tag) as a best practice.

Placing the element at the bottom of the page is for the purposes of the page-load speed. When a browser encounters a script, it will pause downloading and rendering the rest of the page while it parses the script. This results in the page appearing to load much more slowly when large scripts are included at the top of the page before any content. Thus, most scripts should be placed at the very bottom of the page, so that they’ll only be parsed after the rest of the page has loaded. But note that in some cases, the script may need to be placed in the head of your document, because you want it to take effect before the browser starts rendering the page.
Similar to stylesheet references, the type attribute on scripts is not (and never was) needed. Since JavaScript is, for all practical purposes, the only real scripting language used on the Web, and since all browsers will assume that you’re using JavaScript even when you don’t explicitly declare that fact, you can safely leave off type=”text/javascript, which often appears in legacy code.
A Note About Older Browsers and New Elements
When HTML5 was introduced, it included a number of new elements, such as and . You might think that support for unrecognized elements would be a major problem for older browsers — but it’s not! The majority of browsers don’t actually care what tags you use. If you had an HTML document with a element (or even a element) in it, and your CSS attached some styles to that element, nearly every browser would proceed as if this were totally normal, applying your styling without complaint.
Of course, such a hypothetical document would fail to validate and may have accessibility problems, but it would render correctly in almost all browsers — the exception being old versions of Internet Explorer (IE). Prior to version 9, IE prevented unrecognized elements from receiving styling. These mystery elements were seen by the rendering engine as “unknown elements”, so you were unable to change the way they looked or behaved. This includes not only our imagined elements, but also any elements that had yet to be defined at the time those browser versions were developed, including new HTML5 elements.
Fortunately, older browsers that don’t support styling of new elements are virtually nonexistent today, so you can safely use any new HTML element without worry in almost any project.
That being said, if you really need to support ancient browsers, you can still use the trusty HTML5 Shiv, a simple piece of JavaScript originally developed by John Resig. Inspired by the work of Sjoerd Visscher, it made the new HTML5 elements styleable in older versions of IE. Really, though, this shouldn’t be needed today. As indicated by, HTML5 elements are supported across all in-use browsers.
The Complete HTML5 Boilerplate
Here’s our final HTML5 Template — a basic boilerplate that you can use for any project:
doctype html >

A Basic HTML5 Template

You can drop this simple, ready-to-use HTML5 template into any project today! Building on this, you can add whatever content you want between the and tags.
Next Steps
A great way to take your web layouts to the next level is with The Principles of Beautiful Web Design, 4th Edition. This book will teach you the principles of design and show you how to implement them for the Web. It was completely rewritten in September 2020 and includes cutting-edge techniques you haven’t read about anywhere else.
To hone your CSS knowledge, our curriculum of modern CSS projects will help you master the latest, advanced editions to CSS3.
Beyond that point, you can take your website or web app development to the next level with interactivity and programmatic, reactive UIs. Check out SitePoint’s extensive resources on JavaScript and React, for example. And find out how to start new projects faster with our guide to the best scaffolding web tools and libraries. Alternatively, if you’d like to build web experiences without learning to code, read our primer on the no-code movement. The latest no-code tools have changed the game. For the first time, they’re powerful enough to provide a serious alternative to coding in many situations.

The Ingredients of a Great WordPress Plugin

There are currently over 58,000 listings in the WordPress Plugin Repository. Beyond that, there are likely thousands of free and commercial offerings available elsewhere on the web. Together, they cover a staggering number of functionalities and use cases. But not all plugins are created equally. Only a relative few are labeled as “great” by their…

15 Beautiful Resume and CV Web Templates

Do you want to create an impressive online resume to highlight your coding career and catch the attention of recruiters, hiring managers or clients? On Envato Elements you will find high quality resumes and CVs optimized for the web. These templates professionally formatted and are easy to customize. You can replace the placeholder content with your own credentials…

Plutonium – free Next.js template styled with TailwindCSS!

Hey all! I created a Next.js template styled with TailwindCSS with built-in dark mode (with Next-Themes) & Next-SEO support.I’m pretty new to this (first time creating a template), so please let me know if you have any feedback! One pending problem that I’ve seen with it is that the text “web.” will get cut off on mobile for some reason and I’m not able to determine why. I’ll try looking around some more!Let me know if you have any questions about it!Project link – link –

Best Testimonials Plugins for WordPress

Do you want customers to leave testimonials on your website? If you offer services through your website, it’s a good idea to include a system where customers can leave their testimonials.  Customer testimonials convince potential customers who may be on the fence to take the next step and use your products or services.  Testimonial plugins…

Best WordPress Widgets for 2021

Are you looking for widgets that will improve functionality of your WordPress website and create a positive user experience?  On Envato Elements and CodeCanyon you will find WordPress widget plugins that will help build a website that gives your customers and potential customers the best website experience possible.  You can find social media widgets, weather widgets,…

Moving Backgrounds: When, Why, and How to Use Them

Moving Backgrounds: When, Why, and How to Use Them – SitePointSkip to main contentFree JavaScript Book!Write powerful, clean and maintainable JavaScript.RRP $11.95 In this article, we’ll take a close look at the whats and whys of moving backgrounds. We’ll consider the impact they have on conversions, examine when they should and shouldn’t be used, and then offer practical tips for doing them the right way.
Moving Images are Powerful
There’s no denying people love video content. TikTok is shooting up the app charts, and short clips are surpassing pictures for shares on Facebook. Things that move are eye-catching, engaging, and more memorable.
The appeal of video isn’t limited to social media. Moving elements on your landing pages give users a way to instantly connect with your brand. Here are some more web design statistics worth knowing:
Various studies show videos can increase landing page conversions by around 80%.
A shopper who watches a video is nearly two times more likely to convert than a shopper who doesn’t.
Two thirds of people would rather read something beautifully designed than something plain.
Video can do good things for your site. But that doesn’t mean you should turn your home page into a mini cinema. As with all things web design, it’s all about finding that sweet spot between what feels playful and exciting and what works.
When to Use Moving Backgrounds
Moving backgrounds can be incredibly effective, but they’re not always appropriate. They slow your site down, they can be distracting, and they’re creatively bold — three things that aren’t suitable in certain situations.
For example, if you’re offering something complex, a video is more likely to distract that aid comprehension. If you’re offering something serious — like financial advice, government information, or anything to do with healthcare — a video just feels … wrong. Similarly, if you’re a practical site — like a grocery store or tool hire site — then speed is probably more important that giving off a certain vibe.
On the other hand, if your business is all about exuding a certain mood, then moving backgrounds can be perfect.
We use one at Chromatix because we’re a creative design agency, and playfulness and beauty are hugely attractive to our customers.

Luxury lifestyle brands often use moving backgrounds to good effect, because people buy into an experience rather than a product. The same goes for conferences and events, spas, retreats, vacation rentals, and so on.
Here are three reasons to use moving backgrounds:
to set a tone
to exude a lifestyle
to elicit an emotional reaction
Here are three reasons not to use a moving background:
because everyone else is doing it
because conversion statistics tell me it’ll get good results
because it looks pretty
How to Successfully Incorporate Moving Backgrounds into Your Home Page
Whether you’re building your site from the ground up, using WordPress, or working with a drag-and-drop website builder, here are some tips to help you get it right.
1. Don’t let your site slow down
Sending a visitor to a slow site is bad news for your site numbers: 39% of people will leave a website if images take too long to load. It’s one of the top SEO ranking factors. The conversion rates of pages that load slowly drop by an average of 4.42% with each additional second of load time (within the first five seconds).
There’s no getting around it: videos and moving elements will slow things down. Here are three steps you can take to mitigate sluggish site speeds:

Optimize your images. (Check out SitePoint’s Jump Start Web Performance for some in-depth tips.)

Compress your files and manage your own caching. (This can be a complicated job, but tools like Nitropack can help.)

Loop your video. When it comes to looping your video, bear in mind that bigger videos will slow down your site — and as we’ve mentioned previously, having a slow-loading site sends conversion rates plummeting. One way to keep speed up is to have a shorter video that loops. Try to aim for 5–10 seconds in length, then loop it seamlessly and continually to give the impression it’s longer than it is. Remember: you’re just trying to create a mood, not play a full film or advert.

2. Keep your call to action clear
The attraction of moving images is that they’re eye-grabbing — and when it comes to setting the mood and boosting dwell time, that’s a good thing. But watch out: if your CTA is fighting for attention or overlooked because your moving background is too distracting, then you’ll hit problems.
CTAs convert better with a little negative space around them. 232% better, to be precise. When there’s too much visual noise going on, it’s hard to pick out the important bits — so avoid putting your call to action over your video.
3. Make sure text is readable
Ever watched a movie with white subtitles, only for a snow scene to come up and swallow up the text? OK, so that’s quite a niche example, but you get the idea: choose the color of your text carefully when it’s going over video, because the image moves and the text needs to be readable over every single frame. Pick colors that contrast so the message isn’t lost like white subtitles over snow.
If your moving background is detailed and contains all the colors and shades, then simply opting for a contrasting color might not be enough. In this case, try a light, dark, or colored overlay to decrease the contrast and allow your text to pop.
4. Choose a background that enhances your message
Moving backgrounds have a tendency to steal the limelight. It’s why we like them! But if they’re pulling focus from your core message or goal, then you’ll soon hit choppy waters.
When picking your video, don’t just go for what looks pretty. Put some real thought into choosing something that’s relevant to your overall message or brand — and most of all, something that will appeal to your target market. Your moving background needs to enhance your home page’s message, not detract from it.
5. Be careful with audio
There are few things more annoying than clicking onto a website, only to have it blast out some music or sound effect unannounced. Especially when you’re somewhere quiet like the office. For this reason, having auto-playing audio is a no-no. If you absolutely must have sound, make sure it loads muted so the power is in the user’s hands as to whether they switch it on or not.
Here are some more tips for better website background videos.
Final Thoughts
Moving backgrounds can be a great way to enhance your brand’s message and draw users into your site. They have the power to boost engagement, send your conversion rates sky high, and create an irresistibly immersive experience. But use them with caution. They can slow your site down, so make sure to do your research on how best to keep things things speedy. And if you don’t really need a moving background, stick to static images and text. Doing what works best for you and your users will always be the best option.