> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Use Header and Footer elements to detect the beginning and the end of a document

> Detect the first and last pages of multi-page documents with Header and Footer elements, which speed up FlexiLayout matching and improve detection.

To detect the beginning and the end of a document, use **Header** and **Footer** elements. These are compound elements and must be placed at the beginning of the branch of elements. In the tree of elements, **Header** elements are marked with <img src="https://mintcdn.com/abbyy/fmgRWFNHKYN2MLSg/images/flexi-capture/fls/Header.gif?fit=max&auto=format&n=fmgRWFNHKYN2MLSg&q=85&s=5c5ceee2f3fc696ced059d73b34a953b" alt="Header element icon" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="11" height="14" data-path="images/flexi-capture/fls/Header.gif" /> and **Footer** elements are marked with <img src="https://mintcdn.com/abbyy/fmgRWFNHKYN2MLSg/images/flexi-capture/fls/Footer.gif?fit=max&auto=format&n=fmgRWFNHKYN2MLSg&q=85&s=2298792040529fd197452b86920c53a8" alt="Footer element icon" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="11" height="14" data-path="images/flexi-capture/fls/Footer.gif" />.

The **Header** element is positioned on the first page of the document and may not occur on any of the subsequent pages. Select a **Header** element that uniquely identifies the documents described by the FlexiLayout.

The **Footer** element is positioned on the last page of the document and may not occur on the preceding pages.

The **Header** and **Footer** elements are part of the FlexiLayout and their hypotheses may be used to search for other elements.

When applying a multi-page FlexiLayout, the **Header** and **Footer** elements are used to detect the first and last pages of the document respectively.

Using **Header** and **Footer** elements greatly improves document detection and speeds up the FlexiLayout matching process. Be sure to use these elements whenever possible.

## Related topics

* [Header and Footer](/flexi-capture/fls/template/elements-header-footer)
* [Match a multi-page FlexiLayout](/flexi-capture/fls/template/multipage-matching)
