Screenshot a single element of a page by its CSS selector
To screenshot an element by CSS selector, you name the node and the API returns an image of exactly that box. No full-page capture, no cropping math. It fits a chart headed for a weekly report, a pricing table in a competitor comparison, a component in your documentation or a widget in a changelog. The screenshot.element option crops the capture to the matching node and waits until it is visible.
Cropping a full-page screenshot by coordinates is guesswork
You rarely need the whole viewport. You need the revenue chart, the plan comparison or the embedded map, at its real size, every day. A full capture forces a second step: find where the element landed and cut it out.
Cropping by coordinates breaks the moment the page adds a banner, swaps a font or renders at a different width. You end up with half a chart or a strip of the neighboring section. Image-processing code to detect the region is a second system to maintain, and it still fails when the element renders late.
Selecting the node is stable. With screenshot.element the browser finds the element, waits for it to appear and be visible, and captures exactly its box. Add omitBackground and the default white background is dropped, so the image comes back transparent around the element.
How to screenshot an element with a CSS selector
One option selects the node. Combine it with the interaction options when the element sits behind a tab or an accordion. The customizing output guide compares element capture with full-page and viewport captures.
import createClient from 'microlink.io'
const microlink = createClient({
apiKey: process.env.MICROLINK_API_KEY
})
const { url, width, height } = await microlink.screenshot(
'https://example.com/pricing',
{ element: '#pricing-table' }
)The capture is cropped to the element matching the selector. The response includes the hosted image URL plus the width and height of the cropped image.
import createClient from 'microlink.io'
const microlink = createClient({
apiKey: process.env.MICROLINK_API_KEY
})
const { url } = await microlink.screenshot('https://example.com', {
element: '.logo',
omitBackground: true
})omitBackground drops the default white background. Keep the default PNG type, because JPEG has no transparency.
import createClient from 'microlink.io'
const microlink = createClient({
apiKey: process.env.MICROLINK_API_KEY
})
const { url } = await microlink.screenshot('https://example.com/pricing', {
click: '#tab-annual',
element: '#pricing-table'
})click changes the page state before the capture, so the element is captured the way it looks after the interaction.
curl 'https://api.microlink.io/?url=https%3A%2F%2Fexample.com%2Fpricing&meta=false&screenshot.element=%23pricing-table'Dot notation turns nested screenshot options into query parameters, so screenshot.element works from any language or straight from an img tag.
- screenshot.element CSS selector of the element to capture. Waits for it to appear and be visible.
- screenshot.omitBackground Omits the default white background for a transparent capture. Off by default; PNG only.
- click Clicks a selector first, to open the tab or accordion that contains the element.
- scroll Scrolls to a selector while keeping a viewport-sized capture, for a section shown in context.
element crops the image; scroll only moves the viewport. Use element for a widget and scroll for a section you want to show with its surroundings.
Why a selector beats cropping a full screenshot
The selector is a contract with the page, not with its pixels. That gives a screenshot of a specific element three practical advantages.
When the element depends on data that arrives later, the JavaScript-rendered pages recipe covers waiting for a child selector or a network event.
The response still reports the width and height of the image, so it drops into a layout without measuring. Compare the options in the full page capture reference.
When not to: if a sticky header or a modal covers the element, the overlap shows up in the capture. Hide it with styles or dismiss it with click first, as in the cookie banner recipe.
FAQ
How do I screenshot a specific element with a CSS selector?
What if my element screenshot selector matches several nodes?
Can I screenshot an element inside an iframe?
Why is my element screenshot blank or cut off?
Can I get a transparent screenshot as JPEG?
Solve the next problem with the same API
Screenshots without cookie banners or ads
Screenshots of JavaScript-rendered pages
Mobile screenshots at any viewport
Faster, smaller screenshots
Screenshots with a browser frame
Clean Markdown, no boilerplate
Ready to capture just the element?
One selector, one image, no cropping math. Start on the free endpoint and capture a chart, a table or a component in a single call.