# Message Box (lv_msgbox) (/widgets/msgbox)



Overview [#overview]

A Message Box is a pop-up built from a content area plus an optional
header (title, close button, and extra buttons) and an optional footer
with buttons.

Text wraps onto multiple lines and the height adjusts automatically.
Setting the height by hand makes the content scrollable instead.

The message box can be modal (blocking clicks on the rest of the screen)
or non-modal.

Styling [#styling]

The message box is built from other Widgets, so you can check these
Widgets' documentation for details.

* Content, header, and footer: [base widget](/widgets/base_widget)
* Buttons: [Button (lv\_button)](/widgets/button)
* Title and content text: [Label (lv\_label)](/widgets/label)

Create a message box [#create-a-message-box]

<ApiLink name="lv_msgbox_create" display="lv_msgbox_create(parent)" /> creates a message box.
If `parent` is `NULL` the message box will be modal, and will use the
[Default Display](/main-modules/display/setup)'s Top [Layer](/main-modules/display/screen_layers) as a parent.

Adding buttons [#adding-buttons]

If you want to add an \[OK] or \[Cancel] or other buttons for the
user to have a choice of responses, add each button using the
<ApiLink name="lv_msgbox_add_footer_button" display="lv_msgbox_add_footer_button(msgbox, btn_text)" /> function.  Calling this
function adds a footer (container) if one was not already present, and it returns a
pointer to the button created, which can be used to add <ApiLink name="LV_EVENT_CLICKED" /> (or
other) events to detect and act on the user's response.

Footer buttons so added are evenly spaced and centered.

Buttons can also be added to the header if desired with
<ApiLink name="lv_msgbox_add_header_button" display="lv_msgbox_add_header_button(msgbox, symbol)" />.
Buttons so added are added to the right end of the header.

Getting the parts [#getting-the-parts]

The building blocks of the message box can be obtained using the
following functions:

```c title=" " lineNumbers=1
lv_obj_t * lv_msgbox_get_content(lv_obj_t * msgbox);
lv_obj_t * lv_msgbox_get_title(lv_obj_t * msgbox);
lv_obj_t * lv_msgbox_get_header(lv_obj_t * msgbox);
lv_obj_t * lv_msgbox_get_footer(lv_obj_t * msgbox);
```

Functions that add something to the message box return a pointer to the newly added Widget:

```c title=" " lineNumbers=1
lv_obj_t * lv_msgbox_add_text(lv_obj_t * msgbox, const char * text);
lv_obj_t * lv_msgbox_add_text_fmt(lv_obj_t * obj, const char * fmt, ...);
lv_obj_t * lv_msgbox_add_title(lv_obj_t * msgbox, const char * title);
lv_obj_t * lv_msgbox_add_close_button(lv_obj_t * msgbox);
lv_obj_t * lv_msgbox_add_header_button(lv_obj_t * msgbox, const void * symbol);
lv_obj_t * lv_msgbox_add_footer_button(lv_obj_t * msgbox, const char * text);
```

Close the message box [#close-the-message-box]

<ApiLink name="lv_msgbox_close" display="lv_msgbox_close(msgbox)" /> closes (deletes) the message box.

<ApiLink name="lv_msgbox_close_async" display="lv_msgbox_close_async(msgbox)" /> closes (deletes) the message box
asynchronously. This is useful if you want the message box to close the on
the next call to `lv_timer_handler` instead of immediately.

Examples [#examples]

Simple Message box [#simple-message-box]

<LvglExample name="lv_example_msgbox_modal" path="widgets/msgbox/lv_example_msgbox_modal" />

Scrolling and styled Message box [#scrolling-and-styled-message-box]

<LvglExample name="lv_example_msgbox_settings" path="widgets/msgbox/lv_example_msgbox_settings" />

Message box with blurred background [#message-box-with-blurred-background]

<LvglExample name="lv_example_msgbox_blur" path="widgets/msgbox/lv_example_msgbox_blur" />
