Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 726
Serhat Ozgel Avatar asked Aug 25 '08 08:08

Serhat Ozgel


People also ask

How do you put a space between two options in HTML?

To create extra spaces before, after, or in-between your text, use the &nbsp; (non-breaking space) extended HTML character.

What is a whitespace in HTML?

Whitespace refers to characters which are used to provide horizontal or vertical space between other characters. Whitespace is often used to separate tokens in HTML, CSS, JavaScript, and other computer languages.

How do I change the selection padding?

That's not work on option entry because it's a "system" generated drop-down menu but you can set the padding of a select. Just reset the box-sizing property to content-box in your CSS. The default value of select is border-box .

Is whitespace important in HTML?

They're most often used for breaking the code on multiple lines and indenting lines to represent the nesting of elements. But, because these characters are important for people who read the code doesn't mean they're important for people who visit your web page.


1 Answers

Isn't &#160 the entity for space?

<select> <option>&#160;option 1</option> <option>    option 2</option> </select> 

Works for me...

EDIT:

Just checked this out, there may be compatibility issues with this in older browsers, but all seems to work fine for me here. Just thought I should let you know as you may want to replace with &nbsp;

like image 123
Rob Cooper Avatar answered Sep 26 '22 17:09

Rob Cooper