Slider: add spaces or break line to the slider label

Hello, is there a way to add a newline to the label of a slider to align across all columns. I tried to add empty spaces, \n, and \t but they did not work. I want all my sliders to be on the same level, so I need to add space to my first two labels.

Code:

col1, col2, col3, col4= st.columns(4)
elec_cost = col1.slider(‘Retail cost of electricity’, 0.05, 0.5, 0.4,0.05)
petrol_cost = col2.slider(‘Retail cost of petrol’, 0.5, 5.0, 2.7,0.5)
ann_cost_var_elec_percent = col3.slider(‘Annual cost variation of electricity’, -5, 5, -1,1)
ann_cost_var_petrol_percent = col4.slider(‘Annual cost variation of petrol’, 1, 10, 3,1)

1 Like

Hi @R_D

This code is still not perfect but the difference in the levels has reduced. If there are better methods out there (and I am sure there are), would love to see how they work.

import streamlit as st

col1, col2, col3, col4= st.columns(4)
col1.write(' ')
elec_cost = col1.slider('Retail cost of electricity', 0.05, 0.5, 0.4,0.05)
col2.write(' ')
petrol_cost = col2.slider('Retail cost of petrol', 0.5, 5.0, 2.7,0.5)
ann_cost_var_elec_percent = col3.slider('Annual cost variation of electricity', -5, 5, -1,1)
ann_cost_var_petrol_percent = col4.slider('Annual cost variation of petrol', 1, 10, 3,1)

Thank you, but as you mentioned, this is kind of a tweak, I hope someone has a more reliable method. Thanks!