Welcome to Codidact Meta!
Codidact Meta is the meta-discussion site for the Codidact community network and the Codidact software. Whether you have bug reports or feature requests, support questions or rule discussions that touch the whole network – this is the site for you.
Can I use SVG in posts?
Do Codidact posts support SVG (Scalable Vector Graphics) for images and animations?
I can't get either the image upload button or inline SVG to work. Is SVG not supported?
1 answer
SVG is only supported in an img tag
SVG is only supported inside an HTML <img>
tag, or a Markdown image link (which is rendered as an <img>
tag behind the scenes).
The image upload button
The image upload button above a post during editing only supports PNG, JPEG, and GIF files. These generally correspond to file extensions .png
, .jpg
/.jpeg
, and .gif
. The content of the file is checked, so changing the file extension of an SVG file won't help you.
Inline SVG
A Codidact post supports a safe subset of HTML. This means that not all tags are supported. Specifically, the <svg>
tag is not supported.
Discussion
If you have reason to believe that either of these could be supported safely, I have started a discussion post Should inline SVG or SVG uploads be supported in posts?
In the meantime an external link is the only available option.
How to include SVG
Still images
In order to include an SVG file in a post, it will need to be hosted online so that you can include its URL. For example, the SVG logo is hosted online by Wikimedia and can be used in a post by including either of the following:
Markdown

HTML
<img
src="https://upload.wikimedia.org/wikipedia/commons/4/4f/SVG_Logo.svg"
alt="The SVG logo">
In the saved post, this is rendered as:
Scaled still images
Adjusting the size of the image is not supported in Markdown (at least not in CommonMark, the flavour of Markdown used by Codidact), but with an <img>
tag a width can be specified:
<img
src="https://upload.wikimedia.org/wikipedia/commons/4/4f/SVG_Logo.svg"
alt="The SVG logo"
width="100">
This will be rendered as:
Note that on mobile devices with narrow screens, the image will already be scaled to fit the width, so there is no need to specify a width like this unless you want the image to be narrower than the screen/window.
Scaling in this way works for all supported image types, not just SVG, as described in an answer to How to resize images. If you would like to have the ability to rescale images without need for HTML, you could add to the discussion there.
Animations
Animated SVG files can be included in exactly the same way. For example, an animation I uploaded to GitHub can be used in a post by including either of the following:
Markdown

HTML
<img
src="https://raw.githubusercontent.com/trichoplax/centered-hexagonal-number-animation/main/animation/centered_hexagonal_numbers.svg"
alt="Animation of a growing grid of hexagons">
Hidden animations
Out of consideration for other users, and for accessibility, I recommend hiding animations and clearly labelling them as such, so that each user can choose whether or not to view them. The previous example text will give a large animated image that not everyone will want to see. Either of the following will give the same animated image hidden until a user chooses to view it:
Markdown
<details>
<summary>
Animated visualisation
</summary>

</details>
Note that there is a blank line after the closing </summary>
tag, and there is no indentation of the Markdown image link. Both of these are required, otherwise the raw Markdown will be rendered instead of the image. If you prefer consistent indentation and no blank line, you can use the fully HTML version shown below.
HTML
<details>
<summary>
Animated visualisation
</summary>
<img
src="https://raw.githubusercontent.com/trichoplax/centered-hexagonal-number-animation/main/animation/centered_hexagonal_numbers.svg"
alt="Animation of a growing grid of hexagons">
</details>
In the saved post the image will look like this:
Animated visualisation
Scaled animations
Adjusting the size of an animated image can be achieved in the same way as for a still image, by specifying a width in an <img>
tag:
<details>
<summary>
Scaled down animated visualisation
</summary>
<img
src="https://raw.githubusercontent.com/trichoplax/centered-hexagonal-number-animation/main/animation/centered_hexagonal_numbers.svg"
alt="Animation of a growing grid of hexagons"
width="100">
</details>
In the saved post the animation will look like this:
Scaled down animated visualisation
Inline animations
A sufficiently small image or animation can be displayed inline within a paragraph. Adjusting the width can help fine tune this:
<details>
<summary>
Tiny inline animated visualisation
</summary>
<p>
For some reason there is a
<img
src="https://raw.githubusercontent.com/trichoplax/centered-hexagonal-number-animation/main/animation/centered_hexagonal_numbers.svg"
alt="Animation of a growing grid of hexagons"
width="16">
in the middle of this paragraph.
</p>
</details>
This will be rendered as:
Tiny inline animated visualisation
For some reason there is a
in the middle of this paragraph.
0 comment threads