Creating a custom html button with background Image and Text

learner2010 picture learner2010 · Dec 9, 2011 · Viewed 71k times · Source

I would like to know how I can create a custom HTML button which has a background Image and I can show a custom text over that image.

For example, I would like to show a submit button for which I have a background image for that button and the text "Submit" comes on top of that Image.

I tried this -

<input type="button" value="Submit" style="background-image: url(pages/images/ButtonBackground.png);">

However, it does not work properly. I just see the test submit and the button but the image does not show up.

It would be great if someone could help me out with this.

Answer

Saeed Neamati picture Saeed Neamati · Dec 9, 2011

I recommend that you use <button> instead of <input type='submit' /> or <input type='button' />. The reason is that you can embed HTML elements (nest elements) into the <button> element. This way, you can make a much more flexible button, which can be customized even more.

<button>
    <span class='image'></span>
    <span class='text'>Click Me!</span>
</button>