Skip to content

break-before: page not working on elements inside <article> container #2850

Description

@teknosysGit

WeasyPrint version: 68.1
Problem:
We are generating PDFs from a combined HTML document using mkdocs-with-pdf. All content is wrapped inside <article> and <section> tags. We need to insert manual page breaks at specific positions but break-before: page is being ignored on elements inside <article> containers.
What we tried:

Empty div:

<div style="break-before: page; page-break-before: always;"></div>

Div with non-breaking space:

<div style="break-before: page; page-break-before: always;">&nbsp;</div>

CSS class:

css.page-break {
  break-before: page !important;
  page-break-before: always !important;
  display: block !important;
  height: 0;
}

Hidden h2 heading with zero height and font-size:

<h2 class="page-break-hidden">&nbsp;</h2>
h2.page-break-hidden {
  break-before: page !important;
  height: 0 !important;
  font-size: 0 !important;
  line-height: 0 !important;
  visibility: hidden !important;
}

None of these approaches work inside an <article> container.
What works:
break-before: page on actual content headings (<h1>, <h2>) with visible text is respected. But this causes side effects with running headers via string-set.
Minimal reproduction:

<article>
  <p>Some content here.</p>
  <div style="break-before: page;">&nbsp;</div>
  <p>This should start on a new page but does not.</p>
</article>

Question:
Is there a supported way to force a manual page break at an arbitrary position inside an <article> container?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions