<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jonathan Alles</title>
    <description>The latest articles on DEV Community by Jonathan Alles (@jonathanalles).</description>
    <link>https://dev.to/jonathanalles</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3737645%2F04344407-1811-4515-a256-b054eb83a8fd.jpeg</url>
      <title>DEV Community: Jonathan Alles</title>
      <link>https://dev.to/jonathanalles</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jonathanalles"/>
    <language>en</language>
    <item>
      <title>Professional Streamlit Styling with CSS and st_yled</title>
      <dc:creator>Jonathan Alles</dc:creator>
      <pubDate>Wed, 28 Jan 2026 13:48:40 +0000</pubDate>
      <link>https://dev.to/jonathanalles/professional-streamlit-styling-with-css-and-styled-45o6</link>
      <guid>https://dev.to/jonathanalles/professional-streamlit-styling-with-css-and-styled-45o6</guid>
      <description>&lt;p&gt;Streamlit is an effective tool for building data apps, dashboards, and prototypes in Python. While basic theme properties like primary colors and fonts can be set, customizing specific components often requires additional techniques.&lt;/p&gt;

&lt;p&gt;This post covers two approaches for styling Streamlit apps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Targeting components with CSS using the &lt;code&gt;key&lt;/code&gt; attribute&lt;/li&gt;
&lt;li&gt;A Python-centric alternative using the &lt;code&gt;st_yled&lt;/code&gt; package&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Styling with CSS and Component Keys
&lt;/h2&gt;

&lt;p&gt;For components that accept a &lt;code&gt;key&lt;/code&gt; attribute, Streamlit assigns a corresponding CSS class (&lt;code&gt;.st-key-&amp;lt;your-key&amp;gt;&lt;/code&gt;). This can be used to apply custom CSS to individual elements.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6j44wpviq2x3kd2e4z9g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6j44wpviq2x3kd2e4z9g.png" alt="A styled Streamlit container" width="475" height="186"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 1: Container with Background and Padding
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;st.html("""
    &amp;lt;style&amp;gt;
    .st-key-my-container {
        background-color: #F6F6F6;
        padding: 16px;
    }
    &amp;lt;/style&amp;gt;
""")

with st.container(key="my-container"):
    st.write("This container has a custom background and border.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case the CSS class &lt;code&gt;.st-key-my-container&lt;/code&gt; is automatically generated by Streamlit based on the component &lt;code&gt;key&lt;/code&gt;. The container’s background and padding are adjusted via CSS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvqzv9q5c8q53ryq0bx44.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvqzv9q5c8q53ryq0bx44.png" alt="A styled Streamlit button" width="252" height="147"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 2: Button with a Custom Border
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;st.html("""
    &amp;lt;style&amp;gt;
    .st-key-my-button button {
        border: 3px solid #000000;
    }
    &amp;lt;/style&amp;gt;
""")

st.button("Click Me", key="my-button", type="primary")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This snippet inserts a &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; block that targets &lt;code&gt;.st-key-my-button button&lt;/code&gt;, allowing customization of the button’s border. The downside is evident: Each component requires different elements to be targeted with the right CSS selectors.&lt;/p&gt;

&lt;p&gt;These techniques make it possible to customize the appearance of specific components without modifying global theme settings.&lt;/p&gt;




&lt;h2&gt;
  
  
  Using the &lt;code&gt;st_yled&lt;/code&gt; Package
&lt;/h2&gt;

&lt;p&gt;An alternative approach is to use the &lt;a href="https://st-styled.evo-byte.com/" rel="noopener noreferrer"&gt;&lt;code&gt;st_yled&lt;/code&gt;package&lt;/a&gt;, which allows style properties to be specified directly as arguments in Python.&lt;/p&gt;

&lt;p&gt;The st_yled philosophy is simple:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Write styles in Python right next to your components, no CSS&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;The approach is to &lt;code&gt;import st_yled&lt;/code&gt;, call &lt;code&gt;.init()&lt;/code&gt; once, then use prefixed components to apply style properties, whenever necessary — while using standard Streamlit components and functions.&lt;/p&gt;

&lt;p&gt;Instead of styling via CSS, you just pass style properties as arguments to components prefixed with &lt;code&gt;sty.&lt;/code&gt; or &lt;code&gt;st_yled.&lt;/code&gt; .&lt;/p&gt;




&lt;h3&gt;
  
  
  Example 1: Container with Style Properties
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import st_yled as sty

sty.init()

with sty.container(width='content', padding=16, background_color='#F6F6F6'):
    st.write("Hello from Container!")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, style properties such as &lt;code&gt;background_color&lt;/code&gt;and &lt;code&gt;padding&lt;/code&gt;are passed directly to the container component in Python, without requiring explicit CSS.&lt;/p&gt;




&lt;h3&gt;
  
  
  Example 2: Button with Custom Styling
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sty.button(
    "Click Me",
    type="primary",
    border_color='#000000',
    border_style='solid',
    border_width=3
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example shows how a button can be styled with border properties through the &lt;code&gt;st_yled&lt;/code&gt;API. The results are identical to the custom CSS styling in the examples above.&lt;/p&gt;




&lt;h2&gt;
  
  
  Trying new Styles Using st_yled Studio
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://styled-studio.streamlit.app/" rel="noopener noreferrer"&gt;st_yled Studio&lt;/a&gt; is a companion web application built in Streamlit that allows users to interactively explore possible style customizations for common components.&lt;/p&gt;

&lt;p&gt;Users can select a component, adjust style parameters, and then export either:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python code to insert into your Streamlit app&lt;/li&gt;
&lt;li&gt;A CSS file to consistently apply styling to all components (this file is automatically loaded by st_yled)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This tool can aid in developing consistent visual designs, branding or testing styles before integrating them into code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frr7rysl29q5uucjalhlo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frr7rysl29q5uucjalhlo.png" alt="st_yled Studio Elements Page" width="800" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Post you ideas for new styling options and components below!&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;st-styled Python Package on &lt;a href="https://pypi.org/project/st-styled/" rel="noopener noreferrer"&gt;PyPI&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;st_yled &lt;a href="https://st-styled.evo-byte.com/" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://styled-studio.streamlit.app" rel="noopener noreferrer"&gt;st_yled Studio App&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;st_yled on &lt;a href="https://github.com/EvobyteDigitalBiology/st-styled" rel="noopener noreferrer"&gt;Github&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>python</category>
      <category>datascience</category>
    </item>
  </channel>
</rss>
