CSS
HTML
JavaScript
jQuery
PHP
SQL
WordPress
CSS Reference

Quick Reference

CSS has several different units for expressing a length either as an absolute value or relative to another element’s value or the screen size itself.

				
					p {
    font-size: 2em;
}
				
			

Absolute Lengths

Absolute length units are fixed, and the length expressed in any of these will appear at exactly that size regardless of the screen size. This can cause issues because screen sizes vary so much from the very large to the small mobile device. Often, relative lengths would be a better choice.

UnitDescriptionExample
cmcentimeterswidth: 2cm;
mmmillimeterswidth: 20mm;
ininches (1in = 96px = 2.54cm)
width: 2in;
px *pixels (1px = 1/96th of 1in)
width: 96px;
ptpoints (1pt = 1/72 of 1in)
width: 72pt;
pcpicas (1pc = 12 pt)
width: 24pc;

*the density of pixels varies from screen to screen depending on the device and/or manufacturer

Relative Lengths

Relative length units specify a length relative to another element’s length property or even the screen size itself. Relative length units scale much better between the varying screen sizes.

UnitDescriptionExample
emRelative to the font-size of the element (3em means 3 times the size of the current font)width: 6em;
exRelative to the x-height of the current font (rarely used)width: 6ex;
chRelative to the width of the “0” (zero)width: 6ch;
remRelative to font-size of the root elementwidth: 6rem;
vwRelative to 1% of the width of the viewport (browser window size)width: 6vw;
vhRelative to 1% of the height of the viewport (browser window size)width: 6vh;
vminRelative to 1% of the viewport’s (browser window size) smaller dimensionwidth: 60wmin;
vmaxRelative to 1% of the viewport’s (browser window size) larger dimensionwidth: 60vmax;
%Relative to the element’s parent elementwidth: 60%;

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.

CSS
HTML
JavaScript
jQuery
PHP
SQL
WordPress

Why 1SMARTchicken?

This site was built and is maintained to benefit my autistic son.
See More →

My Son's Name is Johnny

He was diagnosed as autistic quite late, at age four...
His story

Buy Me a Coffee

Thanks for your support!

Feedback

If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.