HTML <head> Element

Publish in HTML Tutorial el 24/05/2025 14:57

The <head> Element: Your HTML Document's Control Center

The <head> element is a crucial part of any HTML document, serving as a container for metadata and other essential information that isn't directly displayed on the web page itself. This invisible section provides browsers and search engines with critical details about your document.

Unlike content within the <body> tag, elements in the <head> typically include page titles, character set declarations, stylesheets, scripts, and meta information like descriptions and viewport settings. These elements help browsers render the page correctly and assist search engines in understanding your content.


Basic Structure

Here's how a minimal <head> section looks in an HTML document:


Common Elements Found in <head>

  • <title> - Defines the title shown in browser tabs
  • <meta> - Provides metadata like charset, viewport, and descriptions
  • <link> - Connects external resources like CSS files
  • <style> - Contains internal CSS styles
  • <script> - Includes JavaScript code
  • <base> - Specifies base URL for relative links


Examples of <head> Usage

Example 1: Basic Head with Title and Meta Tags

A simple <head> section with essential metadata:

Play Code


Example 2: Linking External CSS

How to include external stylesheets in your <head>:

Play Code


Example 3: Including JavaScript

Adding JavaScript in the <head> (though typically better at end of <body>):

Play Code


Example 4: SEO Optimization

A <head> section optimized for search engines:

Play Code


Example 5: Dynamic Title with JavaScript

Changing the page title dynamically using JavaScript:

Play Code


Tips and Tricks

  • Order matters: Place charset meta tag first to prevent encoding issues
  • Viewport is essential: Always include viewport meta tag for responsive design
  • Preload critical resources: Use <link rel="preload"> for important assets
  • Favicons: Include multiple favicon sizes for different devices
  • Performance: Place non-critical JavaScript at the end of body or use async/defer
  • Social media: Add Open Graph tags for better sharing appearance

The <head> element might be invisible to users, but it's incredibly powerful for controlling how your page behaves and appears across different platforms and devices. Mastering its use will significantly improve your web development skills.

También te puede interesar

HTML <style> Element
HTML <style> Element

The <style> HTML element contains style information for a document, or part of a document. ...

HTML <strong> Element
HTML <strong> Element

The <strong> element is used to indicate that its content has strong importance, seriousnes...

HTML <span> Element
HTML <span> Element

The <span> element is an inline container used to mark up a part of a text or document. Unl...

HTML <source> Element
HTML <source> Element

The <source> element is used to specify multiple media resources for media elements like &l...

HTML <small> Element
HTML <small> Element

The <small> element is used to represent side-comments and small print, typically for discl...

HTML <section> Element
HTML <section> Element

HTML <section> Element: The Complete Guide The <section> element is a semantic HTML ...