
The URL fragment is the part that comes after the # character. There are two places in a URL that you can overload to carry information that CSS can use: the URL fragment, and URL query parameters. Later I’ll show you some undesirable CSS-related techniques too. In this section I’ll discuss these possibilities. Modern CSS syntax can select elements based on the values of their attributes, so one way to apply CSS rules is to encode extra information into Markdown’s standard src attribute. In general, the best way to style images is with CSS. Thus, many people dislike this solution because it defeats the purpose of Markdown.

This works, and gives you unrestrained control over the resulting HTML.īut Markdown is appealing for its simplicity, unlike HTML that’s cluttered with messy markup. Markdown was originally designed for HTML authoring, and permits raw HTML anywhere, anytime.Īs such, the most straightforward solution is simply to use HTML with the desired attributes: I’ll show you the best solutions first, and the undesirable ones last. I won’t show you how to add alignment, floating, or padding-but my sizing example will suffice, because once you know how to change an image’s size, you’ll know how to do other things too. To motivate this discussion, I’ll use the example of a large image that should be displayed at a smaller size.įor example, !(/media/2018/08/kitten.jpg "A cute kitten") The rest of this post is dedicated to various solutions to these shortcomings. Standard Markdown doesn’t offer anything beyond this, but it’s very common for websites to need width, height, and CSS class attributes as well. That is, Markdown allows you to specify an tag with src, alt, and title attributes in HTML.


Here’s how you insert an image in Markdown: !(/src/of/image.jpg "title") This post presents a variety of ways to format images with Markdown, from brute force to proprietary syntax extensions, unwise hacks, and everything in between. Markdown is a convenient HTML-focused shorthand syntax for formatting content such as documentation and blog articles, but it lacks basic features for image formatting, such as alignment and sizing.
