The Golden Ratio in Web Design

Math is beautiful. Does that sound a little strange? I sure thought so when I first started designing. Math is so rigid and often times boring, or so I thought. You would be surprised to find out that most aesthetically pleasing designs, works of art, objects and even people have math in common. Specifically the Golden Ratio, also known as the divine proportion, which is designated by the Greek letter Φ (phi). This tutorial will cover the anatomy and layout of a website and how the Golden Ratio relates.
The elements of a web page are like organs; they are vital to a properly functioning and aesthetically pleasing web page.

These are the main elements of a web page. There are many different ways to organize them but this is perhaps the most common basic layout used online.
All web pages use a container and for the same purpose; to contain page elements, however the way it is accomplished varies. For example, the body tag or a div is most commonly used. In the past, even a table has been used (do not use a table as your page container, it is a depreciated method). Think of the container as the external walls of your house in which your bedrooms, kitchen, living room, etc. are then placed.
Types of container:
  1. Liquid: Expands to fill the width of the browser window.
  2. Fixed: A specific width you choose which does not change regardless of browser window size.

The header isn't really a specific element although some may consider it to be. It is more generally used in referring to the top section of your web page where your logo, navigation, tagline, etc. are located. Many people prefer to keep these elements contained within a div for easier page styling, element separation and/or element containment. The header would be considered a container so it would have two types to choose from: liquid or fixed as mentioned above.

Your logo is your identity and branding. The most common placement for the logo is within the header, aligned left. We read from left to right, top to bottom, so your logo will most likely be the first element your visitors look at.
Page navigation is one of the most important elements; your visitors need it to use your website. It should be easy to find and use, which is why it is almost always located within the header or at least near the top of the page. Sometimes both types of navigation are used for high content websites.
Types of navigation:
  1. Horizontal: A series of links displayed inline, usually referred to as "navigation".
  2. Vertical: A series of links displayed as a vertical stack, usually referred to as "menu".

As everyone knows (or should), content is king! When people visit your site, this is the element they will be looking for primarily. It should be the main focal point of a web page so visitors find what they are looking for quickly.
The sidebar is the element with your secondary content such as advertising, site search, subscription links (RSS, Twitter, Email, etc), contact methods, etc. This element isn't necessary although many websites use it. It is most often right aligned but can be left aligned or both (two sidebars) so long as it doesn't disrupt main content viewing. For websites that use horizontal AND vertical navigation, the sidebar is often replaced with the vertical navigation element.

The end of a web page should always use a footer to let your visitors know they have reached the completion of your web page. Like the header, the footer isn't really a specific element but more of a containing section. Within your footer will be copyright, legal and contact information primarily. It's a good idea to include a few links to the most important sections of your site such as the top of the page, home page, contact page, etc. Some websites use this area as an opportunity to mention related material or other important information.
This is any area of the web page that is not covered by typography or other content. You may feel the strong urge to fill as much empty space as possible but don't do it! Empty space is just as important to a good web page design as the content to be used. You can see how the NetTuts site uses empty space very effectively to help guide visitors through content, create page balance and give a good sense of content separation.
So that covers the anatomy of a web page. Now lets take a look at how the Golden Ratio relates to these elements.
Advertisement
Remember earlier when I said math was beautiful? We perceive visual appeal based on ratio (i.e. The Golden Ratio). For thousands of years artists, designers, architects, etc. have either intentionally or unintentionally used a common ratio in their work that is aesthetically pleasing. What is the magic number? 1.62 (actually 1.618...) I won't get into the origins of this number but I will tell you how to use it.

Using the golden ratio is very simple. Lets say you want to find the width of your Main Content and Sidebar columns. You would take the total width of your content area (we'll use 900px for this example) and divide that by 1.62. As shown in the example above we divide 900px by 1.62 and get 555.55px. We don't need to be exact so we will round it off to 555px. Now you know your main content element will be 555px wide and your sidebar will be 345px! How easy is that?!
But wait! The fun doesn't stop there. You can also apply the Golden Ratio to other element's width in relation to its height or vice-versa. This produces aesthetically pleasing elements with the Golden Ratio proportions.

If you're like most people though, you won't want to pull out a calculator every time you want to use this ratio. To simplify the process, we can use a simple grid. All you do is divide your width and/or height by thirds.

Each division can be even further reduced by thirds, producing a more detailed grid. If you read the previous article "A Close Look At the Blueprint CSS Framework" you will see that the Blueprint CSS framework uses a detailed grid system. Not only does the grid make designing easier and faster but also it creates an aesthetically pleasing layout! If you aren't already using a grid when designing, now may be a good time to give it a try. You can download a grid template for fireworks, photoshop and more from http://960.gs, which is another fantastic CSS framework that uses grids.

As you can see, Tuts+ abides by the Golden Ratio quite well. The top one third of the page is divided again into thirds to show how even the header section breaks down into smaller increments of thirds, very close to the Golden Ratio. No wonder why the NetTuts design is so appealing!
If you're new to design I highly encourage you to find some popular sites, evaluate their element layout and how it abides by the Golden Ratio and grids. Then take some time to practice using the Golden Ratio with your elements and placing them in your layout using a grid.

Alternatives to Prefixr

by

Awhile ago, the awesome Jeffrey Way created a tool called Prefixr which was meant to help with the onerous task of managing vendor prefixes in your stylesheets. It worked by analyzing your stylesheet and automatically adding the vendor prefixed version of different rules into an output that you could then paste into your file. It was a pretty slick tool.
Unfortunately, now that the site has gone the way of the dodo bird and after having several users ping us about it, we wanted to provide some alternatives that can help provide similar capabilities.

The Express Prefixr Library

The first option which is closest to the functionality of Prefixr is a site called Express Prefixr. This was created by the awesome TJ Holowaychuk who apart from being an expert on Node.js development, also created the Express web application framework for Node.js.
With Express Prefixr, you're presented with two textareas; one for entering your styles and the second to receive the prefixed output from the service. This is very similar to the way that Prefixr worked:
To test this out, I'm taking the same code sample that Jeffrey used in his original article:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
.box {
   opacity: .5;
}
  
.container {
   box-shadow: 20px;
   -moz-transition: box-shadow 2s;
   -webkit-border-radius: 4px;
   animation: slide 1s alternate;
   background: linear-gradient(top, #e3e3e3 10%, white);
}
  
@-webkit-keyframes "slide" {
   0% { left: 0; }
   100% { left: 50px; }
}
Then pressing on the "Prefix it!" button, I can immediately get my prefixed styles sent to me:
Here's the complete result:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
.box {
    -webkit-opacity: .5;
    -moz-opacity: .5;
    -ms-opacity: .5;
    -o-opacity: .5;
}
 
.container {
    -webkit-box-shadow: 20px;
    -moz-box-shadow: 20px;
    -ms-box-shadow: 20px;
    -o-box-shadow: 20px;
    -moz--webkit-transition: box-shadow 2s;
    -moz-transition: box-shadow 2s;
    -ms-transition: box-shadow 2s;
    -o-transition: box-shadow 2s;
    -webkit--webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    -ms-border-radius: 4px;
    -o-border-radius: 4px;
    -webkit-animation: slide 1s alternate;
    -moz-animation: slide 1s alternate;
    -ms-animation: slide 1s alternate;
    -o-animation: slide 1s alternate;
    background: linear-gradient(top, #e3e3e3 10%, white);
    background: -webkit-linear-gradient(top, #e3e3e3 10%, white);
    background: -moz-linear-gradient(top, #e3e3e3 10%, white);
    background: -ms-linear-gradient(top, #e3e3e3 10%, white);
    background: -o-linear-gradient(top, #e3e3e3 10%, white);
}
 
@-webkit-keyframes "slide" {
    0% {
        left: 0;
    }
 
    100% {
        left: 50px;
    }
}
Taking this further, Express Prefixr also provides an API that you can leverage to integrate into your applications or use third party tools like curl. So taking the following snippet:
1
curl http://expressprefixr.herokuapp.com/api/processor -d css='body { border-radius: 10px}'
And pasting it into my terminal window gives me the following results:
1
2
3
4
5
6
reys-mbp:~ rey$ curl http://expressprefixr.herokuapp.com/api/processor -d css='body { border-radius: 10px}'
body {
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    -ms-border-radius: 10px;
    -o-border-radius: 10px;
One final great thing about Express Prefixr, is that the code is available on GitHub allowing you to easily fork it and customize the software to your needs.

The Autoprefixer Library

The next option is actually designed to integrate more so into your workflow, rather than being a visual UI tool. Autoprefixer does in fact add prefixes where appropriate by using rules provided by the popular site, Can I Use. Autoprefixer's slogan is:
"Write your CSS rules without vendor prefixes (in fact, forget about them entirely)"
And it holds true. What this means is that in your stylesheets, you can focus on using the standards-based syntax and Autoprefixer will handle adding in the prefixed rules if necessary.
Let's look at some code:
1
2
3
:fullscreen a {
    transition: transform 1s
}
The above code will be updated by Autoprefixer to the following:
01
02
03
04
05
06
07
08
09
10
11
:-webkit-full-screen a {
    -webkit-transition: -webkit-transform 1s;
    transition: transform 1s
}:-moz-full-screen a {
    transition: transform 1s
}:-ms-fullscreen a {
    transition: transform 1s
}:fullscreen a {
    -webkit-transition: -webkit-transform 1s;
    transition: transform 1s
}
Take a close look at the syntax. Notice that the transition rule was pretty much left alone except for the addition of the two Webkit-specific entries. That's because Autoprefixer only applies vendor prefixes when it's appropriate. In this case, transition is widely supported in modern browsers and doesn't really need to be prefixed.
But, the :fullscreen pseudo-class is still evolving and does need to be properly prefixed. Autoprefixer, using the Can I Use data, is smart enough to determine when to prefix something based on a browser's level of support for a feature. Very cool!
The thing to note is that Autoprefixer is meant to be incorporated into your normal deployment workflow. It's not a client-side library and you leverage it via any number of third party integrations. This includes:
And so many more options. Even the new Atom Editor now has the atom-autoprefixer package which shows that Autoprefixer is well-maintained.
If you'd like to see Autoprefixer in action, jump on over to the following demo and add a bunch of CSS rules that you've traditionally had to vendor prefix and see how it works for you.

The -Prefix-Free Library

The final option is a great client-side library by Lea Verou called -prefix-free. Lea's been a long-time advocate of cross-browser development and built this library to, as a bit of a shim, ensure that your site uses all of the proper vendor prefixes. She built it at a time where, unfortunately, many web developers were simply forgetting to add all of the appropriate prefixes, causing sites to not render properly across all modern browsers.
The key difference between this and the two others I mentioned previously is that -prefix-free is a JavaScript library that looks at your stylesheets in runtime and adds the vendor prefixes when needed.
Using the library is as simple as adding the following line to the head of your page:
1
<script src="prefixfree.js"></script>
No, seriously. That's it. The library handles the processing of every stylesheet in link or style elements and adds a vendor prefix where needed. This is especially useful for sites that are already deployed and it may not be possible to go back and update it.
It also has solid browser support being compatible with IE9+, Opera 10+, Firefox 3.5+, Safari 4+ and Chrome on desktop and Mobile Safari, Android browser, Chrome and Opera Mobile on mobile.

Hoping Vendor Prefixes Go Away

It's great to have alternatives to Prefixr and these solutions certainly fit the bill. Ultimately, though, vendor prefixes have become more complicated than they're worth and with many developers not respecting the original intent of them (for example, to designate experimental features) and leveraging them in production systems, hopefully they'll go away in the near future.
Thankfully, Google mentioned when they announced their Blink rendering engine, that they would be shifting to a feature-flag model which would hide experimental features behind hard-to-set flags which aren't accessible via code. Thank goodness!

 

Copyright @ 2013 Krobknea.

Designed by Next Learn | My partner