The HTML tag <title>
is used to define the title of a document. It is placed inside the <head>
section of an HTML document and is not visible on the web page itself. The title of a document is displayed in the title bar of the web browser and is also used by search engines to identify the content of the page.
The <title>
tag is a required element in HTML documents and should be used to provide a concise and descriptive title for the page. The title should accurately reflect the content of the page and should be no more than 60 characters in length.
Here are some examples of how the <title>
tag can be used:
The following code shows the basic usage of the <title>
tag:
<html>
<head>
<title>My Website</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is the home page of my website.</p>
</body>
</html>
In this example, the title of the page is set to "My Website". This title will be displayed in the title bar of the web browser and will also be used by search engines to identify the content of the page.
The <title>
tag can also be used to include keywords that are relevant to the content of the page. This can help improve the page's visibility in search engine results. Here is an example:
<html>
<head>
<title>My Website - Home Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is the home page of my website.</p>
</body>
</html>
In this example, the title of the page includes the keywords "My Website" and "Home Page". This can help improve the page's visibility in search engine results for those keywords.
The <title>
tag can also be used to dynamically generate the title of a page based on the content of the page. This can be done using server-side scripting languages like PHP. Here is an example:
<html>
<head>
<title><?php echo $pageTitle; ?></title>
</head>
<body>
<h1><?php echo $pageTitle; ?></h1>
<p>This is the <?php echo $pageType; ?> page of my website.</p>
</body>
</html>
In this example, the title of the page is dynamically generated using the PHP variable $pageTitle
. This variable can be set to any value based on the content of the page.