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.

CSS box sizing can change the dimensions a converter writes into a DOCX, but Word does not apply the browser’s CSS box model. A browser’s content-box width excludes padding and borders; border-box includes them. DOCX stores WordprocessingML structures instead of a universal CSS cascade, and Word or another DOCX renderer lays those structures out according to page, table, paragraph, image, and compatibility rules. A converter must translate between the models, so widths, wrapping, and pagination can differ even when the source HTML looks correct.

Why CSS box sizing does not carry over directly

CSS describes a box with a content area and optional padding, border, and margin around it. Under the default content-box behavior, a declared width measures the content area; padding and borders add to the outer dimensions. With border-box, the declared width includes the content, padding, and border. The W3C CSS2 box model describes those areas, and MDN identifies content-box as the default.

A DOCX document has a different underlying model. Microsoft’s Open XML documentation describes a WordprocessingML document as a <document> and <body> containing block-level elements such as paragraphs; paragraphs contain runs, and runs contain text. There is no single universal CSS cascade or DOCX box-sizing property for Word to apply. The HTML-to-DOCX converter has to map CSS dimensions onto WordprocessingML constructs, after which the target application performs its own layout.

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

That distinction matters: box-sizing: border-box may affect how a converter interprets a CSS width, but it is not a command that forces every DOCX renderer to preserve a browser’s outer box dimensions. Nor does matching a CSS width alone guarantee matching line breaks, table geometry, or page breaks.

Where the width differences come from

Content width versus outer width

Suppose an element has width: 600px, horizontal padding of 20px on each side, and a 1px border on each side. With content-box, its outer width is 642px: 600px of content, 40px of padding, and 2px of border. With border-box, the outer width remains 600px, leaving 558px for content after padding and borders. A converter that uses the content width where the DOCX layout needs the outer width—or vice versa—can make the result wider or narrower than intended.

This arithmetic is a useful diagnosis, not a guarantee of how a particular converter maps CSS pixels into WordprocessingML. Check the converter’s behavior and inspect the output in the renderer your readers actually use.

Rank #2
Sale
The Microsoft Office 365 Bible: The Most Updated and Complete Guide to Excel, Word, PowerPoint, Outlook, OneNote, OneDrive, Teams, Access, and Publisher from Beginners to Advanced
  • The Microsoft Office 365 Bible: The Most Updated and Complete Guide to Excel, Word, PowerPoint, Outlook, OneNote, OneDrive, Teams, Access, and Publisher from Beginners to Advanced
  • ABIS BOOK

Page dimensions, margins, gutter, and columns

In DOCX, section properties define page size, margins, headers, footers, columns, and gutter. The space available to body text is not necessarily the full page width: start with the page width and subtract the left and right margins and gutter. If the section uses columns, those columns divide the remaining space. A width that fit the browser viewport may therefore exceed the text area of the DOCX page or of an individual column.

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

The docx.js API reference documents an example A4 page width of 11,906 twips (8.27 inches) and default margins of 1,440 twips (1 inch) each. For that example, subtracting the two margins leaves 9,026 twips—about 6.27 inches—before accounting for a gutter or columns. These are figures from that API example, not universal DOCX defaults; check the actual section settings in the document you generate.

Percentages use a different reference

In CSS, a percentage width is resolved against a containing block according to CSS layout rules. For WordprocessingML tables, percentage widths are calculated against the page’s text extents, excluding margins. Those reference widths are not interchangeable. A percentage-based table or cell can therefore take up a different share of the available space after conversion than it did in the browser.

Tables negotiate their widths

WordprocessingML’s tblW is a preferred table width used as part of the table-layout algorithm, not a promise that the table will retain an exact CSS width. The table’s grid columns and competing width preferences can affect the result; the algorithm may override an individual preference. Long text, cell padding, borders, and the width available on the page can also force wrapping or resizing.

This is why a table that appears fixed in CSS may overflow, wrap, or change proportions in a DOCX. Treat a requested table width as a target within the document’s usable text area, then verify the generated result.

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

Floating shapes and images add positioning rules

Floating and legacy VML shapes introduce another coordinate system. The docx.js VML style type exposes height, width, and positioning relative to page, margin, text, or character. Images and text boxes may consequently shift or clip even when ordinary paragraph text looks right. A paragraph’s correct width does not prove that a floating object’s position or size is correct.

A reliable way to size content for DOCX

  1. Identify the target section. Record its page size, left and right margins, gutter, and column layout. Do not assume the browser viewport is the DOCX content area.
  2. Calculate the usable width. Subtract the margins and gutter from the page width; if there are columns, account for the width available to the relevant column. Use the document’s actual section values.
  3. Choose the width meaning. For each element, decide whether the design’s width refers to the content alone or to the outer border box. For content-box, add padding and borders to get the outer width. For border-box, subtract them to find the content width.
  4. Set table targets within the available width. Map tables to the text area and remember that WordprocessingML table widths are preferences subject to the table-layout algorithm. Avoid assuming an individual cell width will prevail when it conflicts with the table grid or other constraints.
  5. Check content that changes wrapping. Review long words, cell padding, borders, images, and floating shapes. These can make a design overflow or reflow even if the nominal widths appear to fit.
  6. Render in the destination application or conversion engine. Inspect the actual DOCX in the software or service your audience will use. Standards describe structures and algorithms; implementations can differ.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Compare the layout models when diagnosing a mismatch

Question Browser CSS DOCX / WordprocessingML
What does a declared width include? With content-box, the content only; with border-box, content, padding, and border. No universal CSS box-sizing rule; the converter maps dimensions to DOCX structures and the renderer lays them out.
What is the reference for percentages? A containing block governed by CSS layout. For table percentage widths, page text extents excluding margins.
How do padding and borders affect width? They add to a content-box width and are included in a border-box width. The result depends on the converter’s mapping and DOCX layout; verify in the target renderer.
Are table widths exact? CSS sizing applies in the browser’s layout context. tblW is a preferred width used by the table-layout algorithm; grid columns and conflicting preferences can change the outcome.
How are floating objects positioned? By CSS positioning and containing-block rules. Floating/VML positioning can be relative to page, margin, text, or character.
What controls line breaks and pages? Browser layout, available width, font metrics, and content. DOCX paragraph, table, page, and renderer rules; a changed available width can alter wrapping and pagination.

Use a browser screenshot as a source-layout check

A browser screenshot can help determine whether the HTML already has the intended dimensions before conversion. Compare it with the rendered DOCX to locate where the layouts diverge. A screenshot records the browser view; it does not validate WordprocessingML or substitute for opening the DOCX in its destination renderer.

Or skip the browser setup

To capture the source page with one GET request, use ScreenshotNeo’s API documentation for parameter and response details. This example saves a WebP screenshot; change the target URL as needed:

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 banners, popups, and chat widgets before the shot; those cleanup steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and the response includes X-Page-Verdict and X-Billed headers. Its MCP server gives AI agents tools to take screenshots, get page information, and capture PDFs. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. These features are for capturing and inspecting web pages, not for guaranteeing DOCX layout fidelity. Learn about ScreenshotNeo, or sign up for 1,000 free screenshots a month with no card.

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

Troubleshoot common DOCX sizing symptoms

Symptom Likely cause What to check or change
A box or table is wider than expected. The source used content-box, so padding and borders added to the declared width; alternatively, the converter or table algorithm resolved competing width preferences differently. Recalculate the outer width, compare it with the section’s usable text width, and inspect the rendered table rather than relying on its requested width alone.
A table wraps or columns change size. Its available DOCX text area differs from the CSS containing block, or table grid and width preferences interact. Check section margins and columns, percentage-width reference, cell padding, long words, and the rendered output.
Line breaks differ although the page looks similar. The usable line width or content width changed during conversion; paragraph and renderer behavior also affect wrapping. Compare the actual content area after padding and borders, then inspect the DOCX in the target application.
An image or text box moves or clips while text is correct. A floating object uses a position relative to a page, margin, text, or character, rather than the paragraph’s ordinary flow. Inspect the object’s size and positioning reference, then render the document again in its destination application.
The DOCX looks different in two applications. DOCX structures are rendered by the target application’s own page, table, paragraph, drawing, and compatibility rules. Test in the application or conversion engine that matters for delivery; do not infer its output solely from a browser preview.

Frequently Asked Questions

Does a DOCX file contain the original HTML and CSS box model?

The WordprocessingML structure described by Microsoft represents document, body, paragraph, run, and text elements; DOCX does not provide a universal CSS cascade or a general box-sizing property.

Can one browser preview prove what every DOCX reader will see?

No. A browser preview shows CSS layout, while a DOCX is laid out by the application or conversion engine that opens it. Check the actual target renderer.

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.