Import the github-markdown.css file and add a markdown-body class to the container of your rendered Markdown and set a width for it. GitHub uses 980px width and 45px padding, and 15px padding for mobile.
(As BLUEFROG says, this is not a generic stylesheet. It assumes that everything is nested in some HTML container with the class markdown-body, i.e. <div class="markdown-body">)
@BLUEFROG I actually looked at this exact style sheet a while back. I think it makes more sense to remove the full .markdown-body instead of just .markdown- for almost all of the selectors..
Every selector in the stylesheet targets children of some HTML element with the class markdown-body, like I said earlier. That’s what “the prefix” means, it is a class selector.
(If that doesn’t make any sense to you, I suggest you spend 15 minutes reading about the basics of HTML.)
Also, @chrillek wrote a great beginner’s guide to CSS here:
It’s not about a “prefix”. It is about a selector that does not make sense unless you stuff your whole markdown in an element with class markdown-body. Which hardly anyone does, except perhaps the GitHub infrastructure.
Then there are other reasons why you (or anyone) should use this kind of CSS in 2025:
font-size: 16px (or 11px for kbd): That has not made sense for a long, long time. First, a px is not a fixed unit but depends on device resolution and retina mode. Second, users have an interest and a right to set their preferred font size in their browser. If I am myopic and decide to have 24px as my default font size, who is the CSS creator to tell me that I have to buy new glasses just to be able to read their 16px stuff?
.markdown-body h1:hover .anchor .octicon-link:before, Well, where do you see the class .oction-link? What sense does a :hover selector make if one doesn’t check if the current device even supports hovering?
.markdown-body figure { display: block;} Apart from the useless class selector, what is the default display value of figure? Right, it is a block element
Then there are box-sizing: content-box settings strewn about instead of setting it once and for all for *.
Just some things that sprung into my face.
This thing is 7 years old, and it shows (but I don’t think that it was particularly well-written even at that time). Instead of blindly jumping onto an unknown CSS bandwagon just because it says “GitHub”, it makes a lot more sense to craft the CSS one wants and needs. What DT generates from MD, is a lot simpler than GitHub caters for.
Are there open source CSS examples that you recommend that would be useful to look at to understand what good should look like and how to replicate one for my specific use cases?
Check the post I linked. Chrillek even put all of it on Github so it’s easy to download as a complete package. Including a basic style sheet with extensive comments.