---
title: "Padding"
description: "The padding modifier adds padding to a view."
url: https://www.swiftuifieldguide.com/layout/padding
markdown_url: https://www.swiftuifieldguide.com/layout/padding.md
---
> Convenience Markdown export of the HTML page. Interactive samples, diagrams, and visualizations stay on the canonical page.
# Padding

The `padding` modifier adds padding to a view. It does so by taking the proposed size and subtracting the padding. Likewise, it adds padding to the reported size of its child. When we don't specify additional parameters, the default system padding ( on this website) is used, and it's applied to all edges.

> Interactive example on HTML page: Sample0.

We can also specify an explicit value for the padding:

> Interactive example on HTML page: Sample1.

Sometimes, negative padding can be useful to break out of the bounds of a view. In the example below, the background gets proposed the size of the text, but the negative padding makes sure the green rectangle is larger.

> Interactive example on HTML page: Sample Negative Padding.

We can also specify padding for specific edges only. For example, we can indent a view by setting padding on the leading edge:

> Interactive example on HTML page: Indent Sample.

When we're proposing a [nil dimension](/layout/ideal-size) for a view, the padding amount is ignored when we propose to the padding's child. However, when the child reports its size, the padding value is added to the child's size.

> Interactive example on HTML page: Fixed Size Sample.
