Wrap text columns in dataframe/data editor

While I have width option for text columns, does it have capability to wrap text such that users can see full text in the same width?


Hi @Himanshu_Gupta

The width parameter for st.column_config.TextColumn accepts ”small”, ”medium” and ”large” as argument values. (See the Docs page for more details st.column_config.TextColumn - Streamlit Docs)

As for text wrapping in columns, can you see this relevant forum post for more details:

Hope this helps!

1 Like

width parameter changes the width and doesn’t wrap the text in a readable format.
this post is suggesting to use st.table, which doesn’t have column config.
I have multiple columns, one is long text and other is a score, where i use ProgressColumn, renaming, tooltip, etc

Is there a better way to do this using st.dataframe and column_config instead. Like using some python wrap function on text columns before passing to streamlit st.dataframe?

         'query_summary':st.column_config.TextColumn("Summary", width="medium", help="Natural Language Question relevant to entered question"),
         'sim_score':st.column_config.ProgressColumn("Score", width=90, format="%.2f%%",min_value=0,max_value=100, help="Similarity score"),
1 Like

I’d also like to be able to wrap text using st.dataframe :smiley:
Did anyone find a way to do this?


I’d also like to be able to wrap text in column names.

1 Like

Hi, I created a method to fix this issue as I was facing wrap text issue in streamlit for pie charts and sunburst charts where the text was so small due to the length that it was unreadable. This method gives the result same as textwrap.text which doesn’t works in streamlit

def wrap_text(sentences, width):
This function takes a list of sentences and a width and returns a list of lists,
where each inner list contains the wrapped lines for the corresponding sentence.

sentences: A list of strings, where each string is a sentence.
width: An integer representing the maximum character width per line.

A list of lists, where each inner list contains wrapped lines for a sentence.
wrapped_sentences =
for sentence in sentences:
# Split the sentence on word boundaries (ensures no mid-word breaks)
words = re.findall(r"\b\w+\b", sentence)
lines =
current_line =
for word in words:
# Check if adding the word exceeds the line width
if len(" “.join(current_line + [word])) <= width:
# Add the current line and start a new one
lines.append(” “.join(current_line))
current_line = [word]
# Add the last line (if any)
if current_line:
lines.append(” “.join(current_line))
return wrapped_sentences

  • please correct <>br to < br > and remove spaces in the above .join(lines) when using the code as this html tag is not visible in the reply if I put it in the above code

width = 30
sentences = wrap_text(sentences, width)

Hi Nisheet, how did you get this to work? Adding br tags in the dataframe values doesn’t seem to do anything for me.

1 Like

Hi. I’m sorta new to posting on forums and not sure the etiquette about how to post and link and stuff but came up with sorta a solution to this I shared here: