<head> and the <body>. The head contains metadata and configuration, while the body contains the visible content.
The HEAD Section
The<head> section contains metadata - information about the document that browsers and search engines use, but that isn’t directly visible to users.
Essential Meta Tags
Character Encoding (charset)
Character Encoding (charset)
- UTF-8: Supports all characters worldwide (Spanish, Chinese, Arabic, emojis)
- Must be one of the first tags in the
<head> - Without it, special characters like ñ, á, é might display incorrectly
Always use UTF-8 encoding. It’s the web standard and supports internationalization out of the box.
Viewport (Responsive Design)
Viewport (Responsive Design)
width=device-width: Page width equals device widthinitial-scale=1.0: Initial zoom level at 100%
Description (SEO)
Description (SEO)
- Appears in Google results below the page title
- Ideal length: 150-160 characters
- Should be descriptive and include relevant keywords
- Unique for each page
Keywords (Legacy SEO)
Keywords (Legacy SEO)
Google no longer uses meta keywords for ranking. Other search engines might still consider it, but it’s much less important than quality content and the description meta tag.
Page Title
<title> element is crucial for SEO and user experience:
Where it appears:
- Browser tab
- Search engine results (as the clickable headline)
- Bookmarks/favorites
- Social media shares (if no Open Graph title is set)
- Length: 50-60 characters (longer titles get truncated in search results)
- Format: Include brand name and key content, e.g., “Page Name | Brand Name”
- Keywords: Include relevant keywords naturally
- Unique: Every page should have a unique title
- Good Titles
- Poor Titles
Linking Resources
Favicon
Favicon
.ico- Traditional format.png- Good browser support.svg- Scalable, modern choice
- Browser tabs
- Bookmarks
- History
- Mobile home screen shortcuts
Stylesheets
Stylesheets
- Separates content (HTML) from presentation (CSS)
- Browser caches CSS, improving performance on subsequent page loads
- Can be shared across multiple HTML pages
Preconnect (Performance)
Preconnect (Performance)
- Establishes early connection to external servers
- Useful for APIs, CDNs, or external fonts
- Reduces latency when fetching resources
The BODY Section
The<body> contains all visible content:
What Goes in the Body?
- Text content: Headings, paragraphs, lists
- Images and media: Photos, videos, audio
- Structure: Semantic HTML5 elements
- Forms: User input elements
- Interactive elements: Buttons, links
- Scripts: JavaScript files (typically at the end)
Complete Document Example
Here’s a complete, production-ready HTML document structure:Head vs Body Comparison
- HEAD Section
- BODY Section
Contains: Metadata and configurationNot visible to users, but crucial for:
- Browser configuration
- Search engines (SEO)
- Social media sharing
- Performance optimization
<meta>tags<title><link>(CSS, favicons)<script>(with defer/async)<style>(inline CSS)
Best Practices
Do
- Always include
charsetandviewportmeta tags - Write unique, descriptive titles for each page
- Use semantic HTML5 elements in the body
- Place scripts at the end of body or use defer
Don't
- Don’t put visible content in the head
- Don’t duplicate titles across pages
- Don’t omit alt text on images
- Don’t use deprecated tags