CSS CSS Basics 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.

Andre Johnson
Andre Johnson
3,857 Points

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.