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.

If PhantomJS appears to ignore box-sizing: border-box, first check that the intended element received the rule, the stylesheet loaded, and your measurement ran after styles were applied. Then compare the element’s computed style with its actual dimensions in the exact PhantomJS binary you use. A prefixed declaration is worth testing, but it is not a guaranteed fix: PhantomJS runs on QtWebKit, and behavior can vary between WebKit implementations.

What “ignoring box-sizing” can mean

box-sizing controls which parts of an element’s box are included in its declared width or height. With border-box, the declared width includes the content, padding, and borders. Margins remain outside that width. For example, an element with a declared width of 200 pixels, 20 pixels of padding on each side, and 5-pixel borders should have an outer border-box width of 200 pixels; the content area is correspondingly narrower.

An apparent mismatch does not, by itself, show that PhantomJS lacks support for the property. The rule may not apply at all, a later declaration may override it, a measurement may happen before styles finish loading, or the inspected number may describe something other than the border box. A screenshot alone cannot distinguish these causes.

Build a minimal test case

Strip the problem down before changing the application’s layout. Create one element with an explicit width, padding, border, and box-sizing rule. Remove unrelated layout rules, scripts, and dynamically loaded styles while testing. This makes it easier to see whether the cause is the CSS, timing, measurement, or the PhantomJS build.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<!doctype html>
<html>
<head>
  <style>
    #probe {
      box-sizing: border-box;
      -webkit-box-sizing: border-box;
      width: 200px;
      padding: 20px;
      border: 5px solid #333;
      margin: 0;
    }
  </style>
</head>
<body>
  <div id="probe">Box-model test</div>
</body>
</html>

The standard and prefixed declarations are both included as a compatibility diagnostic. Test the case in the PhantomJS binary that runs your job; do not assume the prefix makes the behavior correct. Keep a separate control element using content-box if you want to compare the two models under the same conditions.

Check the selector, stylesheet, and cascade

  1. Confirm the target exists. Check that the selector matches the element you are measuring. A typo, an unexpected duplicate ID, or a script that replaces the node can leave you inspecting a different element from the one styled by the rule.
  2. Confirm the stylesheet loaded. Inspect the page’s network or loading behavior and verify the CSS file request succeeded. For a quick diagnostic, move the minimal rule into an inline style block as in the fixture. If that works but the linked stylesheet does not, focus on the request path, response, or stylesheet application rather than the box model.
  3. Inspect competing declarations. Search for other rules that set box-sizing, including rules with a more specific selector or one that appears later in the cascade. Check styles applied through inline declarations and dynamically added classes too.
  4. Check when measurement occurs. If your code measures the element before the stylesheet, page content, or a script-driven class change has finished, it may capture an intermediate layout. Wait for the relevant loading or application step, then measure again.

When testing a live page, inspect the computed style of the exact node rather than only searching the source CSS. A declaration in a file is not proof that the browser applied it to the element.

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

Inspect computed style and geometry separately

Read the computed value and the geometry in separate fields. getComputedStyle(el).boxSizing reports the computed box-sizing value where exposed. Also inspect getComputedStyle(el).webkitBoxSizing when the engine exposes it. Then record the measured dimensions and the contributing padding and border values. This reveals whether the rule failed to apply or whether the rule applied but the chosen measurement was misunderstood.

Here is a small PhantomJS script that runs the fixture in a page and prints the relevant values. Save the fixture as box-sizing-test.js and run it with the same PhantomJS executable used by the failing job:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
var page = require('webpage').create();

page.content = '<!doctype html>' +
  '<style>' +
  '#probe {' +
  '  -webkit-box-sizing: border-box;' +
  '  box-sizing: border-box;' +
  '  width: 200px;' +
  '  padding: 20px;' +
  '  border: 5px solid #333;' +
  '  margin: 0;' +
  '}' +
  '</style>' +
  '<div id="probe">Box-model test</div>';

var result = page.evaluate(function () {
  var el = document.getElementById('probe');
  var style = window.getComputedStyle(el);

  return {
    found: !!el,
    boxSizing: style.boxSizing,
    webkitBoxSizing: style.webkitBoxSizing,
    computedWidth: style.width,
    offsetWidth: el.offsetWidth,
    paddingLeft: style.paddingLeft,
    paddingRight: style.paddingRight,
    borderLeftWidth: style.borderLeftWidth,
    borderRightWidth: style.borderRightWidth,
    marginLeft: style.marginLeft,
    marginRight: style.marginRight
  };
});

console.log(JSON.stringify(result, null, 2));
phantom.exit();

With the fixture’s intended border-box behavior and no other layout effects, the outer width should be about 200 pixels. offsetWidth is a useful integer geometry check; it is not a substitute for recording the computed style and box components. The computed width field can be reported differently from the outer geometry, so do not treat a single width value as conclusive. If the selector is missing, the script’s found field will be false and the style values will not diagnose the intended element.

Try the vendor-prefixed declaration as a diagnostic

For an older WebKit-based engine, test both declarations on the affected selector:

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
-webkit-box-sizing: border-box;
box-sizing: border-box;

Rerun the minimal fixture in the same PhantomJS binary and compare the computed values and geometry before and after adding the prefix. If the result changes, the prefix may be useful for that tested build and page. If it does not, do not keep adding unrelated CSS in the hope of forcing the result; return to selector, stylesheet, cascade, timing, and measurement checks.

PhantomJS documentation identifies QtWebKit as its rendering foundation and cautions that feature behavior can differ between WebKit implementations. Its supported-standards guidance recommends feature detection and testing in the target implementation. A WebKit version number alone is not proof that a particular CSS behavior works in your compiled PhantomJS build.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Record the build and decide whether to retain PhantomJS

If the isolated case still disagrees with the expected box model, record the PhantomJS version, the binary’s build provenance, operating system, fixture, and stylesheet. The PhantomJS FAQ notes that the WebKit version depends on the libraries used at compile time, so the version is not a reliable shortcut for inferring HTML or CSS support.

The PhantomJS project homepage reports that development is suspended. If you confirm an engine limitation, consider moving the rendering or test job to a maintained browser automation stack. No current official support or capability listing for a particular replacement is provided, so evaluate candidates against your own page and test requirements.

  • Keep a pinned legacy binary when the project cannot migrate and the current build still meets the remaining requirements. Preserve the minimal fixture as a regression check so a binary or dependency change does not silently alter layout behavior.
  • Plan a migration when the confirmed engine limitation blocks required CSS behavior or continued maintenance matters to the job. Test representative pages and assertions in the candidate environment before switching production or CI rendering.

Troubleshooting symptoms and fixes

Symptom Likely cause to check Next action
boxSizing is not border-box The selector missed, the stylesheet did not apply, or another declaration won the cascade. Confirm the element, load the minimal inline fixture, and inspect competing declarations.
The computed style is correct but the measured width looks wrong The measurement may not represent the outer border box, or padding, borders, margins, or layout effects were not accounted for. Record offsetWidth, computed width, padding, border widths, and margins independently.
The value changes between runs Measurement may happen before styles or script-driven class changes finish, or the runs may use different binaries or environments. Wait for the relevant page state and record the exact binary and fixture for each run.
Adding the prefix changes nothing The cause may not be vendor-prefix support; it may be the cascade, loading, timing, measurement, or engine behavior. Use the minimal fixture to isolate those causes; do not assume the prefix is a universal fix.
The issue appears only in one machine or CI job The PhantomJS binary or its compiled WebKit dependencies may differ. Compare version, build provenance, operating system, stylesheets, and the same fixture across environments.

Or skip the browser setup

If you need a screenshot rather than a computed-style diagnosis, ScreenshotNeo can capture a URL with one request. It does not report computed CSS values, so use the fixture and measurements above to diagnose box-sizing; use this API when the deliverable is a screenshot.

For API parameters and options, see the ScreenshotNeo documentation. This cURL example saves a WebP capture:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers report the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000, and all features are available on every plan.

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

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.