HTML & CSS · Senior · Question 11 of 75

Why is em often recommended over px for media query breakpoints?

Explanation

In media queries, em and rem are based on the browser's initial font size (usually 16px), not on page styles. If a user enlarges the base font, the layout switches to the "narrow" version sooner - text won't be cramped. With px that doesn't happen. Tailwind v4 defines breakpoints in rem for the same reason.

Further reading

Problem with a question

HTML & CSS · Senior · question 11

Test yourself

Take the HTML & CSS · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz