• Home
  • Patel Strategy
Subscribe: Posts | Comments | E-mail
  • Business
  • Design
  • Experiments
  • WordPress
  • News

Impress Lab

Posted on August 19, 2008 - by Impress Lab

Creating CSS Alert Boxes

Design

A quick and useful way of beautifying your content are alert boxes, which are becoming more and more common on the web. Alert boxes quickly highlight important information, such as warnings or tips, separating them from your main body content.

Purpose of Alert Boxes

Considering that the average website visitor only spends perhaps a minute on each page, alert boxes can quickly grab the reader’s attention to the most important information. In addition, alert boxes help break the flow of several paragraphs of text with a splash of color and cute icons in our examples below.

Creating CSS Alert Boxes

Creating alert boxes are perhaps one of the easiest CSS tricks:

1. CSS Code

You can create seperate paragraph classes in your stylesheet. For example, to create a red message box (perhaps for warnings), use the following code:

.red { color: #FFFFFF;font-weight: normal;background:#FB7070  url("images/red.gif") no-repeat left center;border:1px solid #D43C3C;padding-left:3px 3px 3px 22px;margin-bottom:7px;}

Notice that the alert box includes a background image (”images/red.gif”). This will create the icon on the left side. For most cases, we suggest you use FAMFAMFAM’s free Silk Icon set. The icon should be only 16px by 16px as not to distract from the actual text.

You can also create alert boxes with border widths of 2px. Depending on the size of the text, you can go even larger. For general body text such as this, a 1px border is usually best.

2. HTML Code

To display an alert in your web page, use the following code:

<p class="red">Warning: Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>

This code will create this alert box when viewed:

Warning: Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

Of course, replace the red class with the class used in your CSS file. You can also create other combinations with different icons and background/border color schemes. See the next section for other types of common alert boxes.

Types of Alert Boxes

There are several types of alert boxes you may want to create and use throughout your site. In each case, notice that: 1.) the background should be a light, pastel color, 2.) the border color should be darker than the background color, and 3.) the font color must be readable on the background color. The most obvious are red warning boxes, which may use the following color scheme:

Background color: #FB7070  (light red)
Border color: #D43C3C (dark red)
Font color: #FFFFFF (white)

Warning: This is a red alert box, good for warnings and cautions.

You can also use yellow boxes for general tips or highlights:

Background color: #FFFFCC (light yellow)
Border color: #DDDB54 (dark yellow)
Font color: #000000 (black)

Tip: This is a yellow alert box, good for general tips.

You can also use green boxes for troubleshooting messages:

Background color: #9BCF7B (light green)
Border color: #669933 (dark green)
Font color: #000000 (black)

Troubleshooting: This is a green alert box, good for problems.

Actual Examples

Alert Box Suggestions

Alert boxes work best on tutorial pages or for instructions as they provide quick information with attention to the most important details.

With anything in design, use alert boxes in moderation. If you see your entire page colored in red or yellow, you may be using this handy CSS technique a bit too much.

Finally, we recommend that you use colors for the CSS classes (i.e. red, yellow, and green) because it will be much easier to remember them when using the classes in your web pages. For example, consider that you used “.warning” as your CSS class for the red alert boxes. You would have to remember that you used this class name when creating the code in your pages. The color name may be easier to remember. However, you can use classes like “.warning” if you have several red-colored boxes, but with different icons.

This entry was posted on Tuesday, August 19th, 2008 at 6:24 pm and is filed under Design. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

8 Comments

We'd love to hear yours!



  1. Visit My Website

    August 20, 2008

    Ryan Holms said:

    simple but effective! good advice for beginners.



  2. Visit My Website

    August 20, 2008

    Kenneth R. said:

    I would lighten up the background of the green box personally as the black may be hard to read on the color. Also, like the examples, you can lighten the red background and then use black font color to be consistent.



  3. Visit My Website

    August 28, 2008

    Matt said:

    Nice for the beginners, but I would try and not name things by their color. Now I know that in this case the colors reflect a “meaning”, but, just to add that extra layer of thoughtfulness to the code, try a more semantic approach.



  4. Visit My Website

    August 28, 2008

    Impress Lab said:

    Matt,

    You are right in the sense that, suppose you have a red message box with 3 different icons. In that case it may be better to use a more semantic labeling system that perhaps describes each icon.

    But if you only have 2 or 3 message boxes total, it may be easier to use color. Image what would happen if you didn’t use a message box for a very long time - you would have to go back and check which CSS tag was used. But if you used the color as the name in your stylesheet, it would perhaps be easier to remember.

    Either way, it is more of a personal choice, and like mentioned, may depend on how many of these styles you have etc. And like you mention, for beginners using colors is probably the best choice. Thanks!



  5. Visit My Website

    August 28, 2008

    kyle said:

    Your css has

    padding-left: 3px 3px 3px 22px;

    which I think should be

    padding: 3px 3px 3px 22px;



  6. Visit My Website

    September 3, 2008

    projectgrfix said:

    Thanks, they look cool. How is that alertbox made which in which color fades away slowly which is found in wordpress admin? Is it only css or some js ?



  7. Visit My Website

    September 3, 2008

    Impress Lab said:

    For an alert box that fades away on some user action, more than CSS is necessary.

    CSS only styles the element (i.e. changing the colors, text style, layout, etc).

    Javascript, or more exactly AJAX or JQuery would be necessary to make the box more functional, for example to fade in and out on some user action.



  8. Visit My Website

    September 8, 2008

    mike said:

    very nice



Leave a Comment

Here's your chance to speak.

  1. Name (required)

    Mail (required)

    Website

    Message

    August
    19th
    2008
    • 8 Commentswe'd love to hear yours!
    • Trackback from your own site
  • Recent Articles

    • Business Realignment: Services move to Patel Strategy September 26, 2008
    • Designing through Writing September 11, 2008
    • Bad Practices: Website Login Form Placement September 10, 2008

© 2008 Impress Lab - Minnesota Creative Marketing
A Patel Strategy Production