CSS Message Boxes for different message types

22. May 2008 12:17 by Janko | Comments (81)

Can you believe this: Few days ago I went to my bank to check my credit score with the Credit Bureau. The bank official typed in my personal data and sent a request. Web application responded by displaying a yellow message box with an exclamation icon saying that data processing is still in progress. He checked several more times, but he didn't notice that at one moment the message changed to "Account available". But the message box hasn't changed. He continued to check a few more times and eventually he realized that the request was successful.

I don't know what was in the minds of developers and designers who created this application, but it certainly wasn't the user. This poor bank official was really frustrated. I can't imagine what the rest of the application looks like.

To prevent this, different message types should be displayed differently. My opinion is that every web application should handle four main message types: information, successful operation, warning and error. Each message type should be presented in a different color and different icon. A special message type represents validation messages.

I will show you a remake of CSS message boxes I used on my latest project. I changed them slightly just to make them simpler for this example. In next article, you will see how to create ASP.NET user control that can support different message types and how to style it using CSS. You will also see how to style ValidationSummary in a similar way.

Let's first take a quick look at message types.

1. Information messages

The purpose of information messages is to inform the user about something relevant. This should be presented in blue because people associate this color with information, regardless of content. This could be any information relevant to a user action.

 error_04

For example, info message can show some help information regarding current user action or some tips.

2. Success messages

Success messages should be displayed after user successfully performs an operation. By that I mean a complete operation - no partial operations and no errors. For example, the message can say: "Your profile has been saved successfully and confirmation mail has been sent to the email address you provided". This means that each operation in this process (saving profile and sending email) has been successfully performed.

error_03  

I am aware that many developers consider this as an information message type, but I prefer to show this message type using it's own colors and icons - a green with a checkmark icon.

3. Warning messages

Warning messages should be displayed to a user when an operation couldn't be completed in a whole. For example "Your profile has been saved successfully, but confirmation mail could not be sent to the email address you provided.". Or "If you don't finish your profile now you won't be able to search jobs". Usual warning color is yellow and icon exclamation.

error_05

4. Error messages

Error messages should be displayed when an operation couldn't be completed at all. For example, "Your profile couldn't be saved." Red is very suitable for this since people associate this color with an alert of any kind.

error_01 

Design process

Now when we know the way to present messages to users, let's see how to implement a it using CSS. Let's take a quick look at the design process.

I will keep this as simple as I can. The goal is to have a single div that implements a single CSS class. So the HTML markup will look like this:

        <div class="info">Info message</div>
        <div class="success">Successful operation message</div>
        <div class="warning">Warning message</div>
        <div class="error">Error message</div>

CSS class will add a background image to the div that will be positioned top-left. It will also create a padding inside the div so that text can have enough white space around it. Note that left padding has to be wider to prevent text overlapping with the background image.

error_07 

And here are the CSS classes for all four (five with validation) different message types:

body{
    font-family:Arial, Helvetica, sans-serif; 
    font-size:13px;
}
.info, .success, .warning, .error, .validation { border: 1px solid; margin: 10px 0px; padding:15px 10px 15px 50px; background-repeat: no-repeat; background-position: 10px center; } .info { color: #00529B; background-color: #BDE5F8; background-image: url('info.png'); } .success { color: #4F8A10; background-color: #DFF2BF; background-image:url('success.png'); } .warning { color: #9F6000; background-color: #FEEFB3; background-image: url('warning.png'); } .error { color: #D8000C; background-color: #FFBABA; background-image: url('error.png'); }

Note: Icons used in this example are from Knob Toolbar icons collection.

Validation messages

I noticed that many developers can't distinguish between validation and other message types (such as error or warning messages). I saw many times that validation message is displayed as error message and caused confusion in the user's mind.

Validation is all about user input and should be treated that way. ASP.NET has built in controls that enable full control over user input. The purpose of validation is to force a user to enter all required fields or to enter fields in the correct format. Therefore, it should be clear that the form will not be submitted if these rules aren't matched. That's why I like to style validation messages in a slightly less intensive red than error messages and use a red exclamation icon.

error_09

CSS class for validation message is almost identical to others (note that in some attributes are defined in previous code sample):

.validation {
    color: #D63301;
    background-color: #FFCCBA;
    background-image: url('validation.png');
}

Conclusion

Messages are an important part of the user experience that is often omitted. There are many articles that show nicely styled message boxes but it is not just a matter of design. It should provide a user with meaningful information, semantically and visually.

There are two other articles I would like to recommend you:

In my next article I will show you how to create ASP.NET user control that can wrap all of these message types and present it to a user. You will also see how to apply this style to a ValidationSummary control.

kick it on DotNetKicks.com

Currently rated 4.7 by 25 people

  • Currently 4.72/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags: | Categories: Design | User experience
E-mail | Permalink

Comments

DotNetKicks.com on May 22. 2008 12:21 wrote:
Trackback from DotNetKicks.com

CSS Message Boxes for different message types
Nick Berardi on May 22. 2008 19:44 wrote:
Very nice.
Kevin Jensen on May 22. 2008 19:59 wrote:
What a great article!
Girl Names on May 22. 2008 20:27 wrote:
helped me a lot. Great article
Steve Schilz on May 22. 2008 20:46 wrote:
This is a very nice, simple CSS example! It combines clear, concise design advice (that should be obvious, but clearly is not to many designers) Thanks...
Dave on May 22. 2008 21:09 wrote:
Very nice.
sir jorge on May 22. 2008 21:35 wrote:
this is going to come in handy for sure.
Marnus on May 22. 2008 21:53 wrote:
Thank you for the article!! It is so refreshing to get a story with it and the best is the layout picture of the different elements. And yes, information/warning/error messages are to much overlooked in thin client web apps!
Daniel Stockman on May 22. 2008 22:09 wrote:
Here's some cleaner CSS:

.info, .success, .warning, .error, .validation {
border: 1px solid;
margin: 10px 0px;
padding:15px 10px 15px 50px;
background-repeat: no-repeat;
background-position: 10px center;
}
.info {
color: #00529B;
background-color: #BDE5F8;
background-image: url('info.png');
}
.success {
color: #4F8A10;
background-color: #DFF2BF;
background-image:url('success.png');
}
.warning {
color: #D8000C;
background-color: #FFBABA;
background-image: url('error.png');
}
.error {
color: #9F6000;
background-color: #FEEFB3;
background-image: url('warning.png');
}
.validation {
color: #D63301;
background-color: #FFCCBA;
background-image: url('validation.png');
}

The border's color is inherited from the color declarations, since they are the same values.
Tony White on May 22. 2008 22:17 wrote:
Excellent article. Very helpful info to share.

For those reading along, notice that the only different between each of those boxes are the colors and background images. All of those message boxes could have an additional class of "messageBox" that handles the shared styles (like border thickness, background image positioning, etc.) , then use .info, .error, etc to attach just the unique css attributes.
estetica-design-forum.com on May 22. 2008 22:22 wrote:
Pingback from estetica-design-forum.com

Css Warning Boxes - Graphic Design Forum and Web Design Forum
Andy Ford on May 22. 2008 22:33 wrote:
A similar concept is built into BlueprintCSS. <a href=""code.google.com/p/blueprintcss/">http://code.google.com/p/blueprintcss/</a>
Andy Ford on May 22. 2008 22:34 wrote:
Janko on May 22. 2008 22:44 wrote:
@Daniel, thank you so much for refactoring! I updated the code in the article Smile

@Steve, @Marnus, you are right. Unfortunatelly this is to much overlooked. Developers and designer often do not take care of it at all. I so many times refactored what other developer messed up and I got surprised each time! Smile
nino on May 22. 2008 22:55 wrote:
this is an amazing work! I will use this as an example for my framework! thanks for sharing!
Blog on May 23. 2008 02:07 wrote:
Keep showing us more code.
codigogeek.com on May 23. 2008 02:21 wrote:
Pingback from codigogeek.com

Aplicar Css a diferentes cajas de mensajes | Codigo Geek
funnyxd.com on May 23. 2008 02:31 wrote:
Pingback from funnyxd.com

links for 2008-05-23 | Funny Stuff is all around
idea*idea on May 23. 2008 02:48 wrote:
Trackback from idea*idea

ウェブサービスに使えるメッセージボックスのCSSスタイル4種
Web Design on May 23. 2008 04:50 wrote:
Very slick subject to cover.

I have to agree with you that GUI Designers / Developers need to focus more on the user experience. Great coverage on how to develop some simple messages to help the designers of the future <thumbs up!>
gulp.com.br on May 23. 2008 05:01 wrote:
Pingback from gulp.com.br

Caixa de mensagens em CSS — Gulp - Desenvolvimento e diversão (youtube, orkut bloqueado, revistas gratis, camera escondida, sites bloqueados, ilusão de ótica …)
codebeater on May 23. 2008 05:07 wrote:
Trackback from codebeater

CSS Message Boxes for different message types
mark on May 23. 2008 08:07 wrote:
The class names are mixed up (warning should be error, and vice versa):

.warning {
color: #D8000C;
background-color: #FFBABA;
background-image: url('error.png');
}
.error {
color: #9F6000;
background-color: #FEEFB3;
background-image: url('warning.png');
}
Janko on May 23. 2008 09:24 wrote:
@Mark, thank you. I fixed the sample.
Manu Temmerman-Uyttenbroeck on May 23. 2008 09:26 wrote:
Great post! I'm almost finished implementing them in our application.
I have a few questions though.
- Why is there the margin of 10px on top and bottom? This didn't look nice here, so I removed it.
- What is in your opinion a user friendly way of closing the popup?
* use a timeout and fadeout after 2 seconds?
* use a close image button on the top right corner?
* click anywhere outside of the message?
* ...?
Daniel Stockman on May 23. 2008 09:26 wrote:
The class names are mixed up

Funny how I didn't notice that, refactoring it and all. Good eyes.
Daniel Stockman on May 23. 2008 09:33 wrote:
All of those message boxes could have an additional class of "messageBox" that handles the shared styles (like border thickness, background image positioning, etc.) , then use .info, .error, etc to attach just the unique css attributes.

@Tony: Normally I would agree with you, but in this case (given no other requirements of the message box, style-wise) I think a grouped selector is the clearer, more parsimonious option.

If there were other messageBoxes that weren't getting styled with the icons, then perhaps the extra class would make sense (and not smell faintly of class-itis). But then that'd be beyond the scope of this example.
Janko on May 23. 2008 09:50 wrote:
@Manu, this 10px margin is to make enough white space between this message box and other controls on the form.
I'd recomment to place close button in the top right corner. It is better to let users have a control over it. If message disappears in some uncommon way, user can be confused, especially if it happens before user read it; and that would be a poor user experience.
mark on May 23. 2008 09:50 wrote:
Not quite fixed. The colors are opposite now. It seemed only the background image was switched b/w each one.

@Manu: It depends on what type of application you're using it for. I just used this code to show error messages when a user submits a form, like for updating profile. It only disappears once they enter all the info in the form correctly and submits it (to make the error popup go and to show the success popup). Then once they leave that page, it disappears entirely.

There is a margin for formatting reasons. Remove it if you don't want it.
Manu Temmerman-Uyttenbroeck on May 23. 2008 09:55 wrote:
Thx for the quick reply. Since you seem to be far better in design then I am, could you maybe post a sample screenshot of how that could look like? Also the icon you're using for it would be nice ;)
Janko on May 23. 2008 10:04 wrote:
@Mark, you are right again. That's what happens when you are doing five things at the same time Smile I hope it's ok now.

@Tony, for the purpose of this example I tried to keep it simple. Daniel suggested some changes which I applied and now it is as simple as it can be. However, I see your point, and in real-world apps this could be a way to do this.
Janko on May 23. 2008 10:28 wrote:
@Manu: I'll write another post on this subject - next post will show how to create asp.net user control that is more complex than those boxes in the example. But if you need it urgently, I could create some sample page for you during the day Smile
Dragan on May 23. 2008 11:35 wrote:
Excellent article, I like it very much. Keep posting, Janko Smile
気ままなWeb屋のBlog on May 23. 2008 17:05 wrote:
Trackback from 気ままなWeb屋のBlog

ウェブサービスに使えるメッセージボックス
mark on May 23. 2008 17:17 wrote:
Yup, it's fine. I now just gotta find good gif icons b/c of the transparency problem in IE6. OR, not make these images as backgrounds, but regular images and use the png fix trick to fix it. OR, forget about IE6 lol.
Ramon Bispo on May 23. 2008 20:07 wrote:
Great Job, guy!

Looks good!

Congrats.
uberbloggerz.com on May 24. 2008 00:16 wrote:
Pingback from uberbloggerz.com

Cajas de error con código CSS | Uberbloggerz
toonz.wordpress.com on May 24. 2008 01:30 wrote:
Pingback from toonz.wordpress.com

links for 2008-05-23 « toonz
marcus.ahnve.net on May 24. 2008 04:32 wrote:
Pingback from marcus.ahnve.net

Head On » Blog Archive » links for 2008-05-24
ctraos on May 24. 2008 05:47 wrote:
exelente !! muchas gracias!!
james.a.arconati.net on May 24. 2008 08:31 wrote:
Pingback from james.a.arconati.net

links for 2008-05-24 at James A. Arconati
Lee Kelleher on May 25. 2008 15:29 wrote:
Good article. I've been using a similar approach with my projects, but using different mark-up:

<div class="message-box"><span class="success">Successful operation message</span></div>

... but it's all down to preference. I feel it gives me more control with the CSS.

Looking forward to seeing your user control example!
ocean.qee.jp on May 26. 2008 05:34 wrote:
Pingback from ocean.qee.jp

Re:design » Blog Archive » メッセージボックスのCSSデザインサンプル
fatihhayrioglu.com on May 26. 2008 14:35 wrote:
Pingback from fatihhayrioglu.com

Fatih HayrioÄŸlu'nun not defteri » 26 Mayıs 2008 web’den seçme haberler » düzenlenmiÅŸ, BaÄŸlantı, arasında, farklılıklar, kutuları, hazırlamak, jQuery, yapılmış, güzel, aralığı
code-inside.de on May 26. 2008 22:35 wrote:
Pingback from code-inside.de

Wöchentliche Rundablage: ASP.NET MVC, Silverlight 2, C#, Entity Framework, WPF, Javascript | Code-Inside Blog
adrian.otero.ws on May 27. 2008 10:46 wrote:
Pingback from adrian.otero.ws

AOWS » Captcha al estilo iPhone
programatik.wordpress.com on May 27. 2008 13:13 wrote:
Pingback from programatik.wordpress.com

Caixa de Mensagem CSS « namespace Programatik
diariothc.com on May 27. 2008 16:08 wrote:
Pingback from diariothc.com

diarioTHC | Creando cajas de mensajes en CSS
cosassencillas.com on May 27. 2008 17:36 wrote:
Pingback from cosassencillas.com

Creando cajas de mensajes en CSS » Cosas sencillas
video script on May 29. 2008 20:28 wrote:
Excellent article. Very helpful info to share.
jacky.seezone.net on May 30. 2008 05:45 wrote:
Pingback from jacky.seezone.net

20080530 網摘 - 以言入罪 - 網絡暴民 Jacky’s Blog
copula.wordpress.com on May 30. 2008 11:33 wrote:
Pingback from copula.wordpress.com

links for 2008-05-30 « copula’s weblog
fashion freak on May 30. 2008 14:13 wrote:
THank, I think I'll use this on my drupal website.
MrMuhKuh on June 1. 2008 22:02 wrote:
awesome, love you! <3
Laughing
Norik on June 2. 2008 09:45 wrote:
another alternative:


.MsgBox {
border: 1px solid;
margin: 10px 0px;
padding:15px 10px 15px 50px;
background-repeat: no-repeat;
background-position: 10px center;
}
.info {
color: #00529B;
background-color: #BDE5F8;
background-image: url('info.png');
}
.success {
color: #4F8A10;
background-color: #DFF2BF;
background-image:url('success.png');
}

HTML:

<div class="MsgBox info">Info message</div>
<div class="MsgBox success">Successful operation message</div>
Janko At Warp Speed on June 2. 2008 10:56 wrote:
Trackback from Janko At Warp Speed

Exception handling best practices in ASP.NET web applications
DailyCoding on June 3. 2008 08:46 wrote:
Trackback from DailyCoding.com
Links - Jun 02, 2008
jf.eti.br on June 4. 2008 17:48 wrote:
Pingback from jf.eti.br

  Caixas de mensagens em CSS by Thunder-Boy
Napolux on June 5. 2008 17:29 wrote:
This is fuc*ing awesome dude, thanks a lot!
macnative.com on June 9. 2008 22:50 wrote:
Pingback from macnative.com

Css Message Boxes | MacNative
Bloodyflux.com on June 11. 2008 02:47 wrote:
Trackback from Bloodyflux.com

A Couple Must Read ASP.NET Articles
Scriptdaemon on June 13. 2008 07:38 wrote:
Do you have a download of the validation icon handy? As the Knob pack doesn't come with that particular one.
Janko on June 13. 2008 08:59 wrote:
@Scriptdaemon: I sent you the icon on your email Smile
Justin Kozuch on June 13. 2008 21:54 wrote:
Another alternative, using shorthand, and set fonts to em to make more accessible:

body{
font: 0.81em Arial, Helvetica, sans-serif; /* 13px = 0.81em */
}

.msgbox {
border: 1px solid;
margin: 10px 0;
padding: 15px 10px 15px 50px;
background-repeat: no-repeat;
background-position: 10px center;
}

.info {
color: #00529B;
background: #bde5f8 url(info.png);
}

.success {
color: #4F8A10;
background: #dff2bf url(success.png);
}

.warning {
color: #9F6000;
background: #feefb3 url(warning.png);
}

.error {
color: #D8000C;
background: #ffbaba url(error.png);
}
Bassie on June 15. 2008 19:01 wrote:
this should be standard for every application!

nice work
Jenny on June 15. 2008 23:44 wrote:
I've done this on my site before. No one liked it though so I got rid of it.
T on June 16. 2008 20:00 wrote:
Another alternative, using shorthand, and set fonts to em to make more accessible:


when using the shorthand version (ie. background: #ffbaba url(error.png);) the all encompassing declaration (.info, .success, .warning, .error, .validation {}) needs to be after each individual class declaration. this also eliminates the need to use multiple classes as in Justin/Norik's examples.
tdotcom.net on June 16. 2008 20:05 wrote:
Pingback from tdotcom.net

TDotCom » Blog Archive » a stumbling gem
e devlet on June 17. 2008 09:52 wrote:
css background examples , Properties , Attribute - - css-lessons.ucoz.com/background-css-examples.htm
Pete White on June 17. 2008 17:48 wrote:
Great resource thanks
calmhuang on June 18. 2008 07:21 wrote:
Very nice.
I fav it.
Norman on June 18. 2008 21:56 wrote:
Those look quite nice, may use that for my next project.Thanks!
opentone on June 19. 2008 10:38 wrote:
Very handy tutorial. Thanks!
Shawn Adrian on June 22. 2008 10:25 wrote:
Really cool post man, original idea and clearly written. I like it.
Muhammad Mosa on June 23. 2008 09:10 wrote:
I loved this post Janko. Really cool
Alfredo Rodrigues Câmara on June 23. 2008 20:15 wrote:
Artigo Maravilhoso, muito bem feito e muito bem escrito. Eu poderia também postar minhas observações mas acho que da maneira que foi feito já está ótimo.

Parabéns.
eugene on June 23. 2008 22:17 wrote:
nice. One drawback: having the icon as a background image will refrain the user/visitor of having the same experience when printing the page. Usually (by default?) backgrounds are not printed by the browser.
sidhudesigner.blog.co.in on June 25. 2008 12:49 wrote:
Pingback from sidhudesigner.blog.co.in

CSS tirks
isopixel.net on July 1. 2008 17:57 wrote:
Pingback from isopixel.net

Cajas en CSS para diferentes tipos de mensajes | Isopixel
darky00 on July 2. 2008 01:32 wrote:
Thank you!!! Very nice boxes.
intelisen.com on July 3. 2008 13:00 wrote:
Pingback from intelisen.com

Bitácora de Intelisen » Cajas informativas con CSS

Add comment


 

  Country flag

biuquote