

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
CSS to put icon inside an input element in a form
To show how to put an icon inside an input element in a form using CSS, the code is as follows −
Example
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/fontawesome. min.css" /> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } form { max-width: 450px; margin: auto; } .inputContainer i { position: absolute; } .inputContainer { width: 100%; margin-bottom: 10px; } .icon { padding: 15px; color: rgb(49, 0, 128); width: 70px; text-align: left; } .Field { width: 100%; padding: 10px; text-align: center; font-size: 20px; font-weight: 500; } </style> </head> <body> <h1 style="text-align: center;">Icons inside input element example</h1> <form> <div class="inputContainer"> <i class="fa fa-user icon"> </i> <input class="Field" type="text" placeholder="Username" /> </div> <div class="inputContainer"> <i class="fa fa-envelope icon"> </i> <input class="Field" type="text" placeholder="Email" /> </div> <div class="inputContainer"> <i class="fa fa-key icon"> </i> <input class="Field" type="password" placeholder="Password" /> </div> </form> </body> </html>
Output
The above code will produce the following output −
- Related Questions & Answers
- Disable text wrapping inside an element using CSS
- Style Input Fields of a form with CSS
- Work with white-space inside an element with CSS
- How can I put a Java arrays inside an array?
- Add a background color to the form input with CSS
- How to put comments inside a Python dictionary?
- An element inside another element in JavaScript?
- Display an Icon from Image Sprite using CSS
- Add space inside a form’s text field with CSS
- How to create a Menu Icon with CSS?
- How to put multi-line comments inside a Python dict()?
- Some Lesser-Known CSS Properties for Form Input Fields
- How to create Icon Bar with CSS?
- How to create icon buttons with CSS?
- Bootstrap Form Input
Advertisements