+ 2
What's the difference between 20px and 20% in css
2 Answers
+ 2
px are absolute units (size hold same) while % its a relative unit (size depend on another size)... At example if you set an div to be 20px width it will be always 20px but if you set to 20%, widh of div will be 20% of parent div then if parent width is 100px, div width will be 20px, if parent width 400px, div width 80px
- 1
âą 20% is based on screen size (width/height).
eg:- <hr width="20%/> will show a horizontal line from 0% to 20% of the screen.
âą 20px is pixel based (pixels are squares that filled with colour).
eg:- <hr width="20px"/> will show a horizontal line with 20 pixels widh.