HTML & CSS · Senior · Question 9 of 75

Why don't ::before and ::after work on <img> and <input>?

Explanation

::before/::after are inserted inside the element, before and after its content. The content of <img>, <video>, <iframe> is replaced by an external resource, while <input> and <br> are void elements. The workaround is to wrap the element in a container and attach the pseudo-element to it. display is irrelevant: pseudo-elements work on an inline <span>.

Further reading

Problem with a question

HTML & CSS · Senior · question 9

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