Image for post
Image for post

The Golden Ratio in SASS and CSS development

Mate Marschalko
Jan 5, 2016 · 3 min read

I recently worked on a web site project where the design I received to work on had multiple cards that seemed very much close to what I remembered as the golden ratio but after measuring them I realised the designer didn’t actually follow the rule and I decided to amend it.

The golden ratio is the ratio of 1 to 1.6180334 that seem to appear very often in Nature. Many scientists and artists believe that the human eye finds this ratio beautiful. Read more about this magic number on livesience.

Image for post
Image for post
The golden ratio appearing in Nature

Double checking the designs is one of the times when your golden mean caliper would come in handy … just make sure you don’t show your tool to the designer if you don’t want to upset anyone.

Image for post
Image for post
A Golden Mean Caliper

The actual idea I’m promoting here is to start using the golden ratio in your development work and if you notice a ratio in a design that is very close but not actually 1 to 1.618 then amend it after discussing it with the designer as it will probably look better in most cases.

Using the golden ratio in SASS

For a very simple example we start off by storing the ratio in a variable in SASS.

$phi: 1.6180339887498948482;

Later on we can use this variable for calculating the sizes of two boxes:

$base-width: 250px;.smaller-box {
width: $base-width;
height: $base-width;
}
.larger-box {
width: $base-width * $phi;
height: $base-width;
}

Or to create a golden rectangle:

.golden-box {
height: 100px;
width: 100px * $phi;
}
Image for post
Image for post

The golden ratio can also be applied to section a circle and the full 360˚ angle. You can try experimenting with the golden angles which are 222.5˚ and 137.5˚.

This is how you can calculate this with SASS:

$phi: 1.6180339887498948482;$small-angle: 360 / ($phi + 1);    // 137.5
$large-angle: 360 - $small-angle; // 222.5

I hope this simple example sparkled some creative ideas for your next project and that you already ordered your caliper from Amazon.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade