1

I've seen that it's possible to specify the image size using pixels, but pixels isn't a great way to specify image size. I've tried

<img src="myimg.png" style="width:20em" />

but that didn't work (although Markdown Viewer for Chrome rendered it)

Is it even possible to specify the size with another size unit other than pixels?

0

1 Answer 1

4

No, you need to define width and/or height attributes to define an image's size, and those attributes only support pixel units. GitHub does no support using the style attribute.

As documented in the github/markup project:

This library is the first step of a journey that every markup file in a repository goes on before it is rendered on GitHub.com:

  1. This library converts the raw markup to HTML. See the list of supported markup formats below.
  2. The HTML is sanitized, aggressively removing things that could harm you and your kin—such as script tags, inline-styles, and class or id attributes. See the sanitization filter for the full whitelist.
  3. Syntax highlighting is performed on code blocks. See github/linguist for more information about syntax highlighting.
  4. The HTML is passed through other filters in the html-pipeline that add special sauce, such as emoji, task lists, named anchors, CDN caching for images, and autolinking.
  5. The resulting HTML is rendered on GitHub.com.

Of note is step 2. Specifically style tags are stripped from any user provided content on GitHub's website. However, a review of the sanitation filter indicates that height and width attributes are whitelisted and not stripped. Note that width and height attributes can only use pixels as units. Therefore, you cannot us any other type of units to define an image size. Your img tag may look like this:

<img src="myimg.png" width="20" />

Of course, you'll need to adjust the actual size to your desired value.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.