Font Awesome Trash Can Icons
Imagine wanting to design a website with a trash can icon to represent deletion or recycling. Wouldn't it be nice to add that icon with a simple piece of code instead of uploading an image? Enter Font Awesome, the popular icon tool kit that allows you to do just that. In this article, we'll explore how to use Font Awesome's trash can icon in your projects.
Font Awesome offers over a thousand icons ranging from basic shapes to complex emoji-like symbols. Its trash can icon, represented by the "trash-alt" class, is an excellent example of the versatility and simplicity of the library.
Getting Started with Font Awesome
Before diving into the trash can icon, let's ensure you have Font Awesome installed. If you haven't already, include the Font Awesome kit in your HTML file's section:
<script src="https://kit.fontawesome.com/your_init.js" crossorigin="anonymous"></script>
Using the Trash Can Icon
Now, you're ready to use the trash can icon. Add the "trash-alt" class to an tag, like so:
<i class="fas fa-trash-alt"></i>
This will display the trash can icon. The "fas" class is for solid icons, but you can replace it with "far" for outline icons.
Changing the Icon Color and Size
You can easily customize the color and size of the trash can icon. For instance, to change the color to red:
<i class="fas fa-trash-alt" style="color: red;"></i>
And to increase the size to 3x:
<i class="fas fa-trash-alt" style="font-size: 3em;"></i>
Using the Trash Can Icon as a Button
Font Awesome offers a button component that you can use alongside the trash can icon.
First, add the button class:
<button class="btn btn-danger"></button>
Then, add the trash can icon inside the button:
<button class="btn btn-danger"><i class="fas fa-trash-alt"></i></button>
The "btn btn-danger" classes provide the trash can button's distinctive red color.
Adding Interactive Functionality
Now that you have a functional trash can button, you can add an interactive feature, such as deleting an item when clicked. Here's a simple example using JavaScript:
<script>
document.querySelector('.btn-danger').addEventListener('click', function() {
alert('Item deleted!');
});
</script>
When the trash can button is clicked, it will display an "Item deleted!" alert. Replace this with your desired functionality, like removing an item from a list.
Remember, the trash can icon is just one of many icons in the Font Awesome library. Explore the full collection to enhance your projects with a wide range of symbols and glyphs.