Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do <style> tags work in Markdown?

Tags:

I'm writing a Github README.md file, and i have diferent tables. The contents are different, so table width is different too.

I want, at least the first column to be of fixed width, so i tried adding this before all the tables in the Markdown file:

<style>td:nth-child(odd){width:200px}</style> 

Surprisingly that is working in my editor preview, but when committed to github, the text appears with the style tags stripped, and no style is applied.

My questions is if it's possible on github, and id it is, how do i do it.

like image 494
gcq Avatar asked Dec 15 '13 19:12

gcq


People also ask

How do I add tags in markdown?

Add tags to your markdown files You add tags by defining them in the frontmatter of your Markdown file. The frontmatter is the area at the top surrounded by dashes that includes post data like the title and date.

Does markdown support inline CSS?

Markdown does have support for inline HTML, therefore you can add your own formatting inline using CSS or other HTML attributes, however this moves away from the quick markdown flavor.

Can you use CSS on GitHub markdown?

Unfortunately you cannot use CSS in GitHub markdown as it is a part of the sanitization process. 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.

Can we add style in body tag?

The <style> element must be included inside the <head> of the document. In general, it is better to put your styles in external stylesheets and apply them using <link> elements.


1 Answers

Just tested it myself.

<style> #foo {color: red} </style>  <p id="foo">foo</p>  <p style="color: blue">bar</p> 

The above rendered to:

#foo {color: red} <p>foo</p>  <p>bar</p> 

GitHub strips style tags and attributes preventing you from changing the style on their pages. This is probably for security reasons. If you could inject css into GitHub pages, you could easily launch a phishing attack.

like image 51
Peter Lundgren Avatar answered Oct 10 '22 11:10

Peter Lundgren