<head> Element

The <head> element provides information about the document.

 

  • Contains all the page header elements
  • Immediately follows the opening <html> tag
  • Should contain the <title> for the document

 

Can also contain the following tags:

  • <meta>
    • information about the document
    • e.g: keywords, description
    • useful for search engines
  • <link>
    • provides a link to an external file, such as a css stylesheet, or JavaScript file
  • <style>
    • provides css rules for the document
  • <script>
    • provides a container for JavaScript
  • <base>
    • provides a base URL for any relative links within the document
  • <object>
    • used to embed multimedia within the document

 

Example showing <head> element containing some of the above example tags:

<!DOCTYPE html>
<html>
	<head>
		<title>Document Title</title>
		<meta name="description" content="Learning html">
		<style>
			body{text-align:center;}
		</style>
		<script>
			window.onload = function() {
				document.getElementById("myHeading").innerHTML = "Hello, World!");
			}
		</script>
		<base href="https://www.tech-academy.co.uk" />
	</head>
	<body>
		<h1 id="myHeading">Don't Display...</h1>
	</body>
</html>

Save & refresh browser:

Hello, World

Leave a Reply