--- title: "Markdown Kramdown Tips & Tricks" author: Marcia Ramos author_twitter: xmdramos categories: engineering image_title: '/images/blogimages/markdown-kramdown-tips-and-tricks-cover.png' twitter_image: '/images/tweets/markdown-kramdown-tips-and-tricks.png' description: "Learn how to apply classes to markdown, create ToCs, embed iframes and much more!" --- If you use a markdown engine for writing your website content and you'd like to learn a few tricks to have more freedom with it, this post is for you. The markdown engine we use for [about.GitLab.com] is [Kramdown], and that is the one we'll be referring to on this post. **Note:** We assume you already know what a markdown engine is and how it is applied to a website. {: .note} ---- ## On this post {: .no_toc} - TOC {:toc} ---- ## Our Markdown Guide Last week a lot of [people were happy][news] for our [Handbook] being open source, as we explained in details on the post "[Our Handbook is open source: here's why][handbook-post]". Every GitLab Team member does touch our website, starting on his or her first weeks, as part of the onboarding tasks. Doesn't matter if he or she is an advanced programmer or never have seen an HTML code before, collaborating is the key for making sure we are all on the same side. And we love it! One of our Handbook pages is a full [Markdown Guide][guide] for the markup that we use in our website, generated by [Middleman]. It brings a lot of details on how to use Kramdown for writing content. Every markdown page of this website, which is an [open source project][www-GitLab-com] available for peeking and contributing, can use any of the rules explained there. This April we changed the markdown engine from RDiscount to Kramdown, and not everybody in our Team knew the new "magical" stuff we could use from this change. That's why we decided that writing a guide would be useful for those already used to markdown, and helpful for those completely new to it. ## Why Kramdown Perhaps your first question will be something like "okay, why is Kramdown so special?". My first experience with markdown was when I first used a [Static Site Generator][SSGs], Jekyll. Coming from previous experiences in web development on PHP and HTML, the first thing I wanted to do to a markdown post was adding a class to a particular heading. When I googled for that, I was pretty disappointed because apparently we aren't supposed to apply classes inline into markdown files. So, I had to experiment a lot until I got the desired result: add some color to my heading. After trying a lot of new tweaks, and digging through the web for answers that insisted on not coming, I finally found out that with Kramdown, yes, I could do a lot of things. And finally I could apply some inline classes through my posts and have my blue headings when I wanted them blue. But at that time, I hadn't noticed that we could do some really great magic with it, and that's what I'm sharing with you in this post. ## The magic We could say that the Kramdown magic concentrates to the following syntax: `{: something}`. This little devil is the basis of a lot of awesome resources. Let's go over a few of them now, but you'll find a lot more in our [Markdown Guide][guide]. ## Classes, IDs and Attributes {::options parse_block_html="true" /} Let's start with something classic, as the ability of [applying CSS classes, custom IDs, and custom attributes][classes] to the elements. ### Applying classes If you think of any CSS class, what comes into your mind first? I suppose it's something like: ```css .blue { color: blue; } ``` Okay, we have a `.blue` class. Let's say once in a while we want a blue paragraph or a blue heading. Just do: ```md This is a paragraph that for some reason we want blue. {: .blue} ``` And of course, the output will be:
Hello World