How to Remove Left and Right Padding in a SwiftUI List

Written by

in

Quick answer: Apply .listRowInsets(EdgeInsets()) to the row content, not to the List itself, and set .listStyle(.plain) so the grouped-style side margins go away. If the insets are ignored, build the list with List { ForEach(items) { ... } } instead of List(items) { ... }.

Why this happens

A SwiftUI List is not a stack of plain views. It is backed by a UIKit collection view, and every row gets default content insets from the list style in use. On top of that, the insetGrouped and grouped styles add horizontal margins around the whole list, which is why a row looks like it has a border on the leading and trailing edges even when your own HStack has no padding at all.

The modifier that controls the per-row insets is listRowInsets(_:). It has to be applied to the row content, and it has to be applied to a view that the list actually treats as a row. When you write List(items) { item in ... }, SwiftUI wraps your closure in its own row container, and a listRowInsets placed there can be swallowed. That is the reason the same modifier appears to do nothing in one initializer and works perfectly in another.

So there are two separate things to fix: the row insets, and the list style’s outer margins. Most people only fix one of them and conclude the modifier is broken.

How to fix it

1. Put .listRowInsets(EdgeInsets()) on the row content

This is the direct fix. Zero out the insets on the view that represents the row:

struct ItemRow: View {
    let item: Item

    var body: some View {
        HStack(spacing: 12) {
            Image(systemName: item.icon)
            Text(item.title)
            Spacer()
        }
        .padding(.vertical, 8)
        .listRowInsets(EdgeInsets())
    }
}

EdgeInsets() defaults every edge to zero, so the row now spans the full width of the list. If you only want to kill the horizontal padding and keep a little breathing room on top and bottom, be explicit:

.listRowInsets(EdgeInsets(top: 8, leading: 0, bottom: 8, trailing: 0))

Do not put .listRowInsets on the List itself. It is a row modifier; applied one level up it has no effect.

2. Switch to the List { ForEach } form if the insets are ignored

If step 1 changes nothing, the initializer is the problem. This form is the one that reliably respects row insets:

List {
    ForEach(items) { item in
        ItemRow(item: item)
            .listRowInsets(EdgeInsets())
    }
}

Instead of this:

List(items) { item in
    ItemRow(item: item)
        .listRowInsets(EdgeInsets())   // may be ignored
}

The two produce the same rows, but the ForEach version gives the modifier a row view it can attach to. It also makes it trivial to mix in static rows or sections later.

3. Use a plain list style to drop the outer margins

Zero row insets remove the padding inside each row. The margins around the list itself come from the style. On iOS 14 and later, .plain removes the inset-grouped look entirely:

List {
    ForEach(items) { item in
        ItemRow(item: item)
            .listRowInsets(EdgeInsets())
    }
}
.listStyle(.plain)

.listStyle(PlainListStyle()) is the same thing written with the concrete type. Either is fine; the shorthand is easier to read.

If you are on iOS 13 and cannot use .plain, the default style on iPhone is already plain, and the inset appearance usually comes from running on iPad or in a split view. In that case the ForEach form from step 2 plus zero insets is the whole fix.

4. Check whether the “border” is actually a separator

Sometimes the line people want gone is not padding at all, it is the row separator. On iOS 15 and later you can hide it per row:

ItemRow(item: item)
    .listRowInsets(EdgeInsets())
    .listRowSeparator(.hidden)

To hide separators for the whole list, apply it inside the ForEach on every row, or use .listRowSeparator(.hidden) on the ForEach content. Hiding separators does not change insets, and changing insets does not hide separators, so decide which one you actually need.

5. Give the row a full-width background if you need one

Once the insets are zero, a row background will extend edge to edge. Apply it after the insets so the order is obvious:

ItemRow(item: item)
    .listRowInsets(EdgeInsets())
    .listRowBackground(Color(.secondarySystemBackground))

If you apply .listRowBackground but still see a gap on the left and right, the insets are still non-zero somewhere, usually because a parent view in the row is adding its own .padding(.horizontal, ...).

6. Drop List entirely when you need full layout control

If you are fighting the list for a custom card layout, a ScrollView with a LazyVStack gives you complete control and no implicit insets:

ScrollView {
    LazyVStack(spacing: 0) {
        ForEach(items) { item in
            ItemRow(item: item)
            Divider()
        }
    }
}

You lose swipe actions, automatic row recycling behaviour and the built-in editing affordances, so only take this route when the design genuinely does not look like a list.

How to prevent it

  • Apply .listRowInsets to the row content, never to the List.
  • Prefer List { ForEach(...) { ... } } when you need per-row modifiers to stick.
  • Pair zero insets with .listStyle(.plain); one without the other leaves half the gap.
  • Check for .padding(.horizontal, ...) inside the row view before blaming the list.
  • Decide early whether you want separators; .listRowSeparator(.hidden) is a separate concern from insets.
  • If the design has no list semantics, start with ScrollView + LazyVStack instead of stripping a List down.

FAQ

Why does .listRowInsets(EdgeInsets()) do nothing on my List?

Either it is attached to the List instead of the row, or the list was built with List(items) { ... }, which can wrap the row in a container that swallows the modifier. Move the modifier onto the row view and switch to the List { ForEach } form.

Do I need both .listRowInsets and .listStyle(.plain)?

Usually yes. listRowInsets controls the padding inside each row, while the list style controls the margins around the list and the grouped background. Removing only one leaves a visible gap on the leading and trailing edges.

How do I remove the separator lines as well as the padding?

Use .listRowSeparator(.hidden) on the row, available from iOS 15. It is independent of listRowInsets, so you can hide separators while keeping padding, or remove padding while keeping separators.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.