# Adding a streamlit component into a markdown block

**URL:** <https://discuss.streamlit.io/t/adding-a-streamlit-component-into-a-markdown-block/85839>\
**Category:** Random\
**Tags:** css, html, discussion\
**Created:** [November 17, 2024, 5:54pm UTC](https://discuss.streamlit.io/t/adding-a-streamlit-component-into-a-markdown-block/85839 "2024-11-17T17:54:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anish5](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/anish5/32/48378_2.png) [@Anish5](https://discuss.streamlit.io/u/Anish5)\
**Post date:** [November 17, 2024, 5:54pm UTC](https://discuss.streamlit.io/t/adding-a-streamlit-component-into-a-markdown-block/85839/1 "2024-11-17T17:54:04Z")

</div>

I have a custom markdown block that shows some information like user profile

```auto
import streamlit as st

# Define CSS style
st.markdown("""
    <style>
    .profile-section {
        background-color: #f9f9f9;
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        padding: 20px;
        font-family: Arial, sans-serif;
        width: 100%;
        max-width: 400px;
    }
    .profile-section h2 {
        font-size: 18px;
        color: #333333;
        margin-top: 0;
    }
    .profile-section .profile-item {
        margin-bottom: 15px;
        font-size: 16px;
        color: #555555;
    }
    .profile-section .profile-item label {
        font-weight: bold;
        color: #888888;
    }
    .profile-section .profile-item a {
        color: #ff6f61;
        text-decoration: none;
    }
    .profile-section .profile-item a:hover {
        text-decoration: underline;
    }
    </style>
    """, unsafe_allow_html=True)

# Display profile information using HTML
st.markdown("""
<div class="profile-section">
    <h2>Personal Information</h2>
    <div class="profile-item">
        <label>Facebook:</label> <a href="https://facebook.com" target="_blank">View</a>
    </div>
    <div class="profile-item">
        <label>Mobile phone:</label> +1-541-754-3010
    </div>
    <div class="profile-item">
        <label>Tax residence:</label> United States
    </div>
    <div class="profile-item">
        <label>Series and number of passport:</label> CO3005978
    </div>
</div>
""", unsafe_allow_html=True)

```

Is there a way to add a streamlit component like st.metric into the block?

This is followup question from a previous post. POsting as new topic as previous topic was closed.

> [@Creating a section for user profile](https://discuss.streamlit.io/t/creating-a-section-for-user-profile/85667/2):
>
> Yes, you can create a visually appealing user profile section in Streamlit by using st.markdown with custom HTML and CSS styling to achieve a similar look to the example you shared. import streamlit as st # Define CSS style st.markdown(""" \<style\> .profile-section { background-color: #f9f9f9; border: 1px solid #e0e0e0; border-radius: 8px; padding: 20px; font-family: Arial, sans-serif; width: 100%; max-width: 400px; } .prof…

---

<div class="post-metadata">

**Author:** ![Anish5](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/anish5/32/48378_2.png) [@Anish5](https://discuss.streamlit.io/u/Anish5)\
**Post date:** [November 17, 2024, 5:54pm UTC](https://discuss.streamlit.io/t/adding-a-streamlit-component-into-a-markdown-block/85839/2 "2024-11-17T17:54:23Z")

</div>

@Encrypt

Thanks for your previous response. This is a followup question since the topic was closed.

---

<div class="post-metadata">

**Author:** ![mathcatsand](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/mathcatsand/32/48006_2.png) [@mathcatsand](https://discuss.streamlit.io/u/mathcatsand)\
**Post date:** [November 18, 2024, 1:18am UTC](https://discuss.streamlit.io/t/adding-a-streamlit-component-into-a-markdown-block/85839/3 "2024-11-18T01:18:24Z")

</div>

The short answer is no, you can’t insert a Streamlit component into Markdown. You can custom script out HTML to and behave how you want, even copying from the HTML that `st.metric` generates, but the Streamlit commands are modular: the `st.markdown` command creates a distinct element from the `st.metric` command. Only layouts can contain other Streamlit elements.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [November 20, 2024, 1:18am UTC](https://discuss.streamlit.io/t/adding-a-streamlit-component-into-a-markdown-block/85839/4 "2024-11-20T01:18:36Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
