- HTML Tutorial
- HTML - Home
- HTML - Introduction
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <head> Tag
HTML <head> tag is used as a container for metadata and placed after the html tag. Metadata which is basically data about data present in the head section. As a result, the information in the head tag is used by browsers and search engines but is not visible on the page itself.
In general, head tags contain elements like the document title, script or stylesheet links, and meta tags that describe the structure and content of the document.
Syntax
<head> ... </head>
Attribute
HTML head tag supports Global Attributes of HTML
The HTML <head> tag also supports the following additional attributes −
Attribute | Values | Description |
---|---|---|
profile | URL | It defines the URL of metadata. |
media | media_query | It indicates which media/device the media resource is optimized for. |
type | text/css | It defines the media type of the <style> tag. |
Try to click the icon run button to run the following HTML code to see the output.
Examples of HTML head Tag
In the bellow examples we will see the usage of head tag with other child tags of head tag.
HTML title Tag in head Tag
Let’s look at the following example, where we are going to use the <title> tag inside the <head> section.
<!DOCTYPE html> <html> <head> <title>Welcome to index page</title> </head> <body style="background-color:#D2B4DE"> <h1>TutorialsPoint</h1> <p>The Best E-Way Learning.</p> </body> </html>
HTML style Tag in head Tag
Considering another scenario, where we are going to use the <style> tag inside the <head> tag.
<!DOCTYPE html> <html> <head> <style> body { background: #D5F5E3; } h1 { color: #17202A; } p { color: #DE3163; } </style> </head> <body> <h1>MSD</h1> <p>Mahendra Singh Dhoni is an former Indian cricketer. He was captain of the Indian national team in limited-overs formats from 2007 to 2017 and in Test cricket from 2008 to 2014.</p> </body> </html>
HTML meta Tag in head Tag
In the following example, we are going to add the URL with a content value that redirects to the page when the time limit is over.
<!DOCTYPE html> <html> <head> <meta http-equiv="refresh" content="4; url=https://www.tutorialspoint.com/index.htm"> </head> <body> <h2>Redirect to home page</h2> <p style="color: green;">After 4 seconds it will automatically redirect to URL specified in the tag</p> </body> </html>
HTML script Tag in head Tag
Following is an example where we are going to use the <script> tag inside the <head> tag.
<!DOCTYPE html> <html> <head> <script> function tutorial() { document.getElementById("tp").style.color = "#2ECC71"; } </script> </head> <body> <h1 id="tp">TUTORIALSPOINT</h1> <p>The Best E-Way Learning.!</p> <button type="button" onclick="tutorial()">CLICK</button> </body> </html>
List of elements can be placed inside head Tag
Tags | Description |
---|---|
<title> | The <title> tag is defined inside of the <head> tag, and it should be text-only. |
<style> | HTML <style> tag contains style properties for an HTML document or part of a document as an internal CSS. |
<meta> | The <meta> tag is used to provide such additional information. |
<link> | HTML <link> tag specifies a relationship between the current document and an external resource. |
<script> | HTML <script> tag is used to contain the internal JavaScript code in HTML document. |
<base> | This tag is used to define the base ULR or target the relative URLs. |
Supported Browsers
Tag | |||||
---|---|---|---|---|---|
head | Yes | Yes | Yes | Yes | Yes |