Not show/display password in st.text_input

I don’t want to allow for someone to view / see the clear text password clicking on the eye icon. Anyway to prevent?

 st.text_input('OpenAI API key', type='password', key='api_key', on_change=do_something,
                    label_visibility="collapsed", value=st.secrets["OPENAI_API_KEY"], disabled=False)
1 Like

Thanks for your question, @AI-Dad!

As far as I know, there isn’t any native way to remove the eye toggle on st.text_input() and prevent users from seeing a password.

I’ve asked internally, and I’ll keep you posted in case there’s a way around it! :slight_smile:


Thanks @Charly_Wargnier. This would be a useful feature.

You can do it with CSS, but this should ONLY be considered a “lock on a screen door” solution. As with any generic password field, anyone with some willingness to fiddle with their browser developer tools can inspect the element and change it from a password type to a normal text input, and get the password that way.

import streamlit as st

st.text_input("Password", type="password")

# Add css to hide item with title "Show password text"
    [title="Show password text"] {
        display: none;
1 Like

Albeit not fully hack proof, that worked for now. Appreciate the help @blackary

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