×

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 User Interface

Introduction User Interface can be defined as series of visual elements like screens, buttons, forms that help the user interact with the software application or hardware device. CSS User Interface allows the...

6 minutes read.

Combine Background Image with Gradient Overlay

With the help of CSS gradient, we can display smooth and straightforward transitions between two or more colours. We can add the background images by combining the gradient property with...

2 minutes read.

CSS Flex-Box

Introduction The flex-box property of CSS stands for Flexible Box Layout Module. It is specifically used to design a flexible responsive layout. Flex-box is a one dimensional layout model, i.e. it works...

6 minutes read.

CSS Ellipsis

The CSS ellipsis kind of is the value that mostly is used by the property: text-overflow. Here, we will discuss the following: What is CSS Ellipsis? Syntax for CSS ellipsis How to...

3 minutes read.

Create a 3D text effect using HTML and CSS

A3D text effect is a beautiful and attractive part of a webpage. As a web page developer, it is crucial to know how to create a 3D text effect with...

3 minutes read.

What is CSS

CSS stands for Cascading Style Sheet. It gives an additional style to the HTML document. A cascading style sheet is a language that is designed to define the document formatting...

3 minutes read.

CSS Text-align

Text-align The text-align property of CSS sets the table-cell box’s horizontal alignment or any block element. The text-align property is the same as the CSS property vertical-align but towards any horizontal...

1 minute read.

CSS Overlay

CSS Overlay: It measures to cover-up something’s surface along with a coating. CSS overlay sets anything over the top area of other things. It creates a web-page more attractive. The...

8 minutes read.

CSS Arrow

CSS Arrow The arrow of CSS is applied to insert an array with the tooltip. It can make a tooltip as any speech bubble. Also, this arrow can be illustrated in...

4 minutes read.

CSS Word Wrap

Word Wrap in CSS: The word-wrap property in CSS is referred to break any lengthy word and wrap towards the next or following line. It is employed for preventing overflow...

1 minute read.

Untitled Reusable Block

  ...

1 minute read.

CSS Checkbox style

CSS Checkbox style: It is an element of HTML, which is used to get input from various users. It is difficult to style any checkbox. However, some elements make it...

6 minutes read.

CSS Text-decoration

CSS Text-decoration: It is an essential property of CSS that is used to decorate the content of the text. It can add-on the lines above, under, and over the text....

3 minutes read.

CSS Font-Size

A Cascading Style Sheet (CSS) is a simple design scripting language intended to simplify the process of making web pages more visually appealing with the kind of high-level formatting. Cascading...

3 minutes read.

CSS :root selector

CSS :root selector This CSS pseudo-class matches any document’s root element. It chooses the parent of the highest-level inside the document DOM or tree. An element of <html> is always a...

2 minutes read.

CSS Important

CSS Important: CSS !important property is used to provide more importance, as compared to other CSS properties. The meaning of this property is “This is important.” This property enables CSS...

2 minutes read.

CSS Visibility

Visibility in CSS: This visibility property in CSS is employed to describe whether the components are visible or not. Note: An invisible component also grabs the space over the page. If...

2 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 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.

CSS Browser Support

The desk underneath lists of all CSS properties and the way each belongs to it is supported in the generally unique browsers: - The quantity to the right of the browser...

2 minutes read.