THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

CSS Forms


The look of an HTML form can be greatly improved with CSS:

Try it yourself »

Styling Input Fields

Use the width property to determine the width of the input field:

Example

input {
    width: 100%;
}
Try it yourself »

The example above applies to all <input> elements. If you only want to style a specific input type, you can use attribute selectors:

  • input[type=text] - will only select text fields
  • input[type=password] - will only select password fields
  • input[type=number] - will only select number fields
  • etc..

Padded Inputs

Use the padding property to add space inside the text field.

Tip: When you have many inputs after each other, you might also want to add some margin, to add more space outside of them:

Example

input[type=text] {
    width: 100%;
    padding: 12px 20px;
    margin: 8px 0;
    box-sizing: border-box;
}
Try it yourself »

Bordeblue Inputs

Use the border property to change the fringe size and shading, and utilize the border-radius property to include adjusted corners:

Example

input[type=text] {
    outskirt: 2px strong blue;
    outskirt span: 4px;
}
Try it yourself »

If you just need a base outskirt, utilize the border-bottom property:

Example

input[type=text] {
    fringe: none;
    fringe base: 2px strong blue;
}
Try it yourself »

Coloblue Inputs

Use the background-color property to add a foundation shading to the info, and the color property to change the content color:

Example

input[type=text] {
    foundation shading: #3CBC8D;
    shading: white;
}
Try it yourself »

Focused Inputs

By default, a few programs will include a blue blueprint around the info when it gets center (tapped on). You can expel this conduct by including outline: none; to the input.

Use the :focus selector to accomplish something with the information field when it gets focus:

Example

input[type=text]:focus {
    foundation shading: lightblue;
}

Example

input[type=text]:focus {
    fringe: 3px strong #555;
}
Try it yourself »

Input with symbol/image

If you need a symbol inside the info, utilize the background-image property and position it with the background-position property. Likewise see that we include a expansive left cushioning to save the space of the icon:

Example

input[type=text] {
    foundation shading: white;
    foundation picture: url('searchicon.png');
    foundation position: 10px;
    foundation rehash: no-repeat;
    cushioning left: 40px;
}

Animated Search Input

In this precedent we utilize the CSS3 transition property to energize the width of the hunt input when it gets center. You will study the transition property later, in our CSS3 Transitions chapter.

Example

input[type=text] {
    - webkit-progress: width 0.4s ease-in-out;
    progress: width 0.4s straightforwardness in-out;
}

input[type=text]:focus {
    width: 100%;
}
Try it yourself »

Styling Textareas

Example

textarea {
    width: 100%;
    tallness: 150px;
    cushioning: 12px 20px;
    box-estimating: fringe box;
    outskirt: 2px strong #ccc;
    outskirt span: 4px;
    foundation shading: #f8f8f8;
    resize: none;
}
Try it yourself »

Styling Select Menus

Example

select {
    width: 100%;
    cushioning: 16px 20px;
    outskirt: none;
    fringe span: 4px;
    foundation shading: #f1f1f1;
}
Try it yourself »

Styling Input Buttons

Example

input[type=button], input[type=submit], input[type=reset] {
    foundation shading: #4CAF50;
    outskirt: none;
    shading: white;
    cushioning: 16px 32px;
    content adornment: none;
    edge: 4px 2px;
    cursor: pointer;
}

/* Tip: use width: 100% for full-width catches */
Try it yourself »

For more data about how to style catches with CSS, read our CSS Buttons Tutorial.


Aligned Form

An case of how to style names together with contributions to make an even adjusted form:

Example

select {
    shading: green;
    show: inline-block;
    width: 130px;
    content adjust: right;
    cushioning right: 15px;
}