Fancy Magento Global Messages

Fancy Magento Global Messages

Magento Global Messages are sometimes not enough visible to the customers.

Let’s improve their visual impact by putting them on top of the page, and prettify with some nice animations!

1. Create local.xml file inside your theme’s layout folder, or insert our layout update to appropriate place if you already have it (read more about “local.xml method”).

<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
		<reference name="root">
			<remove name="global_messages" />
		<reference name="after_body_start">
			<block type="core/template" name="inchoo_global_messages" template="core/inchoo_global_messages.phtml" before="-" />

2. Create inchoo_global_messages.phtml in

<?php if($this->getMessagesBlock()->getMessageCollection()->count()): ?>
	<div id="inchoo_global_messages" style="display: none">
		<a href="javascript:void(0)" id="inchoo_global_messages_close" style="display: none" title="<?php echo $this->__('Hide messages') ?>">&times;</a>
		<?php echo $this->getMessagesBlock()->getGroupedHtml(); ?>
<?php $this->getMessagesBlock()->getMessageCollection()->clear(); ?>
<script type="text/javascript">
	Event.observe('inchoo_global_messages_close', 'click', function() {
		Effect.SlideUp('inchoo_global_messages', { duration: 0.4, delay: 0.3 });
		Effect.Fade('inchoo_global_messages_close', { duration: 0.2 });
	Event.observe(document, 'dom:loaded', function() {
		Effect.SlideDown('inchoo_global_messages', { duration: 0.4, delay: 0.3 });
		Effect.Appear('inchoo_global_messages_close', { duration: 0.2, delay: 1 });
<?php endif; ?>

3. Append styling of #inchoo_global_messages to your CSS file in
skin/frontend/your_ package/your_theme/css/

#inchoo_global_messages {
	position: relative;
	z-index: 9999;
#inchoo_global_messages_close {
	position: absolute;
	top: 13px;
	right: 13px;
	z-index: 10000;
	display: block;
	width: 15px;
	height: 15px;
	background: #666;
	text-align: center;
	color: #fff;
	font-size: 15px;
	line-height: 15px;
	text-decoration: none;
	-webkit-border-radius: 15px;
	-moz-border-radius: 15px;
	border-radius: 15px;

and tweak message styling according to your design.

In video example, I’ve added those overrides to default Magento css:

.messages li, .messages li li { margin: 0 !important; }
.error-msg, .success-msg, .note-msg, .notice-msg {
	border: none !important;
	font-size: 14px !important;
	background-position: 13px 13px !important;
	padding: 10px 35px !important;
	min-height: 22px !important;
.note-msg, .notice-msg { color: #d6b501; }

And that’s it… Reload your cache and notify your customers in a fancy way 🙂

You made it all the way down here so you must have enjoyed this post! You may also like:

Adding gallery tab to a CMS page Antun Martinovic
Antun Martinovic, | 5

Adding gallery tab to a CMS page

Implementing javascript minifier Tomislav Nikcevski
Tomislav Nikcevski, | 5

Implementing javascript minifier

How to set up a CDN (Amazon CloudFront) in Magento Dario Trbovic
Dario Trbovic, | 18

How to set up a CDN (Amazon CloudFront) in Magento


  1. For IE, you have to change style=”display: none” in style=”display: none; overflow:hidden;”.
    Otherwise the message will stay on the screen.

  2. Wonderful tutorial, the quality of the video is a little dull tough and a HD video would have been great since there was no audio to support it…

  3. You could also update the classes without touching one single file except a little javascript. Something like that:

    function globalMessages(){
    var messageBox = jQuery(‘ul.messages’);
    if(messageBox.length){ //check if message exists
    var alertWrapper = messageBox.children(‘:first’);
    var alertType = alertWrapper.attr(‘class’); //get alert type

    switch(alertType) { //update class
    case ‘error-msg’:
    case ‘success-msg’:
    setTimeout(function() { //hide after timeout
    messageBox.slideDown(400); //show message
    }, 500);

    setTimeout(function() { //hide after timeout
    messageBox.slideUp(400); //show message
    }, 5000);

    globalMessages(); //fire the function



  4. If there is anyone looking for a CSS3 Version, try something like the below code – just drop it in your themes stylesheet (make sure you use Modernizer to detect support otherwise your message will display with 0 opacity). Although if you are looking for better browser support Davor’s solution may be better.

    opacity: 0;
    animation: fadeOut 7s;
    -moz-animation: fadeOut 7s;
    -webkit-animation: fadeOut 7s;
    -o-animation: fadeOut 7s;
    @-webkit-keyframes fadeOut { from { opacity:1; } to { opacity:0; } }
    @-moz-keyframes fadeOut { from { opacity:1; } to { opacity:0; } }
    @-o-keyframes fadeOut { from { opacity:1; } to { opacity:0; } }
    @keyframes fadeOut { from { opacity:1; } to { opacity:0; } }
  5. nice work! is it also possible that the message will automatically close after a given time , say 5-10 sec?

  6. Great… But i keep getting empty messages. Backend the global messages showup nicely, frontend just shows empty block 🙁
    Do you know where to look to fix this?

  7. it’s Awesome ! But its not working in list page and product detail page for me . please help me how to solve it .

  8. Wonderful tutorial, the quality of the video is a little dull tough and a HD video would have been great since there was no audio to support it…

  9. I don’t know why, but when the message show, after body tag there is a “space”, and looking at the code I got this:


    How to fix this?

  10. Maybe you could help me, I’m attempting to make this work and i’m almost there, but i’m not getting the close buttons 🙁

  11. @Michael
    I’ve “lost” it in the copy-paste :]
    Thanks for the fix!

    Glad you like it! 🙂

  12. Ah, I figured out my problem, wasn’t the layout XML, you are missing the last line of the template file that includes an endif, e.g.:

    <?php endif; ?>

    Cool tutorial, and thanks!

  13. This is a very cool tutorial, but for some reason the XML update is not working. The old global messages is still there and the new one doesn’t show up. I’ve tried putting the update code in my page.xml (and even the /base/default XML) to no avail.

    I know its hard to guess without actually seeing my install, but any ideas?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.