what is the difference between px and % ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

what is the difference between px and % ?

12th Nov 2016, 1:10 PM
esraa hanafy
4 Answers
+ 2
"px" is relative to the number of pixels of the screen. "%" is relative to a certain dimension of the containing block (the tag). E.g.: #box1 { width: 50%; height: 50%; } #box2 { width: 50%; height: 50%; } <body> <div id="box1"> <div id="box2"/> </div> </body> box1 has half width and length of body and box2 has half width and length of box1.
12th Nov 2016, 2:01 PM
Gleb Golov
Gleb Golov - avatar
+ 1
A percentage means that depending on the width of the window, the width will change. A pixel width means that no matter the window size, the width will always be the same. One has application for fluid-layouts (%) and the other for fixed-width layouts (px)
12th Nov 2016, 2:50 PM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar
+ 1
px is ervery time the same but the % is on every website different
15th Nov 2016, 3:14 PM
anne_german
0
Set body width to 80% and the other to 800 pixels. Resize your browser and see the difference.
16th Nov 2016, 8:34 AM
Core i9
Core i9 - avatar