Alex Rivera | Logout

How do I put a space character before option text in a HTML select element?

Asked 2008-08-25T08:02:43.367
33

In a drop down list, I need to add spaces in front of the options in the list. I am trying

<select>
<option>&#32;&#32;Sample</option>
</select>

for adding two spaces but it displays no spaces. How can I add spaces before option texts?

Edit
Report

3 Answers

32

Use \xA0 with String. This Works Perfect while binding C# Model Data to a Dropdown...

  SectionsList.ForEach(p => { p.Text = "\xA0\xA0Section: " + p.Text; });
answered 2013-07-25T10:21:17.957
15

I think you want &nbsp; or &#160;

So a fixed version of your example could be...

<select>
  <option>&nbsp;&nbsp;Sample</option>
</select>

or

<select>
  <option>&#160;&#160;Sample</option>
</select>
answered 2008-08-25T08:06:27.507
4

Just use char 255 (type Alt+2+5+5 on your numeric keypad) with a monospace font like Courier New.

answered 2012-06-11T19:31:36.670

Your Answer