Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS Framework Basics Build a Website with Bootstrap Adding the Feature Icons

Sam Easterling
Sam Easterling
10,216 Points

Why use the pseudo class to insert the icons instead of using an img inside the html?

Why use the pseudo class to insert the icons instead of using an img inside the html?

2 Answers

Jeff Lemay
Jeff Lemay
14,268 Points

Of course you could do it with an img in the html but Treehouse teaches us to keep styles separate from content (a phone symbol is styling, the phone number is content).

Also, if you put the images in your html, people with screen readers would unnecessarily have to stop just to hear "phone icon" before they hear the actual phone number.

Because all the cool kids do it. :-)

But really there is only one good explanation to it, the image tag will form extra, unneeded tag in your html that might mess with you layout, will need to be styled and so on. Where is ::before or ::after puts the content inside the element specified before the pseudo element in css.

In other words, ::before or ::after generates a content of an element or a tag, and does not creates additional tag like an image tag would, that is why I use it as much as possible.

Best of luck, CSS has been messing with all of us :-)