# How do i align st.title?

**URL:** <https://discuss.streamlit.io/t/how-do-i-align-st-title/1668>\
**Category:** Using Streamlit\
**Tags:** css\
**Created:** [January 19, 2020, 8:46pm UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668 "2020-01-19T20:46:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![qxlsz](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/qxlsz/32/565_2.png) [@qxlsz](https://discuss.streamlit.io/u/qxlsz)\
**Post date:** [January 19, 2020, 8:46pm UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/1 "2020-01-19T20:46:28Z")

</div>

how do i align st.title ?

---

<div class="post-metadata">

**Author:** ![Marc](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/marc/32/602_2.png) [@Marc](https://discuss.streamlit.io/u/Marc)\
**Post date:** [January 20, 2020, 4:27am UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/2 "2020-01-20T04:27:44Z")

</div>

Hi @qxlsz.

I would like to help. But I need more info to be able to help.

Please be a bit more specific. What do you mean by align? Horizonally, vertically or…

The best approach is to provide a small code example and a screenshot that shows how it looks and indicates how it should look.

Thanks.

---

<div class="post-metadata">

**Author:** ![qxlsz](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/qxlsz/32/565_2.png) [@qxlsz](https://discuss.streamlit.io/u/qxlsz)\
**Post date:** [January 20, 2020, 7:44pm UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/3 "2020-01-20T19:44:09Z")

</div>

> [@Marc](#):
>
> all code example and a screenshot that shows how it looks

I would like to get align center  
i currently have  
`st.title("Some title")`  
but the title doesnt show in the center

---

<div class="post-metadata">

**Author:** ![nthmost](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/nthmost/32/484_2.png) [@nthmost](https://discuss.streamlit.io/u/nthmost)\
**Post date:** [January 22, 2020, 8:43pm UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/4 "2020-01-22T20:43:19Z")

</div>

Hi @qxlsz,

Currently it’s not possible to set title and header alignment. Our layout is done in Markdown which doesn’t contain a native notion of text alignment (it’s all left-justified by default).

Additionally I don’t think it will work to [use HTML to force the alignment](https://stackoverflow.com/questions/53419155/how-to-center-text-with-markdown), since the style will get overridden by Streamlit’s CSS. (I am not great at CSS, though; maybe it’s possible with some HTML/CSS wizardry?)

If this is an important feature for you, I recommend [opening a Feature Request](https://github.com/streamlit/streamlit/issues/new?assignees=&labels=enhancement&template=feature_request.md&title=) in our github issues.

---

<div class="post-metadata">

**Author:** ![andfanilo](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/andfanilo/32/1040_2.png) [@andfanilo](https://discuss.streamlit.io/u/andfanilo)\
**Post date:** [January 23, 2020, 8:19am UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/5 "2020-01-23T08:19:27Z")

</div>

Hello @qxlsz,

Actuallly, as hinted by @nthmost, you CAN align HTML through Markdown :

```auto
import streamlit as st
st.markdown("<h1 style='text-align: center; color: red;'>Some title</h1>", unsafe_allow_html=True)

```

…but `unsafe_allow_html` is probably going to be deprecated soon, so we can’t count on this.

I tried adding a CSS file in the `static` folder where Streamlit is installed but no luck 😅 (EDIT : [but it can work if done correctly !](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/5))

There’s a feature in RISE that allows to [inject custom CSS classes over RISE CSS](https://rise.readthedocs.io/en/maint-5.6/customize.html#adding-custom-css) but they allow display of HTML so that makes it easier. I would be interested in custom CSS but maybe it would be too cumbersome to add a list of editable CSS classes as arg of each Streamlit Python method and pointing them to our external CSS file ?

So if you really want to edit CSS, for now the way to go would be to edit the SCSS in Streamlit source code and rebuild the frontend part.

EDIT : well actually [someone did load it’s custom CSS and it’s easy](https://discuss.streamlit.io/t/are-you-using-html-in-markdown-tell-us-why/96/24). You can follow the discussion to see how it goes .

---

<div class="post-metadata">

**Author:** ![nthmost](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/nthmost/32/484_2.png) [@nthmost](https://discuss.streamlit.io/u/nthmost)\
**Post date:** [January 23, 2020, 6:21pm UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/6 "2020-01-23T18:21:35Z")

</div>

Ah hah! Thanks @andfanilo, I was trying to do it with _span_ tags (which didn’t work!) and didn’t think about simply stuffing the **h1** ’s style keyword. Thanks!

---

<div class="post-metadata">

**Author:** ![woden](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/woden/32/10134_2.png) [@woden](https://discuss.streamlit.io/u/woden)\
**Post date:** [September 3, 2021, 2:59am UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/7 "2021-09-03T02:59:30Z")

</div>

If you inspect the element, there’s the default setting that the h1 tag would have an id the same as your text. It’s possible to customize the alignment for different h1. For example:

`st.title("The title")`

The id would be “the-title”. Therefore, you can tweak the position with markdown and CSS

```auto
title_alignment=
"""
<style>
#the-title {
  text-align: center
}
</style>
"""
st.markdown(title_alignment, unsafe_allow_html=True)

```

---

<div class="post-metadata">

**Author:** ![Charly\_Wargnier](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/charly_wargnier/32/1504_2.png) [@Charly\_Wargnier](https://discuss.streamlit.io/u/Charly_Wargnier)\
**Post date:** [September 3, 2021, 9:09am UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/8 "2021-09-03T09:09:22Z")

</div>

Hi @woden,

Please would you mind clarying the issue you may be facing here?

Thanks  
Charly

---

<div class="post-metadata">

**Author:** ![woden](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/woden/32/10134_2.png) [@woden](https://discuss.streamlit.io/u/woden)\
**Post date:** [September 3, 2021, 4:03pm UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/9 "2021-09-03T16:03:10Z")

</div>

Hi @Charly_Wargnier,  
Actually, I had another post regarding the `plotly_chart` alignments with HTML components. The issue I am facing is that the HTML code would be cut or under the plotly chart.

Having a look at the element, the chart is the `svg` type, which is hard to align with HTML code. Using the `streamlit.title`, the `h1` tag is wrapped by the `markdown` class, which perfectly solves my issue.

However, the issue of alignment with HTML code and charts could be challenging for me.

Regards,

---

<div class="post-metadata">

**Author:** ![Charly\_Wargnier](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/charly_wargnier/32/1504_2.png) [@Charly\_Wargnier](https://discuss.streamlit.io/u/Charly_Wargnier)\
**Post date:** [September 6, 2021, 8:17am UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/10 "2021-09-06T08:17:36Z")

</div>

Thanks @woden

For clarity’s sake, I’d suggest sending us the following:

- The app + its code
- A quick mock-up of how you would like things to be like

With these to hand, we should be able to help you get what you’d want 🙂

Best  
Charly

---

<div class="post-metadata">

**Author:** ![woden](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/woden/32/10134_2.png) [@woden](https://discuss.streamlit.io/u/woden)\
**Post date:** [September 10, 2021, 6:29am UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/11 "2021-09-10T06:29:32Z")

</div>

Hi @Charly_Wargnier  
I’ve made a demo of what it looks like to use component.html with customized style above the plotly chart.  
[https://share.streamlit.io/wodenwang820118/streamlit\_bug/main/app.py](https://share.streamlit.io/wodenwang820118/streamlit_bug/main/app.py)

The code is [here](https://github.com/WodenWang820118/streamlit_bug), in Github.

Please advise if I could do it better.

Sincerely,

---

<div class="post-metadata">

**Author:** ![Charly\_Wargnier](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/charly_wargnier/32/1504_2.png) [@Charly\_Wargnier](https://discuss.streamlit.io/u/Charly_Wargnier)\
**Post date:** [September 10, 2021, 7:50am UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/12 "2021-09-10T07:50:01Z")

</div>

Thanks @woden

I believe you could add empty blocks via e.g. `st.text("")` in order to move the chart down and display your text.

 ![image](https://global.discourse-cdn.com/streamlit/original/2X/d/d6666d37acd620d414cfa1fc7af7f30c89729f33.png)

Let me know if that would work?

Best,  
Charly

---

<div class="post-metadata">

**Author:** ![woden](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/woden/32/10134_2.png) [@woden](https://discuss.streamlit.io/u/woden)\
**Post date:** [September 10, 2021, 9:39am UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/13 "2021-09-10T09:39:54Z")

</div>

Hi @Charly_Wargnier  
Yes, it would work, but it’s a little bit hacky since the style could change every time. And the alignment problem happens with the HTML component, not the `st.title`, which works perfectly.

Sincerely,

---

<div class="post-metadata">

**Author:** ![Martin\_Thabang](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/martin_thabang/32/12027_2.png) [@Martin\_Thabang](https://discuss.streamlit.io/u/Martin_Thabang)\
**Post date:** [December 1, 2021, 6:28pm UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/14 "2021-12-01T18:28:11Z")

</div>

I’m sure by now someone, somewhere has already used CSS to get this, but some people are not very familiar with that, so this is the trick I’ve got.

colT1,colT2 = st.columns([1,8])  
with colT2:  
st.title(“Major Consumer Bundle Analysis”)

You can just keep playing with the ratio, or just the 8 to get the right center. It won’t be perfect but its consistent and it is pretty easy. Plus it works with more than just the st.title

Thanks

---

<div class="post-metadata">

**Author:** ![samarth\_singh](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/samarth_singh/32/29783_2.png) [@samarth\_singh](https://discuss.streamlit.io/u/samarth_singh)\
**Post date:** [July 26, 2023, 7:11am UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/15 "2023-07-26T07:11:18Z")

</div>

to align any text you can add \t  
to get into the next line use \n  
It worked for me.

---

<div class="post-metadata">

**Author:** ![DNYANESHWARI\_KADAM](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/dnyaneshwari_kadam/32/33693_2.png) [@DNYANESHWARI\_KADAM](https://discuss.streamlit.io/u/DNYANESHWARI_KADAM)\
**Post date:** [October 26, 2023, 9:48am UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/16 "2023-10-26T09:48:20Z")

</div>

Thx @andfanilo, this helped me a lot in my project. 😀😀

---

<div class="post-metadata">

**Author:** ![Giselle](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/giselle/32/27847_2.png) [@Giselle](https://discuss.streamlit.io/u/Giselle)\
**Post date:** [June 24, 2024, 12:18am UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/17 "2024-06-24T00:18:11Z")

</div>

I made a little (40 line) demo for anyone trying to align their `st.title` with CSS

> **[PyCafe - Streamlit - Stacked Bar Chart Visualization with Streamlit and Plotly](https://py.cafe/giselle.pomodor/streamlit-center-title-with-css)**
>
> PyCafe: get your daily fix of Python!

 ![image](https://global.discourse-cdn.com/streamlit/original/3X/4/7/47c7c6b241511cf110658899e54583143c8fda4a.png)

---

<div class="post-metadata">

**Author:** ![eduardob](https://avatars.discourse-cdn.com/v4/letter/e/b3f665/32.png) [@eduardob](https://discuss.streamlit.io/u/eduardob)\
**Post date:** [October 23, 2024, 11:08pm UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/18 "2024-10-23T23:08:19Z")

</div>

I was trying to do this and found two methods: `st.columns`, and `CSS`. ([here’s the complete code](https://streamlit-generator.ploomberapp.io/editor/bf2f5fab)).

# Approach 1: using `st.columns`

 ![image](https://global.discourse-cdn.com/streamlit/original/3X/6/c/6cbc4c1e6f7c9a0162a58e654f980790f82b69cc.png)

- Pros: simple, an easy to use
- Cons: doesn’t perfectly align elements: it just places them in the center but they remain aligned to the left)

```python
import streamlit as st

# create 3 columns
col1, col2, col3 = st.columns([1, 1, 1])

# place our elements in the second column
with col2:
    st.title('This is some title')
    st.image("http://placekitten.com/200/200")
    st.button("Click me")

```

# Approach 2: inline CSS

 ![image](https://global.discourse-cdn.com/streamlit/original/3X/b/6/b602f971a5783ee017221a7e3573520d7495abb8.png)

- Pros: centers correctly
- Cons:
  1. Can only use it to align HTML elements. i.e. you cannot use it to align `st.button` or any other control
  2. Needs custom CSS for different elements

```python
import streamlit as st
style_heading = 'text-align: center'
style_image = 'display: block; margin-left: auto; margin-right: auto;' 

st.markdown(f"<h1 style='{style_heading}'>This is another title</h1>", unsafe_allow_html=True)
st.markdown(f"<img src='http://placekitten.com/200/200' style='{style_image}'/>", unsafe_allow_html=True)

# cannot align this!
st.button("Click this")

```

---

<div class="post-metadata">

**Author:** ![pgarrett-scripps](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@pgarrett-scripps](https://discuss.streamlit.io/u/pgarrett-scripps)\
**Post date:** [March 1, 2025, 12:35am UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/19 "2025-03-01T00:35:39Z")

</div>

Why is there still no support for centering a component??? This seems like a super basic feature than should have been in since the beginning… I’ve wasted so much time trying to center a stupid table. Please add this natively into Streamlit.

---

<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:** [March 3, 2025, 7:26am UTC](https://discuss.streamlit.io/t/how-do-i-align-st-title/1668/20 "2025-03-03T07:26:56Z")

</div>

Advanced theming and layout are currently under development with new features in this area expected both this and next quarter. [https://roadmap.streamlit.app/](https://roadmap.streamlit.app/)
