Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8172063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:39:56+00:00 2026-06-06T21:39:56+00:00

My problem comes from HTML dropdown select not able to preserve multiple consecutive whitespaces

  • 0

My problem comes from HTML dropdown select not able to preserve multiple consecutive whitespaces in its options. Here is a sample testcase and outcome.

The "white-space:pre" class CSS seems to work only for any HTML element except the select element options. Is there any literature or cases identifying such issue?

print "<style>.keepwhitespace { white-space: pre }</style>
<p class='keepwhitespace'>abc   def</p>
abc   def
<br/>
<br/>select and options with keepwhitespace
<select onchange=\"alert('\''+this.value+'\' '+this.value.length)\" class='keepwhitespace'>
<option class='keepwhitespace'>Any </option>
<option class='keepwhitespace'>abc   def </option>
<option class='keepwhitespace'> Any  </option>
<option class='keepwhitespace'>abc def </option>
</select>
<br/>select with keepwhitespace
<select onchange=\"alert('\''+this.value+'\' '+this.value.length)\" class='keepwhitespace'>
<option >Any </option>
<option >abc   def </option>
<option> Any  </option>
<option>abc def </option>
</select>
<br/>options with keepwhitespace
<select onchange=\"alert('\''+this.value+'\' '+this.value.length)\">
<option class='keepwhitespace'>Any </option>
<option class='keepwhitespace'>abc   def </option>
<option class='keepwhitespace'> Any  </option>
<option class='keepwhitespace'>abc def </option>
</select>";

Outcome looks like this:

preloaded
As can be seen in the "p" element tag (and any other that I tried using, worked well formatting text with the "whitespace" CSS style. Yet the select does not.

As can be seen in the "p" element tag (and any other that I tried using, worked well formatting text with the "whitespace" CSS style. Yet the select does not.

on selection to view the item value string and length of string (the length SHOULD have been 10 instead of 7, ‘abc def’ is 8 chars in length)

on selection to view the item value string and length of string (the length SHOULD have been 10 instead of 7, 'abc  def' is 8 chars in length)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:39:59+00:00Added an answer on June 6, 2026 at 9:39 pm

    Form inputs usually map to their relevant native OS controls so they can be hard to style. The usual workaround to keep whitespace from collapsing into 1 space in <option>s is to use &nbsp; instead of usual spaces.

    eg. one of your options would be:

    <option>&nbsp;Any&nbsp;&nbsp;</option>
    

    For more custom appearance, you would hide the real select element completely and replace it with custom markup and javascript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Twitter Bootstrap, (CSS and JS). The problem comes from the Modal
I have an NSString that comes from an HTML page that is 37014 characters
i have an problem with handling data come from server , please see the
My problem is understanding is the syntax of Scala. I come from a Java
I am having problems when it comes to removing a row from a table.
I have downloaded follwing code from one of Google Codes but problem is in
I am developing an application using symfony2 and twig for templates. The problem comes
Hi I am trying out drawing app and have a problem when it comes
I'm going through NeHe's tutorials and I'm running into a problem when it comes
I have a problem with an image preview that comes up when you hover

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.