Every HTML document should have exactly one head section. This is where we tell things “about” our web pages, such as its title, description, internal style sheet, and external resources it needs.

About HTML Head Tag

The next piece of a web page after the doctype introduces the head section. It looks like this:

<head lang=en>

This specifies the start of the head and also that the web page is in the “en” (English) language.

FAQ: What is the second markup element of every HTML5 webpage?

Answer: <head lang=...>...</head>

It is optional because if we provide header material such as the character set or title, but without explicitly beginning our head, the browser will pretend that we typed <head>. I recommend you have an explicit head.

What Should Go in HTML Head?

Below is the list of items that should go inside the HTML Head tag:

  1. Character Set
  2. Title
  3. Style
  4. Scripts
  5. Meta Tags

The following are more details about each section:

Character Set

One of the first things the browser wants to know about our page is what Character Set we are using. We will use UTF-8, but there are other Character Sets that are desirable for languages like Chinese, Japanese, and Korean, for instance.

The charset is a required element in the head. It is specified like this:

<meta charset=utf-8>

Utf-8 stands for UCS Transformation Format, 8 bit. There are other Character Sets also that you can use instead of UTF-8, but it is the most popular.

FAQ: What HTML markup is used to specify our character set?

Answer: <meta charset=...>

Title Tag

The title tag goes inside the head, we also need to specify the web page title. This is a required element in the head. It is specified like this:

<title>our title goes here</title>

Replace “our title goes here” with whatever we want our title to be.

FAQ: What HTML markup is used to specify the title of our webpage?

Answer: <title>...</title>

Style Tag

The style tag goes inside the head, where we can specify styles. You should specify the style like this:

<style>
   body { text-align: center; background-color: #ffffcc; }
</style>

FAQ: What HTML markup is used to create an internal style sheet?

Answer: <style>...</style>

Script Tag

If we include any JavaScript in our web page, part or all of it should be included in the head section.

FAQ: What HTML markup will you use to specify scripts?

Answer: <script>...</script>

Is HTML Head Mandatory?

The answer is yes. The head tag is mandatory for a web page, and it should be after the HTML tag.

Related Tutorials:

  1. HTML Template Example
  2. What are Validators? [HTML, CSS and JavaScript]
  3. What is DOCTYPE in HTML5?

Reference:

  1. What is in the Head?

Vinish Kapoor

An Oracle Apex Consultant, Oracle ACE, and founder of foxinfotech.in and orclqa.com a question and answer forum for developers.

Leave a Reply