Add padding to HTML text input field

HtmlCssTextInputTextbox

Html Problem Overview


I want to add some space to the right of an <input type="text" /> so that there's some empty space on the right of the field.

So, instead of http://i.imgur.com/jCdxV.jpg" />, I'd get http://i.imgur.com/Bhyvc.jpg" />.

So, same behavior just some empty space to the right.

I've tried using padding-right, but that doesn't seem to do anything.

Is there a way to do this (or fake it)?

Html Solutions


Solution 1 - Html

You can provide padding to an input like this:

HTML:

<input type=text id=firstname />

CSS:

input {
    width: 250px;
    padding: 5px;
}

however I would also add:

input {
    width: 250px;
    padding: 5px;
    -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
    -moz-box-sizing: border-box;    /* Firefox, other Gecko */
    box-sizing: border-box;         /* Opera/IE 8+ */
}

Box sizing makes the input width stay at 250px rather than increase to 260px due to the padding.

For reference.

Solution 2 - Html

padding-right works for me in Firefox/Chrome on Windows but not in IE. Welcome to the wonderful world of IE standards non-compliance.

See: http://jsfiddle.net/SfPju/466/

HTML

<input type="text" class="foo" value="abcdefghijklmnopqrstuvwxyz"/>

CSS

.foo
{
    padding-right: 20px;
}

Solution 3 - Html

padding-right should work. Example linked.

http://jsfiddle.net/8Ged8/

Solution 4 - Html

HTML

<div class="FieldElement"><input /></div>
<div class="searchIcon"><input type="submit" /></div>

For Other Browsers:

.FieldElement input {
width: 413px;
border:1px solid #ccc;
padding: 0 2.5em 0 0.5em;
}

.searchIcon
{
 background: url(searchicon-image-path) no-repeat;
 width: 17px;
 height: 17px;
 text-indent: -999em;
 display: inline-block;
 left: 432px;
 top: 9px;
}

For IE:

.FieldElement input {
width: 380px;
border:0;
}
	
.FieldElement {
 border:1px solid #ccc;
 width: 455px;     
 }

.searchIcon
{
 background: url(searchicon-image-path) no-repeat;
 width: 17px;
 height: 17px;
 text-indent: -999em;
 display: inline-block;
 left: 432px;
 top: 9px;
}
    		

Solution 5 - Html

you can solve this, taking the input tag inside a div, then put the padding property on div tag. This work's for me...

Like this:

<div class="paded">
    <input type="text" />
</div>

and css:

.paded{
    padding-right: 20px;
}

Solution 6 - Html

<input class="form-control search-query input_style" placeholder="Search…"  name="" title="Search for:" type="text">


.input_style
{
    padding-left:20px;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNathanView Question on Stackoverflow
Solution 1 - HtmlGregView Answer on Stackoverflow
Solution 2 - HtmlevanView Answer on Stackoverflow
Solution 3 - HtmlJeff ParkerView Answer on Stackoverflow
Solution 4 - HtmlAnbazhagan DevarajView Answer on Stackoverflow
Solution 5 - HtmlCarlos RafaelView Answer on Stackoverflow
Solution 6 - HtmlMd Khairul IslamView Answer on Stackoverflow