CSS’s Border Attribute – Usage and Best Practices

11

by Shane Jeffers

bordermain

This is the second part in a three part series. Today we will be covering the Border attribute. The first article was on the Background Attribute and the last article will be on the Font Attribute so stay tuned and subscribe. Part one of this CSS series is linked below.

  1. In-Depth Look at CSS’s Background Attribute

Some background on the Border Attribute

Borders used to be those ugly gray things that surrounded elements such as tables and frames, but now with CSS they are a very powerful tool for designers.

Overview

There are 3 properties available in CSS2 relating to the border attribute.

  • border-color : Sets the actual color for the border
  • border-style : Sets the style of the border
  • border-width : Sets how thick the border will be

Usage of basic properties

Border Color

The border-color property sets a specific color for the border of the chosen element. Here are some examples of what this property may look like.

border-color: #999;
border-color: rgb(100,200,200);
border-color: red;
border-color: transparent;

Border Color Example

Border Styles

The border-style property sets the style of the border on the specified element to whatever value it’s given.

border-style: dotted;
border-style: dashed;
border-style: solid;
border-style: double;
border-style: groove;
border-style: ridge;
border-style: inset;
border-style: outset;
border-style: none;
border-style: hidden;

Border Style Example

Border Width

The border-width property determines the thickness of the border on any given element.

border: 3px solid #64c8c8;
border: .5em solid #64c8c8;
border: thin solid #64c8c8;
border: 10pt solid #64c8c8;

Border Width Example

Speed up the process with short hand

This little piece of code is a gem, you might want to take notes on this one. This combines all three border properties into one for increased productivity.

border: (width) (style) (color);
border: 1px solid #999;

Great Examples of Border Usage

1. Kammeradvokaten

border4
border5

This site uses a mixture of typography and borders to bring a truly effective simplistic look. The borders act as organizers for the content. Very well done.

2. Open

border6
border7

This is also another beautiful example of the border attribute. Open has used borders to basically section off each piece of content. Everything is well aligned and they used multiple styles of borders.

My challenge to you

When you are designing that new portfolio or a site for a client, push yourself to incorporate borders in the design. It will not only be a challenge to do it well, but you as a designer will benefit from branching out from the norm. If you do complete this challenge or have completed this challenge please leave a link in a comment so our readers can check them out!

Written by Shane Jeffers

Shane Jeffers is the Creator and Author of Three Styles. I have a unique passion for design trends and tutorials. Follow me on twitter @ThreeStyles

Enjoy this post? Subscribe by RSS or Email

CSS, Tutorials

11 Responses to “CSS’s Border Attribute – Usage and Best Practices”

  1. GravatarYou are now listed on FAQPAL Says:

    CSS’s Border Attribute – Usage and Best Practices…

    Borders used to be those ugly gray things that surrounded elements such as tables and frames, but now with CSS they are a very powerful tool for designers….

  2. GravatarNathalie Firefly Says:

    Great tutorial! Here’s some simple border use on a website I designed…

  3. GravatarDaniel Says:

    So, are you saying that designing a site with borders is somewhat better than using margins and padding?

  4. GravatarJV Says:

    @Danial, using css to design a site is combining borders with padding/margin. You can see in the examples that he uses a lot of padding.
    I guess that since this tutorial is about border Shane is not mentioning the use of padding/margin to keep the focus on the border possibilities.

  5. GravatarShane Jeffers Says:

    @daniel

    JV is correct. I am not condoning using borders over padding and margin, just the use of borders in general to enhance the layout!

  6. GravatarDaniel Says:

    Thanks guys, I was just curious.
    Daniel´s last blog ..My Business Card My ComLuv Profile

  7. GravatarRebecca Says:

    Good tutorial. For a long time borders had a bad reputation and some people still hesitate to use them, but used correctly they can really improve the neatness of a design.

  8. Gravatarmikeo Says:

    nice article.

    i have no problem using borders – just as needed not because they are there.

  9. GravatarAndy Walpole Says:

    Things are getting pretty funky with CSS borders in CSS3. Try out the borders-image property when you get a chance but it’s real difficult to get your head around the syntax. Also Firefox’s -moz-border-bottom-colors is worth playing around with.
    Andy Walpole´s last blog ..The internet 10 years ago this month – January 2000 My ComLuv Profile

  10. GravatarLucy Says:

    Thanks for the pointers. I’m at the stage in building my website that I really need to offset parts of the text in my longer articles and nice, subtle borders are going to do it for me!

    Otherwise, my visitors (not all accountants) would get bored very quickly…

    We all need help getting to the “bottom line” of the page or an article and borders can emphasize important parts of the text in a very elegant way.

  11. GravatarOlivia Gresham Says:

    I think I’ll try it out, I simply ruled them out because its hard to make them look good. Thanks for the read!

Leave a Reply

CommentLuv Enabled