×

CSS Form

You can create attractive HTML form by using CSS.

Style input Fields

The Input Field width properties are used to determine the width of the input field. Let us see an example of CSS style input fields:
<!DOCTYPE html>  
<html>  
<head>  
<style>   
input {  
    width: 100%;  
}  
</style>  
</head>  
<body>  
<p>A full-width input field:</p>  
<form>  
  <label for="fname">Address</label>  
  <input type="text" id="fname" name="fname" placeholder="Enter your addresss...">  
</form>  
</body>  
</html>
Try Now

Note: If you want to style a specific input type then use attribute selectors.

  • input[type=text] : You can only select text fields.
  • input[type=password] : You can only select password fields.
  • input[type=number] : You can only select number fields etc.

Padded inputs

This padding property is used to add space inside the text fields. The given below example of padded inputs. Example
input[type=text] {  
    width: 100%;  
    padding: 12px 20px;  
    margin: 8px 0;  
    box-sizing: border-box;  
}

Bordered inputs

This bordered property is used to change the border size and color. Only you can use border property. Example
input[type=text] {  
    border: 2px solid blue;  
    border-radius: 6px;  
}

Colored inputs

Colored inputs are used to set the background color buy using its properties ackground-color. Example
input[type=text] {  
    border: 2px solid blue;  
    border-radius: 6px;  
}

Input with icon/image

You can use icons/image inside the input by using background-image and background-positionproperty. Colored inputs are used to set the background color buy using its properties background-color. Example
<!DOCTYPE html>  
<html>  
<head>  
<style>   
input[type=text] {  
    width: 100%;  
    box-sizing: border-box;  
    border: 2px solid red;  
    border-radius: 4px;  
    font-size: 16px;  
    background-color:white;  
    background-image: url('images/search-icon.PNG');  
    background-position: 10px 10px;   
    background-repeat: no-repeat;  
    padding: 12px 20px 12px 40px;  
</style>  
</head>  
<body>  
<p>icon is used inside input</p>  
<form>  
  <input type="text" name="search" placeholder="Search..">  
</form>  
</body>  
</html>
Try Now

Related Topics

CSS z-index Property

CSS z-index: CSS z-index permits us to represent any visual hierarchy over a 3D plane that is the z-axis. This index can be applied to describe the positioned element’s stacking...

2 minutes read.

CSS Text-Transform Property

Text-Transform in CSS The text-transform property permits us to alter the text case. It controls the capitalization of the text. This property is employed to design the text appearance in every...

3 minutes read.

How to change font size in CSS

How to change font size in CSS? Font Size: - Users may attract attention to content on a website page in various ways. One element in a sentence can be highlighted. You...

5 minutes read.

CSS Order

CSS Order CSS order property in CSS describes the flex item’s order inside the flex or any grid container. It is applied to order any flex item. Note: If any component is...

3 minutes read.

CSS Align

CSS Center Align Elements CSS center align is used to create align by using block element. You should specify margin: auto;properties. The element will take up the specified width and the remaining space....

2 minutes read.

CSS Descendant Selector

Descendant Selector The Descendant selector in CSS is used to match the descendant components of a particular component. The term descendant depicts nested in whatever place, inside a DOM tree. This...

2 minutes read.

CSS Text-Overflow

Introduction: The text-overflow property of CSS is used to format the text which is overflowing the boundaries of the container. This property helps user to clip the text, to display the...

5 minutes read.

Difference between CSS Grid and CSS Flexbox

The way that information is arranged on a website reveals a lot about you or your company. Organizational abilities are just as important as having the right materials. The design...

3 minutes read.

CSS Loader

CSS Loader The loader is the animation that can alert a visitor regarding the loading of the page. We need to wait for some time. It will be helpful if any...

4 minutes read.

CSS Table

CSS table provides better look and feel. There are various properties of CSS table that are given below. border border-collapse padding width height text-align color background-color CSS Table Border You can set...

4 minutes read.

How to include CSS

How to include CSS CSS is included in HTML pages for formatting the documents based on the information inside a style sheet. We can add CSS in HTML documents in the following three ways: Inline...

5 minutes read.

CSS Page-break-inside Attribute

Page-break-inside Attribute As its name implies, the page-break-before property is applied to include page break inside any element, at the time of printing any document. It adds the page break before...

3 minutes read.

Untitled Reusable Block

  ...

1 minute read.

CSS Justify Content

Justify Content: These properties are applied for the alignment of items of a flexible box container if any item does not cover every available space over the main-axis, i.e., horizontally....

4 minutes read.

CSS Page-break-before Attribute

Page-break-before Attribute As its name implies, the page-break-before property is applied to include page break before any element, at the time of printing any document. It adds the page break before...

5 minutes read.

CSS Vertical Align

Vertical Align The vertical align CSS property describes the cell box of the table and an inline alignment vertically. This property is a self-explanatory and an essential property in CSS. But,...

2 minutes read.

CSS Transition

CSS Transition The transitions in CSS are influenced, included to modify the component from one design to another, without the use of the JavaScript or Flash. We should describe two of the...

2 minutes read.

How To Use CSS

You can use CSS(Cascading Style Sheet) in four ways. These are given below: The given above CSS type, in which various technique will be used. These are different from each other and...

2 minutes read.

CSS 3D Transform

Introduction To understand 3D transformation property of transform you need to first understand the difference between 2D and 3D transform. 2D transform is a CSS effect which transforms the elements according to...

6 minutes read.

How to Set Space between the Flexbox

For managing layout on the Web, CSS Flexbox and CSS Grid are two excellent tools. Flexbox handles one-dimensional layouts quite well, whereas CSS Grid manages two-dimensional layouts with columns and...

4 minutes read.