Movatterモバイル変換


[0]ホーム

URL:


Menu
×
See More 
Sign In
+1 Get Certified Upgrade Teachers Spaces Bootcamps Get Certified Upgrade Teachers Spaces Bootcamps
   ❮     
     ❯   

BootstrapJS Modal


JS Modal (modal.js)

The Modal plugin is a dialog box/popup window that is displayed on top of the current page.

For a tutorial about Modals, read ourBootstrap Modal Tutorial.


The Modal Plugin Classes

ClassDescription
.modalCreates a modal
.modal-contentStyles the modal properly with border, background-color, etc. Use this class to add the modal's header, body, and footer.
.modal-headerDefines the style for the header of the modal
.modal-bodyDefines the style for the body of the modal
.modal-footerDefines the style for the footer in the modal.Note: This area is right-aligned by default. To change this, overwrite CSS with text-align:left|center
.modal-smSpecifies a small modal
.modal-lgSpecifies a large modal
.fadeAdds an animation/transition effect which fades the modal in and out

Trigger the Modal Via data-* Attributes

Adddata-toggle="modal" anddata-target="#modalID" to any element.

Note: For<a> elements, omitdata-target, and usehref="#modalID" instead:

Example

<!-- Buttons -->
<button type="button" data-toggle="modal" data-target="#myModal">Open Modal</button>

<!-- Links -->
<a data-toggle="modal" href="#myModal">Open Modal</a>

<!-- Other elements -->
<p data-toggle="modal" data-target="#myModal">Open Modal</p>
Try it Yourself »


Trigger Via JavaScript

Enable manually with:

Example

$("#myModal").modal()
Try it Yourself »

Modal Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-backdrop="".

NameTypeDefaultDescriptionTry it
backdropboolean or the string "static"true Specifies whether the modal should have a dark overlay:

  • true - dark overlay
  • false - no overlay (transparent)

If you specify the value "static", it is not possible to close the modal when clicking outside of it

Using JSUsing data
keyboardbooleantrueSpecifies whether the modal can be closed with the escape key (Esc):

  • true - the modal can be closed with Esc
  • false - the modal cannot be closed with Esc
Using JSUsing data
showbooleantrueSpecifies whether to show the modal when initializedUsing JSUsing data

Modal Methods

The following table lists all available modal methods.

MethodDescriptionTry it
.modal(options)Activates the content as a modal. See options above for valid valuesTry it
.modal("toggle")Toggles the modalTry it
.modal("show")Opens the modalTry it
.modal("hide")Hides the modalTry it

Modal Events

The following table lists all available modal events.

EventDescriptionTry it
show.bs.modalOccurs when the modal is about to be shownTry it
shown.bs.modalOccurs when the modal is fully shown (after CSS transitions have completed)Try it
hide.bs.modalOccurs when the modal is about to be hiddenTry it
hidden.bs.modalOccurs when the modal is fully hidden (after CSS transitions have completed)Try it

More Examples

Login Modal

The following example creates a modal for login:

Example

<div>
  <h2>Modal Login Example</h2>
  <!-- Trigger the modal with a button -->
  <button type="button">Login</button>

  <!-- Modal -->
  <div role="dialog">
    <div>

      <!-- Modal content-->
      <div>
        <div>
          <button type="button" data-dismiss="modal">&times;</button>
          <h4><span></span> Login</h4>
        </div>
        <div>
          <form role="form">
            <div>
              <label for="usrname"><span></span> Username</label>
              <input type="text" placeholder="Enter email">
            </div>
            <div>
              <label for="psw"><span></span> Password</label>
              <input type="text" placeholder="Enter password">
            </div>
            <div>
              <label><input type="checkbox" value="" checked>Remember me</label>
            </div>
            <button type="submit"><span></span> Login</button>
          </form>
        </div>
        <div>
          <button type="submit" data-dismiss="modal"><span></span> Cancel</button>
          <p>Not a member? <a href="#">Sign Up</a></p>
          <p>Forgot <a href="#">Password?</a></p>
        </div>
      </div>
    </div>
  </div>
</div>
Try it Yourself »


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted ourterms of use,cookies andprivacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved.W3Schools is Powered by W3.CSS.

-->
[8]ページ先頭

©2009-2026 Movatter.jp