> For the complete documentation index, see [llms.txt](https://help.sdocs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.sdocs.com/sdocs/template-architecture/template-settings/header-and-footer-tabs/multiple-pages-with-different-page-margins.md).

# Multiple Pages with Different Page Margins

Use page-specific CSS when one PDF template needs different margins across pages.

This approach also works when one section needs a different page orientation.

### Problem

You need one generated PDF to use more than one page layout.

Common examples:

* a cover page with wide margins
* an embedded section with no margins
* a landscape page between portrait pages

Standard `body` styling is not enough for this case.

### Solution

Define named `@page` rules in CSS.

Then wrap each section in a `<pagebody>` tag with a matching class name.

S-Docs converts each `<pagebody>` tag to a `body` tag at runtime.

{% code title="multi-page-margins-example.html" %}

```html
<style type="text/css">
@page parentTemplate {
  margin: 1in;
}

body.parentTemplate {
  page: parentTemplate;
}

@page componentTemplate {
  margin: 0in;
  size: landscape;
}

body.componentTemplate {
  page: componentTemplate;
}
</style>

<pagebody class="parentTemplate">
Test Page 1
</pagebody>

<pagebody class="componentTemplate">
Test Page 2
</pagebody>

<pagebody class="parentTemplate">
Test Page 3
</pagebody>
```

{% endcode %}

### How it works

* `@page parentTemplate` sets the first margin profile.
* `@page componentTemplate` sets the second profile.
* `body.parentTemplate` and `body.componentTemplate` map each section to a page profile.
* Each `<pagebody>` block starts a new page context with its assigned settings.

### Example result

In the example above:

* **Test Page 1** uses `1in` margins
* **Test Page 2** uses `0in` margins and landscape orientation
* **Test Page 3** returns to `1in` margins

### Tips

* Keep each `<pagebody>` section self-contained.
* Use clear CSS names when you define multiple page layouts.
* Test the final PDF output, not just template preview.

### Related resources

* Review [PDF Rendering Considerations](/sdocs/template-architecture/document-formats/pdf-templates/pdf-rendering-considerations.md) for broader PDF limitations.
* Review MDN's [CSS `@page` reference](https://developer.mozilla.org/en-US/docs/Web/CSS/@page) for supported page-rule syntax.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.sdocs.com/sdocs/template-architecture/template-settings/header-and-footer-tabs/multiple-pages-with-different-page-margins.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
