Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
216,135 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.