Using rems for responsive text

Feb 19, 2014

CSS

While working on an old project I wanted to make it responsive. While doing this I faced the usual task of resizing the header font.

However, I didn’t want to have loads of media queries to set the size at specific breakpoints.

Therefore I decided to do some research and stumbled across REMs (Responsive Ems). I found this blog post and it gave a quick intro into the world of Ems from being used to pixel land.

To use responsive Em’s, basically set the initial html font size as 100%, then at specific break points change the body font size via the body tag in rems, not px. This way you only have to declare one size and all your text will adhere to it.

1html {
2 font-size: 100%;
3}
4
5body {
6 @media (max-width: 640px) { font-size: 1.2rem; }
7 @media (min-width: 640px) { font-size: 1rem; }
8 @media (min-width: 960px) { font-size: 1.2rem; }
9 @media (min-width: 1100px) { font-size: 1.5rem; }
10}
CSS

Contact.

LET'S WORK

TOGETHER

I am open to both contract and freelance developer projects and would love to hear what your ideas are.

Feel free to drop me an email and I'll let you know how I can help you!

mail@benstokoe.co.uk