EM Chart

top feature image

EM Chart

Using a relative unit such as EM is a great way to maintain the vertical rhythm of a web page when a user resizes text in their browser. Constantly reaching for a calculator to compute the correct EM value to use every time you need to is also a great way to drive yourself mad.

Let’s say you have an H3 that’s 24 pixels. It doesn’t matter how the font-size is set (pixels, EMs, percentages, etc). You can check the actual font-size in pixels using Firebug by checking “Show Computed Style” in the Options menu in the upper right corner of the CSS/Style panel while viewing in HTML mode.

You’ve checked the design comp and measured exactly 9 pixels of bottom margin under the H3 until the next element. Of course you can set the bottom-margin of the H3 to 9 pixels and move on. But that won’t scale when a user bumps up their text size in their browser and your vertical rhythm will crumble as the H3 grows in size but keeps the same 9 pixels of bottom margin.

The Formula

The formula for computing the EM multiplier is:

desired pixel size / current pixel size = multiplier

So for the H3 example: 9/24 = .375

The Chart

It’s a handy formula to memorize, but it’s still lame to punch it into a calculator dozens of times a day. I figured it couldn’t be too hard to loop through the formula in PHP or JavaScript to create a lookup chart. So I whipped it up in PHP then later changed it to JavaScript to keep it more portable. The EmChart places desired pixel size in the columns, and current pixel size in the rows. Here’s a screen shot of looking up our H3 example.

em chart 1

Everyday Usage

I use the EmChart all the time when converting design comps to HTML/CSS templates – which is basically all day every day. I find it very useful for calculating bottom margins, line-heights (which are unit-less, but the formula still applies), top margins, and top/bottom padding among other things. It’s also really handy for keeping nested relative font-sizes straight. The CSS and JavaScript is all included within the HTML page to keep it portable. I actually launch it as a standalone application using Fluid (Mac). Feel free to copy the source and use it as you’d like. But get in touch if you make any derivatives.

As I mentioned, it doesn’t matter how your current font-size is set. So this will work for you regardless of what font-size or unit is (or isn’t) set on the HTML element, BODY element, or any other element. You just need to know the effective pixel size of the current element you’re working with.

1px1px2px3px4px5px6px7px8px9px10px11px12px13px14px15px16px17px18px19px20px21px22px23px24px25px26px27px28px29px30px31px32px33px34px35px
2px0.511.522.533.544.555.566.577.588.599.51010.51111.51212.51313.51414.51515.51616.51717.5
3px0.3340.66711.3341.66722.3342.66733.3343.66744.3344.66755.3345.66766.3346.66777.3347.66788.3348.66799.3349.6671010.33410.6671111.33411.667
4px0.250.50.7511.251.51.7522.252.52.7533.253.53.7544.254.54.7555.255.55.7566.256.56.7577.257.57.7588.258.58.75
5px0.20.40.60.811.21.41.61.822.22.42.62.833.23.43.63.844.24.44.64.855.25.45.65.866.26.46.66.87
6px0.1670.3340.50.6670.83411.1671.3341.51.6671.83422.1672.3342.52.6672.83433.1673.3343.53.6673.83444.1674.3344.54.6674.83455.1675.3345.55.6675.834
7px0.1430.2860.4290.5720.7150.85811.1431.2861.4291.5721.7151.85822.1432.2862.4292.5722.7152.85833.1433.2863.4293.5723.7153.85844.1434.2864.4294.5724.7154.8585
8px0.1250.250.3750.50.6250.750.87511.1251.251.3751.51.6251.751.87522.1252.252.3752.52.6252.752.87533.1253.253.3753.53.6253.753.87544.1254.254.375
9px0.1120.2230.3340.4450.5560.6670.7780.88911.1121.2231.3341.4451.5561.6671.7781.88922.1122.2232.3342.4452.5562.6672.7782.88933.1123.2233.3343.4453.5563.6673.7783.889
10px0.10.20.30.40.50.60.70.80.911.11.21.31.41.51.61.71.81.922.12.22.32.42.52.62.72.82.933.13.23.33.43.5
11px0.0910.1820.2730.3640.4550.5460.6370.7280.8190.9111.0911.1821.2731.3641.4551.5461.6371.7281.8191.9122.0912.1822.2732.3642.4552.5462.6372.7282.8192.9133.0913.182
12px0.0840.1670.250.3340.4170.50.5840.6670.750.8340.91711.0841.1671.251.3341.4171.51.5841.6671.751.8341.91722.0842.1672.252.3342.4172.52.5842.6672.752.8342.917
13px0.0770.1540.2310.3080.3850.4620.5390.6160.6930.770.8470.92411.0771.1541.2311.3081.3851.4621.5391.6161.6931.771.8471.92422.0772.1542.2312.3082.3852.4622.5392.6162.693
14px0.0720.1430.2150.2860.3580.4290.50.5720.6430.7150.7860.8580.92911.0721.1431.2151.2861.3581.4291.51.5721.6431.7151.7861.8581.92922.0722.1432.2152.2862.3582.4292.5
15px0.0670.1340.20.2670.3340.40.4670.5340.60.6670.7340.80.8670.93411.0671.1341.21.2671.3341.41.4671.5341.61.6671.7341.81.8671.93422.0672.1342.22.2672.334
16px0.0630.1250.1880.250.3130.3750.4380.50.5630.6250.6880.750.8130.8750.93811.0631.1251.1881.251.3131.3751.4381.51.5631.6251.6881.751.8131.8751.93822.0632.1252.188
17px0.0590.1180.1770.2360.2950.3530.4120.4710.530.5890.6480.7060.7650.8240.8830.94211.0591.1181.1771.2361.2951.3531.4121.4711.531.5891.6481.7061.7651.8241.8831.94222.059
18px0.0560.1120.1670.2230.2780.3340.3890.4450.50.5560.6120.6670.7230.7780.8340.8890.94511.0561.1121.1671.2231.2781.3341.3891.4451.51.5561.6121.6671.7231.7781.8341.8891.945
19px0.0530.1060.1580.2110.2640.3160.3690.4220.4740.5270.5790.6320.6850.7370.790.8430.8950.94811.0531.1061.1581.2111.2641.3161.3691.4221.4741.5271.5791.6321.6851.7371.791.843
20px0.050.10.150.20.250.30.350.40.450.50.550.60.650.70.750.80.850.90.9511.051.11.151.21.251.31.351.41.451.51.551.61.651.71.75
21px0.0480.0960.1430.1910.2390.2860.3340.3810.4290.4770.5240.5720.620.6670.7150.7620.810.8580.9050.95311.0481.0961.1431.1911.2391.2861.3341.3811.4291.4771.5241.5721.621.667
22px0.0460.0910.1370.1820.2280.2730.3190.3640.410.4550.50.5460.5910.6370.6820.7280.7730.8190.8640.910.95511.0461.0911.1371.1821.2281.2731.3191.3641.411.4551.51.5461.591
23px0.0440.0870.1310.1740.2180.2610.3050.3480.3920.4350.4790.5220.5660.6090.6530.6960.740.7830.8270.870.9140.95711.0441.0871.1311.1741.2181.2611.3051.3481.3921.4351.4791.522
24px0.0420.0840.1250.1670.2090.250.2920.3340.3750.4170.4590.50.5420.5840.6250.6670.7090.750.7920.8340.8750.9170.95911.0421.0841.1251.1671.2091.251.2921.3341.3751.4171.459
25px0.040.080.120.160.20.240.280.320.360.40.440.480.520.560.60.640.680.720.760.80.840.880.920.9611.041.081.121.161.21.241.281.321.361.4
26px0.0390.0770.1160.1540.1930.2310.270.3080.3470.3850.4240.4620.50.5390.5770.6160.6540.6930.7310.770.8080.8470.8850.9240.96211.0391.0771.1161.1541.1931.2311.271.3081.347
27px0.0380.0750.1120.1490.1860.2230.260.2970.3340.3710.4080.4450.4820.5190.5560.5930.630.6670.7040.7410.7780.8150.8520.8890.9260.96311.0381.0751.1121.1491.1861.2231.261.297
28px0.0360.0720.1080.1430.1790.2150.250.2860.3220.3580.3930.4290.4650.50.5360.5720.6080.6430.6790.7150.750.7860.8220.8580.8930.9290.96511.0361.0721.1081.1431.1791.2151.25
29px0.0350.0690.1040.1380.1730.2070.2420.2760.3110.3450.380.4140.4490.4830.5180.5520.5870.6210.6560.690.7250.7590.7940.8280.8630.8970.9320.96611.0351.0691.1041.1381.1731.207
30px0.0340.0670.10.1340.1670.20.2340.2670.30.3340.3670.40.4340.4670.50.5340.5670.60.6340.6670.70.7340.7670.80.8340.8670.90.9340.96711.0341.0671.11.1341.167
31px0.0330.0650.0970.130.1620.1940.2260.2590.2910.3230.3550.3880.420.4520.4840.5170.5490.5810.6130.6460.6780.710.7420.7750.8070.8390.8710.9040.9360.96811.0331.0651.0971.13
32px0.0320.0630.0940.1250.1570.1880.2190.250.2820.3130.3440.3750.4070.4380.4690.50.5320.5630.5940.6250.6570.6880.7190.750.7820.8130.8440.8750.9070.9380.96911.0321.0631.094
33px0.0310.0610.0910.1220.1520.1820.2130.2430.2730.3040.3340.3640.3940.4250.4550.4850.5160.5460.5760.6070.6370.6670.6970.7280.7580.7880.8190.8490.8790.910.940.9711.0311.061
34px0.030.0590.0890.1180.1480.1770.2060.2360.2650.2950.3240.3530.3830.4120.4420.4710.50.530.5590.5890.6180.6480.6770.7060.7360.7650.7950.8240.8530.8830.9120.9420.97111.03
35px0.0290.0580.0860.1150.1430.1720.20.2290.2580.2860.3150.3430.3720.40.4290.4580.4860.5150.5430.5720.60.6290.6580.6860.7150.7430.7720.80.8290.8580.8860.9150.9430.9721
36px0.0280.0560.0840.1120.1390.1670.1950.2230.250.2780.3060.3340.3620.3890.4170.4450.4730.50.5280.5560.5840.6120.6390.6670.6950.7230.750.7780.8060.8340.8620.8890.9170.9450.973
%d bloggers like this: