HTML Head
HTML Head Element
The <head> element is a container for metadata and is placed between the <html> and <body> tags.
Metadata is not displayed on the page but provides information about the document.
What Goes Inside the Head Element
The <head> element can contain the following elements:
<title><style><meta><link><script><base>
The title Element
The <title> element defines the title of the document.
The title is shown in the browser tab and is important for search engine optimization.
The <title> element is required in all HTML documents.
<title>A Meaningful Page Title</title>
The style Element
The <style> element is used to define CSS rules for a single page.
<style> body { background-color: powderblue; } h1 { color: red; } p { color: blue; } </style> The link Element
The <link> element defines the relationship between the document and an external resource.
It is most commonly used to link external CSS files.
<link rel="stylesheet" href="mystyle.css">
The meta Element
The <meta> element provides information such as character set, page description, keywords, author, and viewport settings.
Meta information is used by browsers, search engines, and other web services.
<meta charset="UTF-8"> <meta name="description" content="Free Web tutorials"> <meta name="keywords" content="HTML, CSS, JavaScript"> <meta name="author" content="John Doe">
Viewport Meta Tag
The viewport defines the visible area of a web page.
The viewport meta tag helps pages render correctly on different screen sizes.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
The script Element
The <script> element is used to define client-side JavaScript.
<script> document.getElementById("demo").innerHTML = "Hello JavaScript!"; </script> The base Element
The <base> element specifies a base URL or target for all relative URLs on a page.
Only one <base> element is allowed in a document.
<base href="https://www.w3schools.com/" target="_blank">
Chapter Summary
- The
<head>element contains metadata - The
<title>element defines the page title - The
<meta>element defines document metadata - The
<link>element links external resources - The
<style>element defines internal CSS - The
<script>element defines JavaScript - The
<base>element defines base URLs for links
HTML Head Elements
| Tag | Description |
|---|---|
<head> | Defines information about the document |
<title> | Defines the title of a document |
<base> | Defines a default URL or target for links |
<link> | Defines a relationship to an external resource |
<meta> | Defines metadata about a document |
<script> | Defines a client-side script |
<style> | Defines style information for a document |