This worked for me

.modal-dialog,
.modal-content {
    /* 80% of window height */
    height: 80%;
}

.modal-body {
    /* 100% = dialog height, 120px = header + footer */
    max-height: calc(100% - 120px);
    overflow-y: scroll;
}

Fiddle: http://jsfiddle.net/mehmetatas/18dpgqpb/2/

Answer from Mehmet Ataş on Stack Overflow
🌐
Bootstrap
getbootstrap.com › docs › 5.0 › components › modal
Modal · Bootstrap v5.0
This is some placeholder content to show the scrolling behavior for modals. Instead of repeating the text the modal, we use an inline style set a minimum height, thereby extending the length of the overall modal and demonstrating the overflow scrolling.
Discussions

css - how can i increase bootstrap modal height - Stack Overflow
I am simply trying to make a bootstrap modal display extremely tall on a iphone 5/6 device. I cannot get this to work for anything. I have tried increasing the height in the modal-content, as wel... More on stackoverflow.com
🌐 stackoverflow.com
Bootstrap modal body max height 100% - javascript
I have a custom sized (80% height width) bootstrap modal body and it scrolls (body content will overflow on some sized screens) There are 2 problems: I can't set the max-height to 100% as that wil... More on stackoverflow.com
🌐 stackoverflow.com
jquery - Bootstrap 3 - set height of modal window according to screen size - Stack Overflow
I am trying to create a kind of responsive megamenu using Bootstrap 3 modal dialog. I would like to set the width and height of the whole modal window to 80% of the viewport, while setting the moda... More on stackoverflow.com
🌐 stackoverflow.com
html - How to increase Bootstrap Modal Width? - Stack Overflow
i've tried this but gone wrong here's the css body .modal-ku { width: 750px; } and here's the failed result More on stackoverflow.com
🌐 stackoverflow.com
🌐
Bootstrap Studio Forum
forum.bootstrapstudio.io › bootstrap studio help
Modal scaled to viewport height? - Bootstrap Studio Help - Bootstrap Studio Forum
August 29, 2024 - When activated the modal fades into the viewport, but alway exceeds it by approx. 10 % to the bottom. Is there a CSS way to make the modal appear not higher than the current viewport. I have tried max-height = 90vh in different ...
🌐
Bootstrap
getbootstrap.com › docs › 4.2 › components › modal
Modal · Bootstrap
Manually readjust the modal’s position if the height of a modal changes while it is open (i.e. in case a scrollbar appears). ... Destroys an element’s modal. Bootstrap’s modal class exposes a few events for hooking into modal functionality. All modal events are fired at the modal itself (i.e.
🌐
MDBootstrap
mdbootstrap.com › standard › modal size
Bootstrap Modal Sizing - free examples & tutorial
Responsive popup window sizing with Bootstrap 5. Modal width, modal height, fullscreen modal, large modal with lg & xl modal classes and more.
🌐
GitHub
gist.github.com › rqloud › 5fbc9da947d0d0b7932c
Dynamic height Bootstrap modal without JS · GitHub
Dynamic height Bootstrap modal without JS. GitHub Gist: instantly share code, notes, and snippets.
🌐
CodePen
codepen.io › cemg › pen › LQrxLV
Bootstrap 4 Modal Auto Height
.modal-autoheight .modal-body { position: relative; overflow-y: auto; min-height: 100px !important; max-height: 600px !important; }
Top answer
1 of 3
13

The .modal-content block is inside the .modal-dialog block. Hence, tell the child to be of the same height as the parent. Try:

.modal-dialog {
  height: 90%; /* = 90% of the .modal-backdrop block = %90 of the screen */
}
.modal-content {
  height: 100%; /* = 100% of the .modal-dialog block */
}

Check:

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');

.modal-tall .modal-dialog {
  height: 90%;
}
.modal-tall .modal-content {
  height: 100%;
}

/* fix SO stick navigation ;) */
@media (min-width: 768px) { body { padding-top: 75px; } }
<div class="container">
  <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#modalDefault">
    Default modal
  </button>

  <button type="button" class="btn btn-warning btn-lg" data-toggle="modal" data-target="#modalTall">
    Tall modal
  </button>
</div>

<div id="modalDefault" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Default modal</h4>
      </div>
    </div>
  </div>
</div>

<div id="modalTall" class="modal modal-tall fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal has 90% height</h4>
      </div>
    </div>
  </div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

2 of 3
1

It does not work on Bootstrap 5.

.modal-dialog {
  height: 90%; /* = 90% of the .modal-backdrop block = %90 of the screen */
}
.modal-content {
  height: 100%; /* = 100% of the .modal-dialog block */
}

The following works well.

.modal-dialog, .modal-content {
  height: 70%;
}

.modal-body {
  max-height: calc(100% - 120px);
  overflow-y: scroll;
}
Find elsewhere
Top answer
1 of 11
9

I caved in and wrote coffeescript to fix this. If anyone's interested, here's the coffeescript:

fit_modal_body = (modal) ->
  header = $(".modal-header", modal)
  body = $(".modal-body", modal)

  modalheight = parseInt(modal.css("height"))
  headerheight = parseInt(header.css("height")) + parseInt(header.css("padding-top")) + parseInt(header.css("padding-bottom"))
  bodypaddings = parseInt(body.css("padding-top")) + parseInt(body.css("padding-bottom"))

  height = modalheight - headerheight - bodypaddings - 5 # fudge factor

  body.css("max-height", "#{height}px")

# Here you need to bind your event with the appropriate modal, as an example:
$(window).resize(() -> fit_modal_body($(".modal")))

Or the equivalent javascript as generated per above.

var fit_modal_body;

fit_modal_body = function(modal) {
  var body, bodypaddings, header, headerheight, height, modalheight;
  header = $(".modal-header", modal);
  body = $(".modal-body", modal);
  modalheight = parseInt(modal.css("height"));
  headerheight = parseInt(header.css("height")) + parseInt(header.css("padding-top")) + parseInt(header.css("padding-bottom"));
  bodypaddings = parseInt(body.css("padding-top")) + parseInt(body.css("padding-bottom"));
  height = modalheight - headerheight - bodypaddings - 5;
  return body.css("max-height", "" + height + "px");
};

$(window).resize(function() {
  return fit_modal_body($(".modal"));
});
2 of 11
6

I faced the same problem with a long form. Javascript was not an option for me, so I ended up with a fully HTML-CSS solution.

The main goal was to code it just working with percentages, in order to have an easy way to build the media queries.

I've tested it with Firefox 22.0, Google Chrome 28.0.1500.71, Safari 6.0.5 and IE8. Here's the demo.

Modal HTML Structure:

The key is to have the structural divs clean from padding/margin/border. All these styles should be applied to the items inside them.

<div id="dialog" class="modal hide dialog1" aria-hidden="false">
    <div class="modal-header">
    </div>
    <div class="modal-body">
        <div>
        </div>
    </div>
</div>

Styles:

The styles applied to these structure divs are the ones which determines its size.

.modal.dialog1 { /* customized styles. this way you can have N dialogs, each one with its own size styles */
    width: 60%;
    height: 50%;
    left: 20%; /* ( window's width [100%] - dialog's width [60%] ) / 2 */
}

/* media query for mobile devices */
@media ( max-width: 480px ) {
    .modal.dialog1 {
        height: 90%;
        left: 5%; /* ( window's width [100%] - dialog's width [90%] ) / 2 */
        top: 5%;
        width: 90%;
    }
}

/* split the modal in two divs (header and body) with defined heights */
.modal .modal-header {
    height: 10%;
}

.modal .modal-body {
    height: 90%;
}

/* The div inside modal-body is the key; there's where we put the content (which may need the vertical scrollbar) */
.modal .modal-body div {
    height: 100%;
    overflow-y: auto;
    width: 100%;
}

For more detailed code, refer to the demo, where you'll see whole styling classes and those bootstrap styles which needs to be disabled/overriden.

🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-change-the-default-width-of-bootstrap-modal-box.php
How to Change the Default Width of Bootstrap Modal Box
... <!DOCTYPE html> <html lang="en"> ...strap.min.js"></script> <style> @media screen and (min-width: 676px) { .modal-dialog { max-width: 600px; /* New width for default modal */ } } </style> </head> <body> <div class="m-4"> <!-- Button ...
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-configure-modal-width-in-bootstrap
How to configure modal width in Bootstrap? | GeeksforGeeks
September 6, 2021 - Bootstrap Modal: It is a dialog window that opens inside the browser window on triggering certain events. It is a really convenient way to improve the website's content rendering as per the requirements. In this article, we will focus on adjusting the width/height of the modal box.
🌐
CodePen
codepen.io › dimbslmh › pen › nJqJXE
Bootstrap 3 Modal Vertically Center/Max-Height
20 : 60; var contentHeight = $(window).height() - (dialogMargin + borderWidth); var headerHeight = this.$element.find('.modal-header').outerHeight() || 0; var footerHeight = this.$element.find('.modal-footer').outerHeight() || 0; var maxHeight ...
🌐
W3Schools
w3schools.com › bootstrap5 › bootstrap_modal.php
Bootstrap 5 Modal
If you want the modal to span the whole width and height of the page, use the .modal-fullscreen class:
🌐
Plotly
community.plotly.com › dash python
Make Bootstrap Modal bigger than 'xl' - Dash Python - Plotly Community Forum
May 19, 2020 - Hi, I’m a Python developer but very new to Dash and HTML/CSS. I would like to have some advice on how to make the size of a Bootstrap Modal component bigger than using the attribute 'size=‘xl’. Ideally I would like to h…
🌐
GitHub
github.com › mdbootstrap › bootstrap-modal-size
GitHub - mdbootstrap/bootstrap-modal-size: Responsive popup window sizing with Bootstrap 5. Modal width, modal height, fullscreen modal, large modal with lg & xl modal classes and more. · GitHub
Responsive popup window sizing with Bootstrap 5. Modal width, modal height, fullscreen modal, large modal with lg & xl modal classes and more. - mdbootstrap/bootstrap-modal-size
Author   mdbootstrap
🌐
tutorialpedia
tutorialpedia.org › blog › set-bootstrap-modal-body-height-by-percentage
How to Set Bootstrap Modal Body Height by Percentage for Responsive Scrollable Content: Fixing the Max-Height Issue — tutorialpedia.org
Ignoring Parent Heights with Flexbox: If .modal-content isn’t set to height: 100%, Flexbox won’t work—double-check parent styles. Hardcoding vh Values: 90vh might work on desktops but overflow on mobile (try min(90vh, 600px) for a cap). To make Bootstrap modals responsive with scrollable bodies: