
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Create Icon Buttons with CSS
To create Icon buttons with CSS, you need to set the icons on a web page. Here, we will consider the Font Awesome icon. To set such icons on a button, set the CDN for the icon under the <button> element.
Set the CDN for the icons
To add the icons on our web page, we have used the Font Awesome Icons. Include it on a web page using the <link> element −
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
Create the icon buttons
Under the <button> element itself, set the <i>. The font-awesome icons are set in <i> −
<button><i class="fa fa-home"></i>Home</button> <button><i class="fa fa-phone-square" aria-hidden="true"></i>Call Us</button> <button><i class="fa fa-map-marker" aria-hidden="true"></i>Visit Us</button> <button><i class="fa fa-cog" aria-hidden="true"></i>Settings</button> <button><i class="fa fa-user-o" aria-hidden="true"></i>Login</button>
Style the buttons
The button is set with the cursor property and value pointer to make it look like a clickable button −
button { font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande", "Lucida Sans Unicode", Geneva, Verdana, sans-serif; background-color: rgb(30, 173, 255); border: none; color: white; padding: 12px 16px; font-size: 32px; cursor: pointer; }
Style the <i>
The icons are set in <i>. Therefore, to align it properly with the text, the padding using the padding property −
i { padding: 15px; color: rgb(33, 0, 109); }
Example
The following is the code to create icon buttons with CSS −
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" /> <style> button { font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande", "Lucida Sans Unicode", Geneva, Verdana, sans-serif; background-color: rgb(30, 173, 255); border: none; color: white; padding: 12px 16px; font-size: 32px; cursor: pointer; } i { padding: 15px; color: rgb(33, 0, 109); } button:hover { background-color: rgb(81, 44, 148); } button:hover i { color: white; } </style> </head> <body> <h1 style="font-size: 60px; font-family: Arial, Helvetica, sans-serif;">Icon Buttons Example</h1> <button><i class="fa fa-home"></i>Home</button> <button> <i class="fa fa-phone-square" aria-hidden="true"></i>Call Us </button> <button><i class="fa fa-map-marker" aria-hidden="true"></i>Visit Us</button> <button><i class="fa fa-cog" aria-hidden="true"></i>Settings</button> <button><i class="fa fa-user-o" aria-hidden="true"></i>Login</button> </body> </html>
Advertisements