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

Alex Hird
Alex Hird
2,767 Points

Difference between setting %'s and px for margins, width's and height.

Just wondering, what's the main difference with setting %'s or px for height, width, margins etc. Just getting into CSS and presenting the HTML structure and just trying to figure it out.

Many thanks

1 Answer

Steven Parker
Steven Parker
228,978 Points

Pixel dimensions are rigid. Anything sized with them will be the same size on any window or screen.

Percentage dimensions will expand and contract with the size of their container, typically a result of different screen sizes.

So one common use for the difference is whether you want the element you are styling to dynamically adjust to screen sizes, or always be the same on every screen. There are several courses here that explore practical applications for both types for dimensions.

Alex Hird
Alex Hird
2,767 Points

thanks for reply, very helpful.