- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- 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 - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- 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 Code Builder
- HTML References
- 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
The head tag is an HTML component used to specify the headings of an HTML document. Metadata which is basically data about data is 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.
The list of tags used in metadata is as follows −
S.No. | Tags |
---|---|
1 | title |
2 | style |
3 | meta |
4 | link |
5 | script |
6 | base |
Syntax
Following is the syntax of <head> tag −
<head> <title>Title of the document</title> </head>
Specific Attributes
The HTML <head> tag also supports the following additional attributes −
S.No. | Attribute & Description |
---|---|
1 | profile It defines the URL of metadata. |
2 | media It indicates which media/device the media resource is optimized for. |
3 | type It defines the media type of the <style> tag. |
Example
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>
When we execute the above code, the output window will pop up, displaying the text along with the applied CSS on the webpage.
Example
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>
On running the above code, it will generate an output consisting of the text along with a CSS applied that is displayed on the webpage.
Example
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>
When we execute the above code, the output window will pop up, displaying the text on the webpage. After the completion of the 4 seconds, the page redirects to the page of the link we mentioned in the meta tag.
Example
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>
On running the above code, it will generate an output consisting of the text along with a click button displayed on the webpage. When the user clicks the button, the event gets triggered and changes the color of the <h1> tag text.
To Continue Learning Please Login
Login with Google