The head area
Every page has a <head>
element that contains information about your page.
What belongs in the <head>
of every website?
Included on every page should be:
- Title. The title should be 30 - 60 characters long for SEO optimization.
- Description. The description should be 50 - 160 characters long for SEO optimization.
- Viewport and Charset. Viewport refers to the window width. Charset defines which characters the browser can expect. There’s not much reason to change these so just use:
<meta name="viewport" content="width=device-width,initial-scale=1">
&<meta charset="utf-8">
- Favicon. The icon of your webpage. There’s a guide by EvilMartians on how to optimize your favicon for legacy browsers but just using a simple .svg with a .fav fallback is enough nowadays.
- Robots. Define which pages should be indexed by search engines or not. This way you can exclude pages which you might not want to show up on Google searches. It is best practice to also include the sitemap in your robots.txt file. The sitemap is a list of all the pages on your website.
- Open Graph. In addition to other meta tags you have the Open Graph protocol which has been established by Facebook. It includes information such as which image to use for the social preview image, for example when a link is shared within a post on a social media site.
- Canonical. When you have multiple pages with the same content you will want to define which on of these is the canonical page. The canonical page is the one that will show up in search results.
Optionally you might want to include:
- Theme Color. Define a specific theme color. Some browsers will adjust the color of some elements such as the scroll bar to fit your theme color.
- Manifest. If your website is a Progressive Web App (PWA) you will want to add a manifest which defines some behaviour for when the webpage is installed on the user’s device.
- Pre-loading fonts.
Included in the head are also links to the stylesheets and script files, if they exist.
Also will want stylesheet and script files.
<head>
Code Example
Example of the code for a possible head:
Further helpful resources: