---
canonical: 'https://htmlcsstoimage.com/features/html-to-webp/csharp-client'
title: 'Convert HTML to WebP in C# with the HCTI NuGet package | HTML/CSS to Image'
description: 'Convert HTML and CSS to WebP in C# with the HtmlCssToImage NuGet package. Generate a hosted .webp image URL.'
---

# Generate WebP images in C# with the HCTI NuGet package without managing Chrome

Render HTML and CSS from C# with the HtmlCssToImage NuGet package without installing Chrome, running Playwright or Selenium, or building a separate image-storage pipeline.

## Why use the API instead of native C# browser automation?

- Keep ASP.NET services and background workers free of local browser binaries and browser-process lifecycle code.
- Use managed browser versions, isolated render jobs, timing controls, and consistent viewport behavior across deployments.
- Receive a hosted .webp URL without building a separate pipeline for temporary files, uploads, storage, and delivery.

## Complete C# request (HtmlCssToImage NuGet package)

Use this request to render the example HTML and CSS as WebP.

```csharp
// dotnet add package HtmlCssToImage

using HtmlCssToImage;
using HtmlCssToImage.Models;
using HtmlCssToImage.Models.Requests;
using System.Collections.Generic;
using System.Text.Json.Nodes;

// In an application, use IHttpClientFactory through dependency injection:
// https://www.nuget.org/packages/HtmlCssToImage.DependencyInjection
using var httpClient = new HttpClient();
var hctiOps = new HtmlCssToImageOptions(Environment.GetEnvironmentVariable("HCTI_API_ID")!, Environment.GetEnvironmentVariable("HCTI_API_KEY")!);
var client = new HtmlCssToImageClient(httpClient, hctiOps);

var request = new CreateHtmlCssImageRequest
{
    Html = """
           <div class="card">
             <h1>Hello, world!</h1>
             <p>Generated from HTML and CSS.</p>
           </div>
           """,
    Css = """
          .card {
            width: 480px;
            padding: 40px;
            background: #f0fdf4;
            color: #052e16;
            font-family: sans-serif;
          }
          """,
};

using var result = await client.CreateImageAsync(request);
if (result.Success)
{
    Console.WriteLine(result.Response.Url);
}

```

## When to use WebP

WebP combines modern compression with high visual quality, making it a strong default for images delivered on the web.

- **Efficient compression**: Deliver high-quality rendered images with smaller files than many traditional image formats.
- **Transparency support**: Keep transparent areas in HTML designs while benefiting from a web-focused output format.
- **Built for the modern web**: Use WebP for product UI, content feeds, responsive sites, and performance-sensitive delivery.

## API request

Send an authenticated `POST` request to `https://hcti.io/v1/image`. Include `html`, optional `css`, `format`, and any viewport or browser options required by the render.

```json
{
  "html": "\u003Carticle class=\u0027card\u0027\u003E...\u003C/article\u003E",
  "css": ".card { display: grid; width: 1200px; }",
  "format": "webp",
  "viewport_width": 1200,
  "viewport_height": 630
}
```

## Request workflow

1. **Send HTML and CSS** — Submit the content with format set to webp and any viewport or browser settings.
2. **Chromium renders the design** — The API loads the markup, styles, fonts, and assets in a managed browser environment.
3. **Use the .webp URL** — Embed the hosted result, download the file, or save it in your own storage and application records.

## Authentication and output handling

- Authenticate from trusted server-side code. Do not expose an API key in browser JavaScript, generated HTML, logs, or agent-visible output.
- Treat the returned URL as the generated `webp` resource. Download it, embed it, or copy it to configured storage as required by the workflow.
- Use viewport, selector, timing, and browser options when the default capture does not match the required dimensions or page state.
- If credentials are unavailable, ask the user to configure them securely before attempting an API request.

## Use through MCP

An MCP-compatible agent can connect to `https://mcp.hcti.io` with OAuth and use the connected HTML/CSS to Image account instead of handling an API key directly.

Ask the MCP tool to render the supplied HTML and CSS as WebP, or specify `format: webp` explicitly when constructing the request.

- [Read the MCP integration documentation](https://docs.htmlcsstoimage.com/integrations/mcp/)

## Related conversions

- [URL to WebP](https://htmlcsstoimage.com/features/url-to-webp/csharp-client.md): Capture a public webpage as WebP instead of supplying HTML and CSS.
- [HTML to PNG](https://htmlcsstoimage.com/features/html-to-png/csharp-client.md): PNG preserves sharp edges, text, and transparency, making it ideal for interface captures and designed graphics.
- [HTML to JPEG](https://htmlcsstoimage.com/features/html-to-jpeg/csharp-client.md): JPEG is a practical choice for photographic and content-rich images where broad compatibility and smaller files matter.
- [HTML to PDF](https://htmlcsstoimage.com/features/html-to-pdf.md): Generate paginated documents with page sizing, margins, backgrounds, and print styles.

## Reference links

- [API authentication and request documentation](https://docs.htmlcsstoimage.com/getting-started/using-the-api/)
- [MCP integration documentation](https://docs.htmlcsstoimage.com/integrations/mcp/)
- [Interactive HTML to WebP page](https://htmlcsstoimage.com/features/html-to-webp/csharp-client)
- [Plans and current limits](https://htmlcsstoimage.com/pricing.md)
