Title: CSS to Center Image
Last modified: October 13, 2021

---

# CSS to Center Image

 *  Resolved [jaket89](https://wordpress.org/support/users/jaket89/)
 * (@jaket89)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/css-to-center-image/)
 * Hi, Can anyone please help me fill in the CSS below to center the image:
 *     ```
       add_action('woocommerce_after_add_to_cart_button', 'add_content_on_add_to_cart_button');
   
       function add_content_on_add_to_cart_button() {
             echo "<img src='image.png' width="70%" />"; 
       }
       ```
   
 * TIA
    -  This topic was modified 4 years, 7 months ago by [jaket89](https://wordpress.org/support/users/jaket89/).
    -  This topic was modified 4 years, 7 months ago by [jaket89](https://wordpress.org/support/users/jaket89/).
    -  This topic was modified 4 years, 7 months ago by [jaket89](https://wordpress.org/support/users/jaket89/).

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Tim Burkart](https://wordpress.org/support/users/bigmoxy/)
 * (@bigmoxy)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/css-to-center-image/#post-14967492)
 * Hi,
 * Can you add a CSS class to the echo statement so you can style it in the customizer?
   Have you tried style=”margin: 0 auto;”?
 * Is the image on a new line by itself?
 *  Thread Starter [jaket89](https://wordpress.org/support/users/jaket89/)
 * (@jaket89)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/css-to-center-image/#post-14967865)
 * Hi,
    The code is written exactly as you see it in the post above. This code is
   in the functions.php file.
 * I tried adding your bit of code in-line, above and below but it didn’t work.
 * Sorry but I’m a complete novice when it coems to this stuff.
 * Thanks
 *  [Mirko P.](https://wordpress.org/support/users/rainfallnixfig/)
 * (@rainfallnixfig)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/css-to-center-image/#post-14968385)
 * Hi [@jaket89](https://wordpress.org/support/users/jaket89/)!
 * Can we take a look at the page where you have positioned the image that needs
   to be centered?
 * Cheers.
 *  Thread Starter [jaket89](https://wordpress.org/support/users/jaket89/)
 * (@jaket89)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/css-to-center-image/#post-14968391)
 * Hi Mirko,
 * I sorted it out. The answer was to edit the line as below:
 * `echo "<img src='https://simplysupersteals.com/wp-content/uploads/2021/10/GREY-
   PAYMENT_TRUST_BADGES.png' style='display:block;margin-left: 15%;width: 70%;'>";`
 * Thanks
    -  This reply was modified 4 years, 7 months ago by [jaket89](https://wordpress.org/support/users/jaket89/).
 *  [Mirko P.](https://wordpress.org/support/users/rainfallnixfig/)
 * (@rainfallnixfig)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/css-to-center-image/#post-14968395)
 * Okay [@jaket89](https://wordpress.org/support/users/jaket89/)! Thanks for letting
   us know.
 * If you have any other questions please feel free to open a new thread.
 * Cheers.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘CSS to Center Image’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [Mirko P.](https://wordpress.org/support/users/rainfallnixfig/)
 * Last activity: [4 years, 7 months ago](https://wordpress.org/support/topic/css-to-center-image/#post-14968395)
 * Status: resolved