Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Basics (2014) Understanding Values and Units Percentages

Andy tran
Andy tran
7,112 Points

when do we use px ?and when do we use %?

im not sure when to use px and when to use percentage

2 Answers

I might be wrong but I just use them interchangeably. I tend to prefer percentages as when you resize your browser windows or if you were on a different device the content will change to the percentage of the viewport. If you use pixels and resize your browser the things that you have applied the size to will not change to match the window and may end up being unproportional to the page size.

i think you should only use px when you know the size of the screen if what ever it is you're deploying to. also if you believe that the screen size may change sometime in the future you should not use px. for everything else use a relative unit.