HTML head Tag Examples

 HTML <head> Tag examples

The <head> tag in HTML is used to define the head portion of the document which contains information related to the document. 

The <head> tag contains other head elements such as <title>, <meta>, <link>, <style> <link> etc. 

In HTML 4.01 the <head> element was mandatory but in HTML5, the <head> element can be omitted.

Tag Specific Attributes:

The below-mentioned layout attributes of the <hr> tag have been removed from HTML5. 


Syntax : 


<head>

<title>Title of the document</title>

</head>


Example

A simple HTML document, with a <title> tag inside the head section:

<!DOCTYPE html>
<html lang="en">
<head>
<body>

<h1  <title>Title of the document</title>
</head>
>This is a heading</h1>
<p>This is a paragraph.</p>

</body>
</html>


TRY IT

More Examples:


<html>
<head>
  <base href="https://www.w3schools.com/" target="_blank">
</head>
<body>

<img src="images/stickman.gif" width="24" height="39" alt="Stickman">
<a href="tags/tag_base.asp">HTML base Tag</a>

</body>
</html>


TRY IT

Example

The <style> tag (adds style information to a page) goes inside <head>:

<html>
<head>
  <style>
    h1 {color:red;}
    p {color:blue;}
  
</style>
</head>
<body>

<h1>A heading</h1>
<p>A paragraph.</p>

</body>
</html>


 

Using style tag inside the head tag HTML


EXAMPLE: 



<!DOCTYPE html>

<html>

<head>
<style>
body {
background: blue;
}
h1 {
color: red;
}
p {
color: blue;
}
</style>
</head>

<body>

<h1>HELLO WORLD </h1>
<p>Your text here</p>

</body>

</html>

Using the link tag inside the head HTML tag


EXAMPLE:

<!DOCTYPE html>

<html>

<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>

<body>

<h1>HELLO WORLD</h1>
<p>Your text here.</p>

</body>

</html>

Default head tag CSS Setting example with value:


head {
  display: yes;
}

Comments :

Post a Comment