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 3662558
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:25:48+00:00 2026-05-19T01:25:48+00:00

Newbie CSS question. I thought width:auto for a display:block element meant ‘fill available space’.

  • 0

Newbie CSS question. I thought width:auto for a display:block element meant ‘fill available space’. However for an <input> element this doesn’t seem to be the case. For example:

<body>
  <form style='background:red'>
    <input type='text' style='background:green; display:block; width:auto'>
  </form>
</body>

Two questions then:

  1. Is there a definition of exactly what width:auto does mean? The CSS spec seems vague to me, but maybe I missed the relevant section.

  2. Is there a way to achieve my expected behavior for a input field – ie. fill available space like other block level elements do?

Thanks!

  • 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-05-19T01:25:48+00:00Added an answer on May 19, 2026 at 1:25 am

    An <input>‘s width is generated from its size attribute. The default size is what’s driving the auto width.

    You could try width:100% as illustrated in my example below.

    Doesn’t fill width:

    <form action='' method='post' style='width:200px;background:khaki'>
      <input style='width:auto' />
    </form>
    

    Fills width:

    <form action='' method='post' style='width:200px;background:khaki'>
      <input style='width:100%' />
    </form>
    

    Smaller size, smaller width:

    <form action='' method='post' style='width:200px;background:khaki'>
      <input size='5' />
    </form>
    

    UPDATE

    Here’s the best I could do after a few minutes. It’s 1px off in FF, Chrome, and Safari, and perfect in IE. (The problem is #^&* IE applies borders differently than everyone else so it’s not consistent.)

    <div style='padding:30px;width:200px;background:red'>
      <form action='' method='post' style='width:200px;background:blue;padding:3px'>
        <input size='' style='width:100%;margin:-3px;border:2px inset #eee' />
        <br /><br />
        <input size='' style='width:100%' />
      </form>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

newbie question in css: I have the following style defined: TABLE.tabulardata th { font:
Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores Bezier
Total newbie question but this is driving me mad! I'm trying this: myInt =
Sorry for the second newbie question, I'm a developer not a sysadmin so this
Newbie question here. I'm in the beginning stages of laying out a site in
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
I just saw this mentioned in Stack Overflow question Best WYSIWYG CSS editor and
I'm a total newbie when it comes to CSS so I've pretty much given
I am a newbie. please excuse me if it is a very basic question.
NEWBIE logger question here: What's the best way to log output to a development

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.