HTML & CSS · Junior · Question 36 of 75

Why doesn't a ::before with only width, height and background show up?

Explanation

::before and ::after are generated only when content is set - even empty: content: "". They are also inline by default, so sizing needs display: block or inline-block (or positioning). They don't work on replaced elements like <img> and <input>.

Further reading

Problem with a question

HTML & CSS · Junior · question 36

Test yourself

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

Take this quiz