0

The most upvoted or accepted answers to this question are 10+ years old (2012). Trying to center an image using the idea they propose:

<p align="center">
    <a href="https://www.yiiframework.com/" target="_blank">
        <img src="https://www.yiiframework.com/image/yii_logo_light.svg" width="400" alt="Yii Framework" />
    </a>
</p>

Causes my WebStorm yelling at me:

enter image description here

When I follow the "correct" (according to WebStorm) way:

<p style="text-align: center">
    <a href="https://www.yiiframework.com/" target="_blank">
        <img src="https://www.yiiframework.com/image/yii_logo_light.svg" alt="Yii Framework" />
    </a>
</p>

Then image is not centered at all in GitHub front page of given repository (showing contents of README.md).

I have also tried this solution adapted to GitHub reality (no <style> tag supported):

<a href="https://www.yiiframework.com/" target="_blank">
    <img src="https://www.yiiframework.com/image/yii_logo_light.svg" alt="Yii Framework" style="display:block;margin-left:auto;margin-right:auto;" />
</a>

But, again, no effect -- image is again "glued" to the left margin.

So... which code must I use today (2023) to have image in README.md in GitHub centered, using methods that are not obsolete today?

trejder
  • 17,148
  • 27
  • 124
  • 216
  • 3
    Yes, `

    ` works. It doesn't matter that Webstorm points out the attribute is deprecated. [How do I center an image in the README.md file on GitHub?](https://stackoverflow.com/questions/12090472/how-do-i-center-an-image-in-the-readme-md-file-on-github)

    – Andy Ray Jun 24 '23 at 21:13
  • @AndyRay An interesting point of view, if I may say so. Exactly why it doesn't matter? Why should I ignore world standards? Or should I rather assume that Markdown does not support align at all and therefore none-standard or deprecated solutions may be needed to workaround this? – trejder Jun 26 '23 at 07:34
  • Note that GitHub documents their markup processing [here](https://github.com/github/markup#github-markup). Specifically, in step 2, they run all generated HTML through a sanitizer which removes all user provided styles (among other things). The only method which GitHub does not interfere with is using the `align` attribute. Therefore, that is the only method which works. – Waylan Jun 26 '23 at 14:07

0 Answers0