<?xml version="1.0" encoding="utf-8"?>

CSS percentage (%)

A length set in percentage (%) is based on the length of the same property of the parent element. In the example, the yellow-box is the child of the purple-box. No matter how much the width of the purple-box (parent) changes, the width of the yellow-box(child) will always be 90% of that.

Percentage isn't technically a length unit, but it's similar to relative length units that specify a length relative to another length property. Percentage and relative length units are great for both screen and print media types and are the most frequently used CSS units.

Pro Tip: When developing for the web, you'll mostly be using %, px and em.

Improve your UX & Product skills with interactive courses that actually work