IronPDF How-Tos CSS (Screen & Print) How to use CSS with HTML Chaknith Bin Updated:July 28, 2025 The CSS 'screen' media type is primarily intended for display on computer screens and similar devices. When styles are defined for the 'screen' media type, they affect how web content is presented on screens, emphasizing visual design and interactivity. In contrast, the CSS 'print' media type is designed for printing. It determines how the web page will appear when printed, with a focus on optimizing content for the printed page. This optimization may include adjusting font sizes, margins, and removing or hiding elements that are not relevant or necessary when printed. How to use Responsive CSS with HTML Download the IronPDF C# library for CSS and HTML integration Prepare the HTML file for conversion to PDF Specify CSS media type for optimal PDF formatting Set CSS media type 'Print' for repeated table headers in PDFs Configure viewport dimensions for responsive design Get started with IronPDF Start using IronPDF in your project today with a free trial. First Step: Start for Free Screen & Print CSS Types (CSS3) IronPDF generates PDFs from HTML in C# and can effortlessly render a screen stylesheet to a PDF by default. This is convenient because print stylesheets are often less well-documented, used, or developed compared to their screen counterparts. CSS3 allows certain CSS styles to be rendered exclusively in printed documents, while others are intended for web browsers. IronPDF can be programmed to work with either. Create and apply a print stylesheet to your HTML: Learn how to create and apply a perfect print stylesheet.. It is very hard to say which CSS media type is better since each type targets different use cases. It is worth trying each one through trial and error to see which is suitable for your requirement. Repeat Table Headers When dealing with HTML tables that span multiple pages, set the CssMediaType property to PdfCssMediaType.Print. This ensures that the table header is repeated at the top of each extended page. In contrast, PdfCssMediaType.Screen instructs Chrome to print the headers only once. To make sure Chrome detects the table header, it should be enclosed in a <thead> tag. Let's render the 'tableHeader.html example of repeating table headers' HTML file to PDF to see the effect. :path=/static-assets/pdf/content-code-examples/how-to/html-to-pdf-responsive-css-table-header.cs using IronPdf; using IronPdf.Rendering; ChromePdfRenderer renderer = new ChromePdfRenderer(); // Change the paper size to small renderer.RenderingOptions.SetCustomPaperSizeinPixelsOrPoints(600, 400); // Choose screen or print CSS media renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print; // Render HTML to PDF PdfDocument pdf = renderer.RenderHtmlFileAsPdf("tableHeader.html"); pdf.SaveAs("tableHeader.pdf"); Imports IronPdf Imports IronPdf.Rendering Private renderer As New ChromePdfRenderer() ' Change the paper size to small renderer.RenderingOptions.SetCustomPaperSizeinPixelsOrPoints(600, 400) ' Choose screen or print CSS media renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print ' Render HTML to PDF Dim pdf As PdfDocument = renderer.RenderHtmlFileAsPdf("tableHeader.html") pdf.SaveAs("tableHeader.pdf") $vbLabelText $csharpLabel Frequently Asked Questions How can I convert HTML to PDF with responsive design? You can convert HTML to PDF with responsive design using IronPDF by first downloading the IronPDF C# library. Then, prepare your HTML file, specify the appropriate CSS media type, and configure viewport dimensions to ensure the PDF is responsive across different devices. What is the difference between CSS 'screen' and 'print' media types? The CSS 'screen' media type is used for displaying content on digital screens, focusing on visual design and interactivity. In contrast, the 'print' media type optimizes content for printed materials by adjusting elements like font sizes and margins, making it suitable for physical printouts. How do you ensure table headers repeat on each page in a PDF? To ensure that table headers repeat on each page in a PDF, set the CssMediaType property to PdfCssMediaType.Print and enclose the table header in a <thead> tag. This ensures consistent header representation across multiple pages. Can IronPDF handle both screen and print stylesheets? Yes, IronPDF can handle both screen and print stylesheets. It allows for rendering PDFs from HTML with either media type, ensuring flexibility based on whether the output is intended for digital screens or print. What are the benefits of using a print stylesheet when converting HTML to PDF? A print stylesheet is beneficial when converting HTML to PDF as it ensures the content is optimized for print. This includes adjustments to font sizes and margins, making sure the PDF is formatted correctly for physical printouts. How do you implement responsive CSS in a PDF using a C# library? To implement responsive CSS in a PDF using IronPDF, download the IronPDF C# library, prepare your HTML content, specify the desired CSS media type, and adjust viewport dimensions to ensure the PDF adapts to various devices. Why is it important to use the correct CSS media type for PDFs? Using the correct CSS media type is important for PDFs because it determines how the content is rendered. 'Screen' media type is suited for digital displays, while 'print' media type ensures content is optimized for paper, affecting elements like layout and readability. Chaknith Bin Chat with engineering team now Software Engineer Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience. Ready to Get Started? Free NuGet Download Total downloads: 15,080,714 View Licenses