Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

If PhantomJS appears to ignore box-sizing: border-box, first check that the declaration reaches the intended element and is applied before you measure it. A screenshot or unexpected offsetWidth alone does not prove the CSS property is unsupported. PhantomJS uses QtWebKit, and behavior can vary between WebKit implementations, so verify computed style and geometry in the exact PhantomJS binary you run.

What “ignoring box-sizing” can mean

box-sizing: border-box makes an element’s declared width include its content, padding, and border. Margins remain outside that width. For example, if an element has a declared width of 200 pixels, 20 pixels of padding on each side, and 2-pixel borders, its border-box width should be 200 pixels—not 244 pixels. The content area shrinks to make room for padding and borders.

That distinction matters because a page can look wider than expected without the property being ignored: margins, a child element, flex or grid sizing, transforms, or another layout rule can affect the visible result. Likewise, a computed width may represent the content box rather than the total outer geometry. Inspect the CSS value and the measurements separately before diagnosing an engine bug.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

PhantomJS is built on QtWebKit. The PhantomJS documentation cautions that support can vary across WebKit implementations and recommends testing the feature in the target implementation. Its FAQ also says the WebKit version depends on the libraries used when the binary was compiled; that version alone is not a reliable way to infer HTML or CSS support. The project homepage says development is suspended.

Isolate the problem with a minimal test

Reduce the page to one element and one stylesheet rule. Remove unrelated layout rules, scripts, and framework styles temporarily. This tells you whether the problem is the property itself or something about the full page.

<!doctype html>
<html>
<head>
  <style>
    #probe {
      box-sizing: border-box;
      width: 200px;
      padding: 20px;
      border: 2px solid black;
      margin: 0;
    }
  </style>
</head>
<body>
  <div id="probe">Box-sizing test</div>
</body>
</html>

In a conforming result for this fixture, the declared width includes the padding and borders. Compare the result in the PhantomJS executable used by your job, not just in a current desktop browser. Keep the fixture unchanged when you compare runs so that the browser binary is the only variable.

Check selector, stylesheet, cascade, and timing

  1. Confirm the node exists. Make sure the selector matches the element you intend to inspect. A correct rule applied to a different node has no effect on the measured element.
  2. Confirm the stylesheet loaded. Check the stylesheet request and its response, and make sure the rule is not in a file that failed to load, was blocked, or was not included in the page PhantomJS actually opened.
  3. Inspect the winning declaration. Look for a later rule, a more specific selector, an inline style, or a script that changes the element’s class or style. A declaration in the source stylesheet is not necessarily the computed value after the cascade.
  4. Wait until the page is ready to measure. If the page injects CSS, changes classes, or creates the element with JavaScript, an early measurement can capture the pre-change state. Take the measurement after the relevant stylesheet and script-driven updates have completed.

In the page’s JavaScript context, inspect the computed style for the exact element:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
var el = document.getElementById('probe');
var style = window.getComputedStyle(el);
console.log('boxSizing:', style.boxSizing);
console.log('webkitBoxSizing:', style.webkitBoxSizing);
console.log('computed width:', style.width);
console.log('offsetWidth:', el.offsetWidth);
console.log('padding:', style.paddingLeft, style.paddingRight);
console.log('border:', style.borderLeftWidth, style.borderRightWidth);
console.log('margin:', style.marginLeft, style.marginRight);

If your diagnostic context does not expose one of the style properties, record that fact rather than assuming a value. The useful evidence is the computed value the engine reports alongside the element’s actual dimensions and the CSS that won the cascade.

Measure the right box

Record at least the computed width, offsetWidth, left and right padding, left and right border widths, and margins. Do not infer the box model from a screenshot alone: screenshots show rendered pixels, while CSSOM measurements report layout values, and the two can be affected by different factors.

  • box-sizing affects how the declared width and height relate to the content, padding, and border.
  • Margins are outside the border box and are not included in a border-box width.
  • offsetWidth describes the layout box’s width, including padding and borders, rather than the margin area.
  • A computed width should be interpreted alongside the computed box-sizing value and the other measurements; do not treat one reported number as proof of the whole layout.

For the minimal fixture, use zero margins to remove one common source of confusion. If the fixture behaves as expected but the real page does not, restore the page’s styles in groups until the conflicting rule or timing issue returns.

Try the WebKit-prefixed declaration as a diagnostic

On the affected selector, test both declarations together:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
-webkit-box-sizing: border-box;
box-sizing: border-box;

Rerun the same minimal fixture in the exact PhantomJS binary and compare the computed style and geometry. This is a compatibility check, not a guaranteed fix. The PhantomJS guidance is to test the feature in the target implementation rather than assume support from a WebKit version or family resemblance.

If the prefixed declaration changes the result, retain it only if it is appropriate for the project’s supported browsers and validated by your tests. If it does not change the result, return to the computed style, stylesheet, cascade, and timing checks before concluding that the engine cannot handle the property.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

When PhantomJS itself is the likely cause

If a minimal case still disagrees with the expected box model after the selector, stylesheet, cascade, and measurement timing have been verified, capture enough detail to reproduce the issue:

  • the PhantomJS version and the exact binary or build provenance;
  • the operating system and how the binary was obtained or compiled;
  • the minimal HTML, CSS, and diagnostic output;
  • the computed style values and geometry from the run.

The build details matter because PhantomJS’s FAQ notes that the WebKit version depends on compile-time libraries. Do not use that version number alone as evidence that a CSS feature must work identically. If the confirmed engine limitation blocks the project, moving rendering or tests to a maintained browser automation stack is the practical long-term option. If migration is not possible, pin the existing binary and keep the minimal fixture as a regression test so that environment changes are visible.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

If your goal is to obtain a website screenshot rather than diagnose the exact PhantomJS layout, ScreenshotNeo offers a screenshot API and MCP server. It is not a fix for PhantomJS or a way to guarantee that another renderer will produce the same output. One GET request can return an image or PDF; here is the supplied cURL form, adapted to the test page:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo documentation for API parameters and setup. Before capture, it accepts the cookie or consent banner like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failure patterns and fixes

Symptom Likely explanation What to check
Computed style is not border-box The rule did not apply, lost in the cascade, or had not been applied when measured. Verify selector match, stylesheet load, later declarations, and script timing.
Computed style is border-box, but the page looks too wide The measured or visible width may include something outside the border box, or other layout rules may be involved. Compare offsetWidth, padding, borders, margins, and surrounding layout.
Only the full application fails; the minimal fixture works A page-specific rule, script, or timing dependency is more likely than the property alone. Restore styles and scripts incrementally until the behavior changes.
Prefixed and unprefixed declarations disagree The target build may handle prefixed syntax differently. Compare both computed properties and geometry in the exact binary; preserve the test case.
Different machines produce different results The PhantomJS binary or its compiled libraries may differ. Record version, build provenance, OS, and fixture; pin the binary if retaining it.

Choosing between a workaround and migration

Keep PhantomJS only when the pinned binary reliably produces the CSS behavior the project needs and the regression fixture continues to pass. A local prefix or stylesheet adjustment is reasonable when testing shows it fixes the specific target build without breaking other supported browsers. When a minimal reproduction confirms an engine limitation—or the project needs browser behavior that the suspended PhantomJS project cannot maintain—move the rendering or test job to a maintained browser automation stack. The available evidence here does not establish which replacement product is best for a particular project; choose against your page requirements and migration constraints.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Does ScreenshotNeo reproduce PhantomJS’s rendering exactly?

No exact rendering equivalence is established. ScreenshotNeo is an alternate screenshot API, not a PhantomJS compatibility layer; compare its output with your required target before switching a workflow.

Should I report the WebKit version as the sole reproduction detail?

No. Include the PhantomJS binary or build provenance, operating system, minimal fixture, and measured values because the WebKit version alone does not establish CSS support.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.