HTML <head> tag
The <head> tag is used to provide information about a HTML page. It stores metadata and additional resources of the page, even though the content within this element is not showing in the page.
Type: Not classified
Syntax of <head> tag
<head> <title> Page Title </title> </head>
Content within the<head> tag is not showing in the webpage. But many elements can be used within this element which helps in styling the webpage internally and externally.
Supported Browsers
| Tag | Chrome | Internet Explorer | Firefox | Safari | Opera Mini |
|---|---|---|---|---|---|
| <head> | Yes | Yes | Yes | Yes | Yes |
Full code example
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Page Title</title> <style> body { font-family:Arial; } </style> </head> <body> Body Content </body> </html>
All the texts for the above document will be Arial font-family.
Contents of <head> element
- <title> tag: It defines the title of an HTML document within the active window. It helps in displaying on search engine results.
Example
<head> <title> Page Title </title> </head>
- <style> tag: It defines the style of an individual HTML Page. All styles are making with CSS properties.
Example
<head> <title>Page Title</title> <style> p { font-family:Arial; text-color:red; } </style> </head>
All the texts within the <p> element will be Arial font in black color.
- <meta> tag: It is used to denote which character set is used, and to define keywords, page description & author etc. Adding this meta element helps in finding on web search results.
Example
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="HTML5 Tutorials.. "> <meta name="keywords" content="HTML5, Advanced HTML"> <meta name="author" content="Kayniz L"> </head>
- <link> tag: It is used to link the current webpage with an external CSS. It is the most common CSS linking form.
Example
<head> <link rel="stylesheet" href="style.css" type="text/css"> </head>
- <script> tag: It is used to embed JavaScript code. JavaScript is used to show the behavior of web page.
Example
<!DOCTYPE html> <html> <head> <script> function myFunction() { alert("I am an alert box!"); } </script> </head> <body> <button onclick="myFunction()"> Click Me </button> </body> </html>
- <base> tag: It specifies the base URL and base target in a webpage. It is used rarely.
Click here to learn more about <base> tag.Example
<head> <base href="https://learncodinghub.com/" target="_blank"> </head>
- <noscript> tag: It defines whether the script is supported or not in the active browser. It can be used within the <head> or <body> element.
Example
<head> <script> document.write("Hello World!"); </script> <noscript> Your browser does not support JavaScript! </noscript> </head>
