Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
To convert HTML to GIF in C#, use
Converter.ConvertHTML() with an HTML source,
ImageSaveOptions, ImageFormat.Gif, and an output path. ImageSaveOptions lets you control page setup, background color, resolution, CSS media type, and rendering quality.
This guide shows the core HTML to GIF workflows for C# applications: file-based conversion and custom image rendering options. Before running the examples, install and configure Aspose.HTML for .NET in your project. The complete C# example project is available in the Aspose.HTML for .NET GitHub repository.
GIF is a raster image format commonly used for lightweight web graphics and simple visual assets. Use HTML to GIF conversion when your application needs to render a web page, generated HTML, or template output into a GIF image file.
A typical file-based conversion uses an
HTMLDocument instance, an ImageSaveOptions object configured with ImageFormat.Gif, and Converter.ConvertHTML(). By default, ImageSaveOptions uses PNG as the output image format, so set the format explicitly for GIF output.
The workflow is:
HTMLDocument constructor.ImageSaveOptions instance with ImageFormat.Gif.Converter.ConvertHTML(document, options, savePath) to render the HTML document as a GIF image.The following C# code converts the sample file spring.html to GIF.
1// Convert HTML to GIF using C#
2
3// Prepare a path to a source HTML file
4string documentPath = Path.Combine(DataDir, "spring.html");
5
6// Prepare a path to save the converted file
7string savePath = Path.Combine(OutputDir, "spring-output.gif");
8
9// Initialize an HTML document from the file
10using HTMLDocument document = new HTMLDocument(documentPath);
11
12// Create an instance of the ImageSaveOptions class
13ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Gif);
14
15// Convert HTML to GIF
16Converter.ConvertHTML(document, options, savePath);Use GIF output when compatibility with simple image viewers, lightweight web graphics, or legacy systems matters more than full-color fidelity. GIF is usually not ideal for detailed HTML pages, gradients, screenshots with many colors, or high-quality previews. For sharper lossless rendering, use HTML to PNG. For smaller photographic previews, use HTML to JPG.
For GIF output, create ImageSaveOptions(ImageFormat.Gif) explicitly because the default ImageSaveOptions.Format value is PNG. You can then tune page setup, background color, resolution, antialiasing, and text rendering.
Use
ImageSaveOptions when the output image needs custom rendering settings. The same options class is used for PNG, JPG, BMP, GIF, and TIFF output; for GIF, set Format to ImageFormat.Gif.
| Option | Use it to control |
|---|---|
Format | Output image format, such as PNG, JPG, BMP, GIF, or TIFF. The default value is ImageFormat.Png. |
PageSetup | Output page size and margins used during rendering. |
BackgroundColor | Background fill color. The default value is transparent. |
HorizontalResolution | Horizontal resolution for output images in pixels per inch. The default value is 300 dpi. |
VerticalResolution | Vertical resolution for output images in pixels per inch. The default value is 300 dpi. |
UseAntialiasing | Rendering quality for shapes, text, and images. Antialiasing is enabled by default. |
CSS | CSS media type and related CSS processing options. |
Text | Text rendering options for image output. |
The following example converts HTML to GIF using custom save options such as page setup, background color, resolution, and rendering quality.
1// Convert HTML to GIF in C# with custom background, resolution, and antialiasing settings
2
3string documentPath = Path.Combine(OutputDir, "convert-to-gif.html");
4string savePath = Path.Combine(OutputDir, "convert-to-gif-options.gif");
5
6// Prepare HTML code and save it to a file
7string code = "<h1> HTML to GIF Converter </h1>\r\n" +
8 "<p> GIF is a popular image format that supports animated images and frequently used in web publishing. HTML to GIF conversion allows you to save an HTML document as a GIF image. </p>\r\n";
9
10File.WriteAllText(documentPath, code);
11
12// Initialize an HTML Document from the html file
13using HTMLDocument document = new HTMLDocument(documentPath);
14
15// Initialize ImageSaveOptions
16ImageSaveOptions options = new ImageSaveOptions(ImageFormat.Gif)
17{
18 UseAntialiasing = false,
19 HorizontalResolution = 100,
20 VerticalResolution = 100,
21 BackgroundColor = System.Drawing.Color.MistyRose
22};
23options.PageSetup.AnyPage = new Page(new Aspose.Html.Drawing.Size(500, 200), new Margin(30, 20, 10, 10));
24
25// Convert HTML to GIF
26Converter.ConvertHTML(document, options, savePath);In this example, ImageSaveOptions is passed to Converter.ConvertHTML() together with the loaded HTML document and output path. The sample configures background color, horizontal and vertical resolution, antialiasing behavior, page size, and margins.
Use UseAntialiasing = true when visual smoothness is more important than rendering speed. Use UseAntialiasing = false for simpler, performance-oriented rendering where sharper edges or faster processing are acceptable.
The custom settings example produces a GIF image similar to the following output:

PdfSaveOptions.DocSaveOptions.Use the online HTML to GIF Converter for quick manual conversion. Use Aspose.HTML for .NET when HTML to GIF rendering must run inside a C# application, service, reporting tool, or image-generation workflow.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.