# The Head: charset, viewport, title

> Three lines of invisible setup that decide whether your text renders, your page fits a phone, and your tab and search result read well.

Subject: HTML | Lesson 2 of 42 | 5 min read
Interactive lesson: https://codewithanimation.in/html/the-head-essentials
Previous: [The HTML Document Skeleton](https://codewithanimation.in/html/document-skeleton.md) | Next: [Tags, Elements & Attributes](https://codewithanimation.in/html/elements-tags-attributes.md)

## What it is

The `<head>` is where a page keeps its setup: information for the browser, search engines, and social apps, none of which is drawn on the screen. Most of it is optional, but three lines belong on nearly every page you build.

Those three are `<meta charset="utf-8">`, `<meta name="viewport">`, and `<title>`. Each one is invisible, and each one quietly controls something the visitor definitely notices: whether the text is readable, whether the page fits their phone, and what the browser tab and search result say.

## Why it matters

These lines are easy to skip because nothing on the page looks broken without them on your own laptop. The damage shows up elsewhere: garbled characters for some readers, a tiny zoomed-out layout on phones, a tab that just says the file name.

Setting them is a thirty-second habit that prevents three of the most common embarrassing bugs in a beginner's first real site. Get them in from the start and you never think about them again.

## How it works

`<meta charset="utf-8">` declares the character encoding. UTF-8 can represent almost every character in every human language plus emoji, so your text renders correctly whether it is English, accented French, or Japanese. Put it near the top of the head so the browser knows the encoding before it reads much text.

`<meta name="viewport" content="width=device-width, initial-scale=1">` tells mobile browsers to make the layout match the device width and start at 100% zoom. Without it, phones render your page in a pretend window about 980px wide and shrink it to fit, so everything looks tiny and your responsive styles never trigger.

`<title>` sets the document title. It is the text in the browser tab, the default name when someone bookmarks the page, and the headline of your entry in search results. It is metadata, so it is not the same as the on-page `<h1>` heading; give every page its own clear title.

## Common mistake: Forgetting the viewport tag breaks the page on phones only

Leave out the viewport line and your site looks perfect on a desktop, then loads zoomed-out and unreadably small on a phone, with your media queries never kicking in because the browser thinks the screen is about 980px wide. It is a confusing bug precisely because the desktop you are testing on looks fine. Add `width=device-width, initial-scale=1` and the layout fits the device. While you are there, do not disable zoom with `user-scalable=no`, because pinch-to-zoom is an accessibility need.

## Tip: Set all three before you write any content

Make the first lines inside every `<head>` the charset, then the viewport, then a unique `<title>`. Charset goes first so the browser reads the rest of the document with the right encoding. Treat the title as your search-result headline, not an afterthought, since it is often the first thing a stranger reads about your page.

## Try it: What the machine sees

These three lines never appear on the page, but a browser, a phone, and a search engine each read one. Watch what each one produces on the right.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/html/the-head-essentials

## Check yourself

### Question 1

What happens if you leave out the viewport meta tag?

- A. Phones render the page zoomed-out and wide, and responsive styles do not trigger
- B. The page refuses to load on mobile
- C. All the text turns into garbled symbols

Correct answer: A

Without the viewport tag, mobile browsers assume a roughly 980px layout and zoom out to fit, so the page looks tiny and media queries built for small screens never apply. `width=device-width, initial-scale=1` fixes it.

- Why not B: It still loads, it just renders in a ~980px virtual viewport shrunk to fit the screen.
- Why not C: That is what a missing or wrong `charset` causes, not a missing viewport.

### Question 2

What does <meta charset="utf-8"> do?

- A. Sets the character encoding so every language and emoji renders correctly
- B. Chooses the font for the page
- C. Sets the text shown in the browser tab

Correct answer: A

`charset="utf-8"` declares the encoding. UTF-8 covers virtually every written language plus emoji, so text decodes correctly instead of turning into garbled symbols.

- Why not B: Fonts are a CSS job. Charset is about which characters the bytes decode to.
- Why not C: That is the `<title>` element. Charset is about encoding.

### Question 3

Where does the <title> element show up?

- A. The browser tab, bookmarks, and search results
- B. As the large heading at the top of the page
- C. Nowhere, it is only a comment for developers

Correct answer: A

`<title>` is the document title: it labels the browser tab, becomes the default bookmark name, and is the clickable headline in search results. It is separate from the on-page `<h1>`.

- Why not B: That is the on-page `<h1>`. The title is metadata and is not drawn in the body.
- Why not C: It is real metadata the browser and search engines use, not a comment.

## Remember this

- The head holds invisible setup for browsers, search engines, and social apps, never page content.
- `<meta charset="utf-8">` lets every language and emoji render; without it text can turn to garbled symbols.
- `<meta name="viewport" content="width=device-width, initial-scale=1">` makes the page fit phones and lets responsive CSS work.
- `<title>` is your tab label, bookmark name, and search-result headline; give every page its own.
