NgbModal Container and Body Explained | Generated by AI

Home 2026.02

Question: What does “container body” mean in ngb-modal?

Answer:

In ng-bootstrap (the Angular wrapper for Bootstrap components), there is no option or property called “container body” in NgbModal.

What you are most likely seeing (or hearing about) is the combination of two separate concepts that are frequently used together:

1. The container option

When you open a modal with NgbModal.open(...), you can pass options:

this.modalService.open(content, {
  container: 'body',          // ← this is the most common value
  // or: container: '#some-div'
});

This setting is important when:

2. The .modal-body part

This is not an option — it’s part of the HTML structure you write inside your modal template:

<ng-template #content let-modal>
  <div class="modal-header">...</div>
  <div class="modal-body">           <!-- ← this is .modal-body -->
    This is the actual content area with padding.
  </div>
  <div class="modal-footer">...</div>
</ng-template>

.modal-body is a Bootstrap CSS class that adds:

So when people say “container body” in ngb-modal conversations, they almost always mean:

Use container: 'body' in the modal options
and put your main content inside <div class="modal-body"> in the template.

Quick summary table

Term What it is Where it appears Typical value / usage
container Option – where to append the modal NgbModal.open(..., { container }) 'body' (most common)
.modal-body CSS class – content area with padding Inside your modal template <div class="modal-body">...</div>

Most common / recommended pattern:

this.modalService.open(content, { container: 'body', centered: true });
<div class="modal-body">
  Your form, text, table, etc. goes here
</div>

References:


Back Donate