Creating a section for user profile

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;
    }
    .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)

You can also use string templating to populate the fields with dynamic data.

1 Like