Streamlit Markdown An Ultimate Guide

Streamlit Markdown – An Ultimate Guide

Streamlit Markdown is an essential tool for creating interactive web applications. It is a simple yet powerful markup language that allows users to format text, insert images, and add links. Unlike other Markdown tools, Streamlit Markdown has the added advantage of being able to render arbitrary HTML, allowing for customization and flexibility. This makes it a valuable tool for developers looking to create rich content within their Streamlit app.

Getting Started with Streamlit Markdown

Streamlit Markdown is a powerful tool that allows you to easily insert rich content into your Streamlit application. With Streamlit Markdown, you can format your text, add images, and even create tables.


To install Streamlit Markdown, you first need to install Streamlit. You can install both Streamlit and Streamlit Markdown using pip. Simply open your terminal and type:

pip install streamlit streamlit-markdown

Basic Syntax

The syntax for Streamlit Markdown is based on the common Markdown syntax, which is an easy-to-use markup language that allows you to format text without using HTML tags. Below are some of the basic syntax:

  • Headers: You can use # to create headers. The number of # corresponds to the level of the header, e.g. # for H1, ## for H2, and so on.
  • Bold and Italic: To make text bold, enclose it in ** or __. To make text italic, enclose it in * or _.
  • Lists: To create an ordered list, use numbers followed by a period. To create an unordered list, use a dash or an asterisk.
  • Links: To create a link, put the text you want to display in square brackets and the URL in parentheses, e.g. [Google](

Using Markdown Files

Streamlit Markdown also allows you to use Markdown files in your application. This is especially useful if you have a large amount of text or if you want to reuse text across multiple pages. Below are some of the benefits, tips, and best practices:

  • Benefits: Using Markdown files allows you to separate your text from your code, making it easier to maintain and update. It also allows for better collaboration, as multiple people can work on the text without affecting the code.
  • Tips: When using Markdown files, make sure to organize your text into sections, use headers to provide structure, and use links to reference other pages or websites.
  • Best practices: When creating your Markdown files, make sure to name them appropriately and store them in a separate folder. You can then use the Streamlit Markdown component to display the contents of the file in your application.

Advanced Streamlit Markdown Techniques

Conditionally Displaying Long Content

One of the advanced Streamlit Markdown techniques is displaying long content only when certain conditions are met. This can be achieved by using a combination of st.checkbox and

elements in Markdown. For example, you can use st.checkbox to create a checkbox input and wrap the long content inside a

element. This will allow you to display the long content only when the checkbox is selected by the user.



Another technique to improve readability is by using the


This element can be used in Streamlit Markdown to reduce font size and make the content more compact. However, it’s important to use this element sparingly and only on non-critical text or captions.

Visual Separation with st.markdown(“—“)

The st.markdown(“—“) function is a very useful tool for correctly separating content in your application. This function creates a horizontal rule that visually separates content and helps users better navigate through your application. You can use this function in combination with headings and paragraphs to create a clear and organized layout.

Emoji Usage

Using emojis in your Markdown content can add a fun and engaging element to your application. However, it’s important to be mindful of how it affects the performance of your application. Using too many emojis can slow down your application, so it’s best to use them sparingly. Additionally, you can stylize emojis using CSS to fit with the overall design of your application.

Combining f-strings with Markdown

f-strings can be used in combination with Streamlit Markdown for more efficient and convenient string formatting. This allows you to dynamically insert values into your Markdown content, making it easier to create dynamic and interactive applications. For example, you can use f-strings to insert values from user inputs into your Markdown content.

Examples and Inspirations

Streamlit Markdown offers a flexible way of inserting rich content into your application. Below are some examples and inspirations to help you understand how to use Streamlit Markdown to improve your Streamlit dashboards:

1. Customize the Look and Feel of Your App

With Streamlit Markdown, you can customize the look and feel of your app by adding text styles, colors, and images. For example, you can add headings, bold or italic text, and even tables to your app to make it more engaging and easier to read.

Here’s an example of a Streamlit Markdown snippet that illustrates how to create a table:

st.markdown(‘First Header | Second Header\n————– | ————–\nContent from cell 1 | Content from cell 2\nContent in the first column | Content in the second column’)

2. Add Emojis for Visual Appeal

Emojis can add a touch of humor and personality to your Streamlit app. With Streamlit Markdown, you can easily add emojis to your text by using Unicode characters.

Here’s an example of a Streamlit Markdown snippet that shows how to add an emoji:

st.markdown(‘📘 Here is my emoji!’)

3. Use Math Symbols to Enhance Technical Content

If your Streamlit app deals with technical content, Streamlit Markdown can be beneficial in displaying mathematical equations and symbols. Use LaTeX syntax to display math symbols and equations.

Here’s an example of a Streamlit Markdown snippet that illustrates how to use LaTeX to display a math symbol:

st.markdown(‘$\sqrt{x^2+y^2}=1$ is a Pythagorean identity.’)

With Streamlit Markdown, the possibilities of enhancing the appeal of your Streamlit application are endless. The examples above are only scratching the surface of what Streamlit Markdown can do, and we encourage you to experiment and explore its full potential.

Alternatives to Streamlit Markdown: Similar Packages

While Streamlit Markdown is a powerful tool for incorporating rich content into Streamlit applications, there are also several alternatives and competitor packages that can be used for writing Markdown in Streamlit applications. Here are some of the most popular options:

Package Pros Cons
Dash Highly customizable, offers more advanced graphing options Steep learning curve, less straightforward than Streamlit
Jupyter Widely used, easy to share and collaborate on notebooks Not specifically designed for building Streamlit applications
Flask Flexible, allows for more complex web applications Requires more coding than Streamlit Markdown
Shiny Highly customizable, easy to integrate with R code Less user friendly than Streamlit, limited documentation
Bokeh Advanced data visualization capabilities Requires knowledge of Python or JavaScript, limited documentation

Ultimately, the choice of which package to use for writing Markdown in Streamlit applications will depend on the specific needs and preferences of the user. Streamlit Markdown remains a powerful and user-friendly option for most use cases, but it is important to be aware of other options as well.

Frequently Asked Questions

What is Streamlit Markdown?

Streamlit Markdown is a tool within a Streamlit application that allows users to insert rich content by using HTML formatting. In Streamlit, st.markdown function is used to display strings formatted in Markdown. This function allows users to create colored text, create Pythagorean identities, format text in bold, italicized or underlined styles, and add links and images to the text.

How does Streamlit Markdown compare to other tools?

Streamlit Markdown is a unique tool as it is the only feature in Streamlit that allows for custom HTML formatting. Alternatives to Streamlit, such as Dash, Jupyter, Flask, Shiny, and Bokeh, offer similar features but may not have the same flexibility as Streamlit Markdown.

What are the benefits of using Streamlit Markdown?

Using Streamlit Markdown can significantly improve the look and feel of your Streamlit dashboards. You can add rich and interactive content that engages your users and makes your dashboard more readable. Additionally, using Streamlit Markdown can help increase the discoverability and visibility of your website by making it more SEO-friendly.

How can Streamlit Markdown be used to improve Streamlit dashboards?

Streamlit Markdown can be used to display important information, create visual interest, format text, and enhance user experience by adding interactive content such as links, images, and Pythagorean identities. By using Streamlit Markdown, users can make their Streamlit dashboards more engaging and user-friendly.


Streamlit Markdown is an essential tool for developers who want to add rich content to their Streamlit applications. Using st.markdown, developers can add colored text, create tables, and incorporate mathematical formulas in their applications with ease. Streamlit’s quick and easy development flow allows for seamless integration between source code and the application, making it an ideal tool for data scientists and developers alike.

By using Streamlit Markdown, developers can create powerful and interactive dashboards that are engaging and informative for users. The simplicity of the Streamlit framework, combined with the flexibility of Markdown, allows for the creation of custom applications that can be tailored to specific user needs. With its growing popularity, Streamlit continues to be a go-to choice for developers looking for a streamlined and efficient way to build data science applications.


Streamlit Official Documentation

Streamlit Discussion Forum

Streamlit Github Issues

Markdown on Wikipedia

Being a web developer, writer, and blogger for five years, Jade has a keen interest in writing about programming, coding, and web development.
Posts created 491

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top