HTML Head Tag
HTML head tag contain other tag that contain metadata. Metadata provides information about the document such as title, description, keywords etc.
The <head> tag is written as <head>.../<head> with the metadata content enclosed between the start and end tags. The <head> tag is placed between the opening and closing <html> tags.
The <head> tag contains following elements:
- <title>
- <style>
- <meta>
- <link>
- <script>
The <title> Element
The <title> element is used to write the title of a HTML document.
HTML Example:
<html>
<head>
<title> Page Title </title>
</head>
<body>
Body content goes here...
</body>
</html>
Run Example
The <style> Element
The <style> element is used to style a single HTML document.
HTML Example:
<style>
body { background-color: lightblue; }
h1 { color: red; }
p { color: blue; }
</style>
</html>
Run Example
The <link> Element
The <link> element is used to link external css files.
HTML Example:
The <meta> Element
The <meta> element is used to define character set, page description, keywords, author, and other metadata. You will not see any effect of the meta tag in the website. All the meta information goes before the body.
Here is an example of defining the character set:
HTML Example:
Here is an example of defining a description:
HTML Example:
Here is an example of defining keywords for search engines:
HTML Example:
Here is an example of defining an author of a page:
HTML Example:
The <script> Element
The <script> element is used to connect the JavaScript code with the HTML document.
Example:
function jsexample() {
var num2 = 10;
document.write(num2);
}
jsexample();
</script>
Run Example