We have more to share with you. Follow us along to modal 2
That's everything!
Your inbox is getting full, would you like us to enable automatic archiving of old messages?
Are you sure you want to delete your account
Are you sure you want to delete your account

Are you sure you want to delete your account
Are you sure you want to delete your account
Give us your feedback
Do you want to change that thing to something else?

This is an example of expanded content that will cause the modal's content to scroll








This is an example of expanded content that will cause the modal's dimmer to scroll








Content is centered
They are aligned to the left
Basic actions below

We've found the following gravatar image associated with your e-mail address.
Is it okay to use this photo?

We've found the following gravatar image associated with your e-mail address.
Is it okay to use this photo?
Modal
Definition
Types
Content
Content
A modal can contain content
<div class="ui modal">
<div class="header">Header</div>
<div class="content">
<p></p>
<p></p>
<p></p>
</div>
</div>
Image Content
New in 2.0
A modal can contain image content
<div class="ui modal">
<div class="header">Header</div>
<div class="image content">
<img class="image">
<div class="description">
<p></p>
</div>
</div>
</div>
Actions
A modal can contain a row of actions
<div class="ui modal">
<div class="header">Header</div>
<div class="content">
<p></p>
</div>
<div class="actions">
<div class="ui approve button">Approve</div>
<div class="ui button">Neutral</div>
<div class="ui cancel button">Cancel</div>
</div>
</div>
Variations
Full Screen
A modal can use the entire size of the screen
Run Code$('.fullscreen.modal')
.modal('show')
;
Overlay Full ScreenNew in 2.7.3 Word order required
A modal can overlay the entire screen
Run Code$('.overlay.fullscreen.modal')
.modal('show')
;
Size
A modal can vary in size
Run Code$('.mini.modal')
.modal('show')
;
$('.tiny.modal')
.modal('show')
;
$('.small.modal')
.modal('show')
;
$('.large.modal')
.modal('show')
;
Inverted
A modal can be shown inverted on white dimmer...
Run Code$('.mini.inverted.modal')
.modal({
inverted: true
})
.modal('show')
;
... or default black dimmer
Run Code$('.mini.inverted.modal')
.modal('show')
;
Scrolling Content
New in 2.2.11
A modal can have a scrolling content
<div class="ui modal">
<div class="header">Header</div>
<div class="scrolling content">
<p>Very long content goes here</p>
</div>
</div>
$('.ui.longer.modal')
.modal('show')
;
Center Aligned
New in 2.8.8
You can center align the header, the content or even actions individually
<div class="ui modal">
<div class="center aligned header">Header is centered</div>
<div class="center aligned content">
<p>Content is centered</p>
</div>
<div class="center aligned actions">
<div class="ui negative button">Cancel</div>
<div class="ui positive button">OK</div>
</div>
</div>
$('#centerexample')
.modal('show')
;
Left Actions
New in 2.9.0
You can also place the action buttons to the left
<div class="ui modal">
<div class="header">Look at the Actions</div>
<div class="content">
<p>They are aligned to the left</p>
</div>
<div class="left actions">
<div class="ui negative button">Cancel</div>
<div class="ui positive button">OK</div>
</div>
</div>
$('#leftactionsexample')
.modal('show')
;
Basic Header and Actions
New in 2.9.0
Header and/or Actions can also appear on the same basic background as the content
<div class="ui modal">
<div class="basic header">Basic Header</div>
<div class="content">
<p>Basic Actions below</p>
</div>
<div class="basic actions">
<div class="ui negative button">Cancel</div>
<div class="ui positive button">OK</div>
</div>
</div>
$('#basicheaderactionsexample')
.modal('show')
;
States
Examples
Disabling Vertical Centering
New in 2.3
When your modal has dynamic content, or multiple steps, it can make sense to disable centering so content doesn't jump around vertically when its height changes.
Run Code$('.special.modal')
.modal({
centered: false
})
.modal('show')
;
Top or Bottom aligned
New in 2.7.3 Word order required
If you leave the centered
option to the default true
, you can also force positioning of the modal by adding additional classes top aligned
(which equals to the usage of centered:false
) or bottom aligned
to the modal itself
$('.bottom.aligned.modal')
.modal('show')
;
Scrolling Modal
When your modal content exceeds the height of the browser the scrollable area will automatically expand to include just enough space for scrolling, without scrolling the page below.
Run Code$('.long.modal')
.modal('show')
;
Internally Scrolling Content
You may prefer to have the content of your modal scroll itself, you can do this by using the scrolling content
variation.
$('.longer.modal')
.modal('show')
;
Multiple Modals
A modal can open a second modal. If you use allowMultiple: true
parameter the second modal will be opened on top of the first modal. Otherwise the modal will be closed before the second modal is opened.
// initialize all modals
$('.coupled.modal')
.modal({
allowMultiple: true
})
;
// open second modal on first modal buttons
$('.second.modal')
.modal('attach events', '.first.modal .button')
;
// show first immediately
$('.first.modal')
.modal('show')
;
$('.coupled.modal')
.modal({
allowMultiple: false
})
;
// attach events to buttons
$('.second.modal')
.modal('attach events', '.first.modal .button')
;
// show first now
$('.first.modal')
.modal('show')
;
Forcing a Choice
You can disable a modal's dimmer from being closed by click to force a user to make a choice
Run Code$('.basic.test.modal')
.modal('setting', 'closable', false)
.modal('show')
;
Approve / Deny Callbacks
Modals will automatically tie approve deny callbacks to any positive/approve, negative/deny or ok/cancel buttons.
Run Code$('.ui.basic.test.modal')
.modal({
closable : false,
onDeny : function(){
window.alert('Wait not yet!');
return false;
},
onApprove : function() {
window.alert('Approved!');
}
})
.modal('show')
;
Attach events
A modal can attach events to another element
Run Code$('.test.modal')
.modal('attach events', '.test.button', 'show')
;
Transitions
A modal can use any named ui transition.
$('.selection.dropdown')
.dropdown({
onChange: function(value) {
$('.test.modal')
.modal('setting', 'transition', value)
.modal('show')
;
}
})
;
Dimmer Variations
Modals can specify additional variations like blurring
or inverted
which adjust how the dimmer displays.
$('.ui.modal')
.modal({
inverted: true
})
.modal('show')
;
$('.ui.modal')
.modal({
blurring: true
})
.modal('show')
;
Initializing a modal
Via Javascript propertiesNew in 2.8.8
You can create temporary modals without the need to create markup on your own. Temporary modals will be removed from the DOM once closed by default if there isn't a custom onHidden
callback given.
$.modal({
title: 'Important Notice',
class: 'mini',
closeIcon: true,
content: 'You will be logged out in 5 Minutes',
actions: [{
text: 'Alright, got it',
class: 'green'
}]
}).modal('show');
Via existing DOM node
A modal can be included anywhere on the page. On initialization a modal's current size will be cached, and the element will be detached from the DOM and moved inside a dimmer.
$('.ui.modal')
.modal()
;
<div class="ui modal">
<i class="close icon"></i>
<div class="header">
Modal Title
</div>
<div class="image content">
<div class="image">
An image can appear on left or an icon
</div>
<div class="description">
A description can appear on the right
</div>
</div>
<div class="actions">
<div class="ui button">Cancel</div>
<div class="ui button">OK</div>
</div>
</div>
Reuse existing modal with new contentNew in 2.8.8
You can prepare a modal markup as a general template and reuse it's general style but provide actual content via js properties.
Run Codevar now = new Date();now.setDate(now.getDate()+Math.floor(Math.random() * 31 + 1));
$('#reusemodal').modal({
title: 'Free voucher until '+now.toDateString(),
content: 'Your voucher code is'+Math.random().toString(16).substr(2).toUpperCase()+'',
classContent: 'centered',
class: 'small'
}).modal('show');
<div class="ui modal">
<div class="header"></div>
<div class="content"></div>
<div class="actions">
<button class="ui green approve button">Redeem now</button>
<button class="ui red deny button">Not now</button>
</div>
</div>
Behavior
All the following behaviors can be called using the syntax:
$('.ui.modal')
.modal('behavior name', argumentOne, argumentTwo)
;
Behavior | Description |
---|---|
show | Shows the modal |
hide | Hides the modal |
toggle | Toggles the modal |
refresh | Refreshes centering of modal on page |
show dimmer | Shows associated page dimmer |
hide dimmer | Hides associated page dimmer |
hide others | Hides all modals not selected modal in a dimmer |
hide all | Hides all visible modals in the same dimmer |
cache sizes | Caches current modal size |
can fit | Returns whether the modal can fit on the page |
is active | Returns whether the modal is active |
set active | Sets modal to active |
destroy | Destroys instance and removes all events |
Config TemplatesNew in 2.8.8
A config template is a special behavior to immediately show preconfigured temporary modals. Three basic templates are included: alert
, confirm
, prompt
as equivalents to existing vanilla JS variants, but with more possibilities to customize the look & feel.
$.modal('alert','hello')
$.modal('confirm','Are you sure?',function(value){})
$.modal('prompt','Enter Code', function(value){})
Alert
Possible parameters are: title, content, handler (in that order to stay nearly identical to vanilla js usage) or a given object {title:'',content:'',handler:function(){}}
where as title and content can contain HTML.
$.modal('alert','hello');
$.modal('alert','Watch out','This is an important message!');
$.modal('alert',{
title: 'Listen to me',
content: 'I love Fomantic-UI',
handler: function() {
$.toast({message:'Great!'});
}
});
Confirm
The parameter list and logic is the same as for alert. The selected boolean choice will be provided to a given callback handler.
Run Code// title and content
$.modal('confirm','Attention!','Ready?');
// title, content and handler
$.modal('confirm','Attention!','Ready?', function(choice){
$.toast({message:'You '+ (choice ? 'Accepted':'Declined')});
});
// content and handler
$.modal('confirm','Ready?', function(choice){
$.toast({message:'You '+ (choice ? 'Accepted':'Declined')});
});
// title and handler
$.modal('confirm',{
title: 'Ready?',
handler: function(choice){
$.toast({message:'You '+ (choice ? 'Accepted':'Declined')});
}
});
Prompt
The call for prompt is basically identical to alert and confirm. There are 2 more options available when an object is given placeholder
and defaultValue
.
If you provide HTML Code for the content and this contains an input, this will be used as the inputfield. Otherwise it creates one dynamically for you.
// provide a placeholder
$.modal('prompt',{
title: 'Enter your name',
placeholder: 'Do not enter your mothers name!',
handler: function(name){
$.toast({message: 'Your name is ' + (name || 'CANCELLED')});
}
});
// set a defaultValue
$.modal('prompt',{
title: 'Enter your name',
defaultValue: 'mommy',
handler: function(name){
$.toast({message: 'Your name is ' + (name || 'CANCELLED')});
}
});
// custom input
$.modal('prompt', 'Custom Input', 'Nickname', function(name) {
$.toast({message: 'Your name is ' + (name || 'CANCELLED')});
});
Create your own template
By extending the modals templates object once, you can define your own custom config templates. It has to return an object which will be merged into the modals settings prior to creating/showing the modal.
$.fn.modal.settings.templates.greet = function(username) {
// do something according to modals settings and/or given parameters
var settings = this.get.settings(); // "this" is the modal instance
return {
title: 'Greetings to ' + username + '!',
content: ''+ username.toUpperCase() + 'is the best!',
class: 'inverted',
classContent: 'centered',
dimmerSettings: {
variation: 'inverted'
}
}
}
Reuse this whenever you need
Run Code$.modal('greet','mom')
$.modal('greet','dad')
Settings
Modal Settings
Modal settings modify the modal's behavior
Setting | Default | Description |
---|---|---|
detachable | true | If set to false will prevent the modal from being moved to inside the dimmer |
useFlex | 'auto' | Auto will automatically use flex in browsers that support absolutely positioned elements inside flex containers. Setting to true/false will force this setting for all browsers. |
autofocus | true | When true, the first form input inside the modal will receive focus when shown. Set this to false to prevent this behavior. |
restoreFocus | true | When false, the last focused element, before the modal was shown, will not get refocused again when the modal hides. This could prevent unwanted scrolling behaviors after closing a modal.New in 2.7.2 |
autoShow | false | When true, immediately shows the modal at instantiation time.New in 2.8.8 |
observeChanges | false | Whether any change in modal DOM should automatically refresh cached positions |
allowMultiple | false | If set to true will not close other visible modals when opening a new one |
inverted | false | If inverted dimmer should be used |
blurring | false | If dimmer should blur background |
centered | true | If modal should be center aligned |
keyboardShortcuts | true | Whether to automatically bind keyboard shortcuts. This will close the modal when the ESC-Key is pressed. |
offset | 0 | A vertical offset to allow for content outside of modal, for example a close button, to be centered. |
context | body | Selector or jquery object specifying the area to dim |
closable | true | Setting to false will not allow you to close the modal by clicking on the dimmer |
dimmerSettings |
|
You can specify custom settings to extend UI dimmer |
transition | scale | Named transition to use when animating menu in and out, full list can be found in ui transitions docs. Alternatively you can provide an object to set individual values for hide/show transitions as well as hide/show duration.
|
duration | 400 | Duration of animation. The value will be ignored when individual hide/show duration values are provided via the transition setting |
queue | false | Whether additional animations should queue |
scrollbarWidth | 10 | Used internally to determine if the webkit custom scrollbar was clicked to prevent hiding the dimmer. This should be set to the same (numeric) value as defined for @customScrollbarWidth in site.less in case you are using a different theme |
Callbacks
Callbacks specify a function to occur after a specific behavior.
Setting | Context | Description |
---|---|---|
onShow | Modal | Is called when a modal starts to show. If the function returns false , the modal will not be shown. |
onVisible | Modal | Is called after a modal has finished showing animating. |
onHide($element) | Modal | Is called after a modal starts to hide. If the function returns false , the modal will not hide. |
onHidden | Modal | Is called after a modal has finished hiding animation. |
onApprove($element) | Click | Is called after a positive, approve or ok button is pressed. If the function returns false , the modal will not hide. |
onDeny($element) | Modal | Is called after a negative, deny or cancel button is pressed. If the function returns false the modal will not hide. |
DOM Settings
DOM settings specify how this module should interface with the DOM
Setting | Default | Description |
---|---|---|
namespace | modal | Event namespace. Makes sure module teardown does not effect other events attached to an element. |
selector |
|
|
className |
|
Config Template Settings
Config Template Settings define default content for dynamically created modals
Setting | Default | Description |
---|---|---|
title | '' | Content of the modal header |
content | '' | Content of the modal content |
closeIcon | false | Whether the modal should include a close icon |
actions | false | An array of objects. Each object defines an action with properties text ,class ,icon and click .
|
preserveHTML | true | Whether HTML included in given title, content or actions should be preserved. Set to false in case you work with untrusted 3rd party content |
class | '' | Can hold a string to be added to the modal class to control its appearance. |
classTitle | '' | Can hold a string to be added to the title class to control its appearance. |
classContent | '' | Can hold a string to be added to the content class to control its appearance. |
classActions | '' | Can hold a string to be added to the actions class to control its appearance. |
fields |
|
|
text |
|
Debug Settings
Debug settings controls debug output to the console
Setting | Default | Description |
---|---|---|
name | Modal | Name used in debug logs |
silent | false | Silences all console output including error messages, regardless of other debug settings. |
debug | false | Provides standard debug output to console |
performance | true | Provides standard debug output to console |
verbose | false | Provides ancillary debug output to console |
error |
|