- Docs
- Parameters
- Viewport Params
Viewport Params
Control the size and device characteristics Chrome uses to render your image.
How it works
Section titled “How it works”The viewport is the visible area of the browser page. By default, Chrome renders pages in a 1920x1080 viewport. Use the viewport parameters to render responsive layouts at a specific size or emulate mobile, landscape, and touch behavior.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
viewport_width |
Integer |
Set the viewport width in CSS pixels. Must be used with viewport_height. The maximum width is 6000. |
viewport_height |
Integer |
Set the viewport height in CSS pixels. Must be used with viewport_width. |
viewport_mobile |
Boolean |
Set to true to emulate a mobile viewport and apply the page’s mobile viewport behavior. |
viewport_landscape |
Boolean |
Set to true to render the viewport in landscape orientation. |
viewport_touch |
Boolean |
Set to true to enable touch support in the viewport. |
The three Boolean parameters are optional and default to false. They can be used together, but they do not set the viewport dimensions. Use viewport_width and viewport_height to choose the exact layout size.
Setting viewport width and height
Section titled “Setting viewport width and height”Both dimensions must be included when setting the viewport:
curl -X POST https://hcti.io/v1/image -u 'UserID:APIKey' \ --data-urlencode url="https://example.com" \ --data viewport_width=1200 \ --data viewport_height=630{ "url": "https://example.com", "viewport_width": 1200, "viewport_height": 630}Setting explicit dimensions disables automatic cropping and returns the area rendered inside the viewport. For HTML snippets that should be tightly cropped to their content, set the dimensions in CSS instead.
Emulating a mobile viewport
Section titled “Emulating a mobile viewport”Combine a mobile-sized viewport with mobile emulation:
{ "url": "https://example.com", "viewport_width": 390, "viewport_height": 844, "viewport_mobile": true}viewport_mobile enables Chrome’s mobile viewport behavior, including support for a page’s <meta name="viewport"> settings.
Using landscape orientation
Section titled “Using landscape orientation”viewport_landscape works independently of viewport_mobile. It can be used with mobile, tablet, or desktop-sized viewports.
For example, render a tablet-sized viewport in landscape orientation with touch support:
{ "url": "https://example.com", "viewport_width": 1180, "viewport_height": 820, "viewport_landscape": true, "viewport_touch": true}Add viewport_mobile: true only when you also want Chrome’s mobile viewport behavior.
Enabling touch support
Section titled “Enabling touch support”Set viewport_touch to true to enable touch-capability detection for pages that adapt their controls or interactions for touch devices:
{ "url": "https://example.com", "viewport_width": 390, "viewport_height": 844, "viewport_mobile": true, "viewport_touch": true}Interactions with other parameters
Section titled “Interactions with other parameters”The viewport is Chrome’s virtual screen, measured in CSS pixels. It controls the page layout but does not necessarily determine the final image dimensions.
device_scalechanges the output resolution without changing the CSS viewport size. A1000x1000viewport withdevice_scale: 1.5produces a1500x1500image.full_screencan produce an image taller thanviewport_heightby capturing content below the initial viewport.selectorcrops the final image to a specific element rendered inside the configured viewport.- Automatic cropping controls the bounds of the final image after the page has been rendered.
- The
widthandheightquery parameters can resize the generated image on the fly without changing the viewport or rerendering the page.
Need help?
Talk to a human. Email support@htmlcsstoimage.com and we’ll help you get started.