# .html MIME Type: text/html

> Web pages. Browsers render a response as HTML only when it's served as text/html.

- MIME type: `text/html`
- Extensions: .html, .htm
- Content-Type header: `text/html; charset=utf-8`
- Compress in transit: yes

## Good to know

- Declare the encoding in the header (`charset=utf-8`) or as the first element of `<head>` with `<meta charset="utf-8">`.
- XHTML served as `application/xhtml+xml` is parsed by the stricter XML parser — one error and the page fails to render.
- Serve user-uploaded HTML from a separate domain or as an attachment, never inline on your main origin.

## Server configuration

### nginx (inside the types block in mime.types)

```
text/html html htm;
```

### Apache (.htaccess or server config)

```
AddType text/html .html .htm
```

### Express

```
res.set("Content-Type", "text/html; charset=utf-8");
```

### Python

```
import mimetypes

mimetypes.add_type("text/html", ".html")
mimetypes.add_type("text/html", ".htm")
```

### HTML file input

```
<input type="file" accept=".html,.htm,text/html">
```

## FAQ

### What is the MIME type for .html files?

`text/html`. The same type covers .htm.

### What Content-Type header should a .html file be served with?

`Content-Type: text/html; charset=utf-8`. As a text format, include the charset so browsers don't guess the encoding. It compresses well, so let the server apply gzip or Brotli.

## Related types

- [.css — text/css](https://www.devkult.com/mime/css.md)
- [.js — text/javascript](https://www.devkult.com/mime/js.md)
- [.xml — application/xml](https://www.devkult.com/mime/xml.md)
- [.svg — image/svg+xml](https://www.devkult.com/mime/svg.md)

Open the interactive page: https://www.devkult.com/mime/html