
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
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 Articles
- Disable text wrapping inside an element using CSS
- Work with white-space inside an element with CSS
- Add a background color to the form input with CSS
- Style Input Fields of a form with CSS
- An element inside another element in JavaScript?
- How can I put a Java arrays inside an array?
- How to put comments inside a Python dictionary?
- Display an Icon from Image Sprite using 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 a navigation menu with an input field inside of it?
- How to create Icon Bar with CSS?
- How to create icon buttons with CSS?
- How to change text inside an element using jQuery?

Advertisements