HTML & CSS Cheatsheet

Free searchable HTML and CSS cheatsheet: page structure, forms, tables, accessibility, selectors, flexbox, grid, units and responsive design.

Frequently asked questions

Should I use flexbox or grid?

Use flexbox to lay items out in one direction, such as a row of buttons or a navigation bar. Use grid when you need rows and columns together, such as a page layout or a set of cards. They work well together: a grid of cards, each laid out with flexbox.

What is the difference between rem and em?

rem is relative to the root font size, usually set on the html element, so 2rem is the same everywhere. em is relative to the font size of the current element, so it grows inside larger text. rem is easier to predict for most sizes.

Why does every image need alt text?

Screen readers read the alt text aloud, and browsers show it when an image cannot load. Describe what the image shows or why it is there. For images that are only decoration, use an empty alt="" so screen readers skip them.