HTML Head Element
The head element contains metadata about a web page that is not displayed in the browser.
Head Tag
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Page Title</title>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
Important Meta Tags
<!-- Character Encoding -->
<meta charset="UTF-8">
<!-- Viewport -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Description -->
<meta name="description" content="Page description">
<!-- Keywords -->
<meta name="keywords" content="keyword1, keyword2">
<!-- Author -->
<meta name="author" content="Author Name">
<!-- Robots -->
<meta name="robots" content="index, follow">
Title Element
<title>Page Title - Campus Website</title>
Link Element
<!-- CSS -->
<link rel="stylesheet" href="style.css">
<!-- Favicon -->
<link rel="icon" href="favicon.ico" type="image/x-icon">
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
Script Element
<!-- External Script -->
<script src="script.js"></script>
<!-- Internal Script -->
<script>
console.log('Hello!');
</script>
<!-- Async Script -->
<script src="script.js" async></script>
<!-- Defer Script -->
<script src="script.js" defer></script>
Case Study: Complete Head Element
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Character Encoding -->
<meta charset="UTF-8">
<!-- Viewport for mobile -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- SEO Meta Tags -->
<title>Technology University - Academic Portal</title>
<meta name="description" content="Academic portal of Technology University for students and lecturers">
<meta name="keywords" content="university, campus, academic, student, lecturer">
<meta name="author" content="Technology University IT Team">
<meta name="robots" content="index, follow">
<!-- Open Graph -->
<meta property="og:title" content="Technology University">
<meta property="og:description" content="Academic Portal">
<meta property="og:image" content="https://univ-tech.edu/og-image.jpg">
<meta property="og:url" content="https://univ-tech.edu">
<!-- Favicon -->
<link rel="icon" href="favicon.ico" type="image/x-icon">
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<!-- CSS -->
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/responsive.css">
<!-- Canonical URL -->
<link rel="canonical" href="https://univ-tech.edu">
</head>
<body>
<!-- Page content -->
</body>
</html>
Everyday Case Study
Case: A developer needs to optimize performance.
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Preconnect for performance -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<!-- Preload critical resources -->
<link rel="preload" href="fonts/main.woff2" as="font" type="font/woff2" crossorigin>
<link rel="preload" href="css/critical.css" as="style">
<!-- CSS -->
<link rel="stylesheet" href="css/style.css">
<!-- Defer non-critical JS -->
<script src="analytics.js" defer></script>
</head>
Best Practices
- Charset always first: For correct encoding
- Viewport: For mobile responsiveness
- Descriptive title: 50-60 characters
- Meta description: 150-160 characters
- Preconnect: For performance
Summary
The head element contains important metadata for SEO, performance, and page identity. Always complete the head element with the required tags.