Web Design. Web Development. Web Hosting.
0 items

Embedding images in CSS

Need some help? We are here for you!

We have a very friendly service - Come and chat to us and let us know what you need, we work for an hourly fee and can also provide you a no obligation quote and begin work immediately in most cases. Click "Request Support" or use our Live Chat.

Request support

Embedding images into your CSS is one of those things that might sound unfavourable but in fact gives you many benefits. First and foremost it can lower the number of requests your webpage needs to make, every connection to every resource requires a handshake, negotiation and then download. The more you have in one file, generally the better the performance. This is why some tools will give hints such as embedding the image into the CSS or using Sprites (which I will not cover in this article, and which I think are a horrible HACK in general).

Please bare in mind, it is recommended you only do this for very small images, maximum 2KB in size – don’t use this technique for large images as you have to remember that the browser is going to be needing that CSS file in order to render your pages, so if you have a enormous CSS file it is really going to have an opposite effect and will cause serious bottleneck to your web page load times.

So if you have things like buttons, small badges, small background images then you should seriously consider embedding them into the CSS to save on requests and resource load times.

So this is achievable by generating a BASE64 encoded string of the image file and then referencing it in CSS, much like when you embed an image into HTML IMG tags. We have a tool already which can take an image file and convert it to a BASE64 embeddable string which you can find below.

Embed Image into CSS

Let us know what you think of the tool.

How to embed image into CSS

The first thing you are going to want to do is convert your image into a BASE64 encoded string, the tool above can do this for you, and here is an example image I have done:


To embed this into CSS you would do this:

.myclass {

And thats it!

0 0 votes
Article Rating
Need some help? We are here for you!

We have a very friendly service - Come and chat to us and let us know what you need, we work for an hourly fee and can also provide you a no obligation quote and begin work immediately in most cases. Click "Request Support" or use our Live Chat.

Request support
Author: Dean WilliamsProfessional PHP Web Developer with expertise in OpenCart Web Development, WordPress Web Development, Bespoke Systems - also a seasoned Linux Server Administrator.

Notify of
Inline Feedbacks
View all comments

Share this page..

Let's begin your journey...

Get in touch us now to begin your journey to having a beautifully crafted mobile responsive website. If you're still unsure what we could do for you then take a look at our why us page which includes reviews, or take a look at our portfolio.

We can work on improving existing websites or craft a new stylish website making your business stand out.

You could always catch us by email, telephone, Skype or live chat to us below.

    Would love your thoughts, please comment.x