> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/tokio-rs/axum/llms.txt
> Use this file to discover all available pages before exploring further.

# Html

> Return HTML responses with proper content-type headers

The `Html` response type wraps any response body and automatically sets the `Content-Type: text/html; charset=utf-8` header.

## Basic usage

Wrap a string or any type that implements `IntoResponse`:

```rust theme={null}
use axum::{response::Html, routing::get, Router};

async fn handler() -> Html<&'static str> {
    Html("<h1>Hello, World!</h1>")
}

let app = Router::new().route("/", get(handler));
```

## How it works

### IntoResponse implementation

The `Html` type is a simple wrapper that sets the content-type header:

```rust theme={null}
impl<T> IntoResponse for Html<T>
where
    T: IntoResponse,
{
    fn into_response(self) -> Response {
        (
            [(header::CONTENT_TYPE, HeaderValue::from_static("text/html; charset=utf-8"))],
            self.0,
        )
            .into_response()
    }
}
```

See implementation in `axum/src/response/mod.rs:32-53`.

### Type definition

```rust theme={null}
pub struct Html<T>(pub T);
```

The inner value is public, allowing direct access and construction.

## Response fields

<ResponseField name="Content-Type" type="header">
  Automatically set to `text/html; charset=utf-8`
</ResponseField>

<ResponseField name="body" type="T">
  The inner response body (must implement `IntoResponse`)
</ResponseField>

## Common patterns

### Serving static HTML

```rust theme={null}
async fn index() -> Html<&'static str> {
    Html(
        r#"
        <!DOCTYPE html>
        <html>
            <head><title>My App</title></head>
            <body><h1>Welcome!</h1></body>
        </html>
        "#,
    )
}
```

### With template rendering

```rust theme={null}
use askama::Template;

#[derive(Template)]
#[template(path = "index.html")]
struct IndexTemplate {
    name: String,
}

async fn index() -> Html<String> {
    let template = IndexTemplate {
        name: "Alice".to_string(),
    };
    Html(template.render().unwrap())
}
```

### Serving multipart forms

```rust theme={null}
async fn show_form() -> Html<&'static str> {
    Html(
        r#"
        <!doctype html>
        <html>
            <head><title>Upload</title></head>
            <body>
                <form action="/upload" method="post" enctype="multipart/form-data">
                    <input type="file" name="file" multiple>
                    <input type="submit" value="Upload">
                </form>
            </body>
        </html>
        "#,
    )
}
```

Example from `examples/stream-to-file/src/main.rs:60-85`.

### With custom status codes

```rust theme={null}
use axum::http::StatusCode;

async fn not_found() -> (StatusCode, Html<&'static str>) {
    (
        StatusCode::NOT_FOUND,
        Html("<h1>404 - Page Not Found</h1>"),
    )
}
```

### Using From trait

```rust theme={null}
// Html implements From<T>
async fn handler() -> Html<String> {
    let html = String::from("<p>Hello</p>");
    html.into() // Calls Html::from()
}
```

## See also

* [Response tuples](/api/responses/tuples) for combining status codes and headers
* [IntoResponse trait](/api/responses/into-response) for custom response types
