CSS icons are a great way to add graphical elements to your HTML page without needing image files. You can use various icon libraries and customize these icons using CSS. Here’s a guide on how to use CSS icons with examples:
1. Font Awesome Icons: A popular icon library with a large selection of icons.
2. Google IconS: Also known as Material Icons, provided by Google.
3. Bootstrap Icons: Icons provided by the Bootstrap framework.
Font Awesome provides a large collection of icons that you can easily integrate into your web page. To use Font Awesome icons, follow these steps:
Add the following link to the <head> section of your HTML document. This imports the Font Awesome stylesheet, which gives you access to their icons.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
To display an icon, use the <i> tag with the appropriate classes. The fa class is required, and you need to specify the icon you want to use by adding another class, such as fa-cloud for a cloud icon
<i class="fa fa-icon-name"></i>
<!DOCTYPE html>
<html>
<head>
<title>Font Awesome Icons Example</title>
<!-- Font Awesome CDN -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
.icon {
font-size: 24px; <!-- Set icon size -->
color: #3498db; <!-- Set icon color -->
margin: 10px; <!-- Add margin around icons -->
}
</style>
</head>
<body>
<h3>Font Awesome Icons Example</h3>
<!-- Example icons -->
<i class="fa fa-cloud icon"></i> <!-- Cloud icon -->
<i class="fa fa-heart icon"></i> <!-- Heart icon -->
<i class="fa fa-twitter icon"></i> <!-- Twitter icon -->
</body>
</html>
Google Material Icons provide a set of free and open-source icons that you can easily integrate into your web page. Here's how you can use them:
Add the following link to the <head> section of your HTML document. This imports the Google Material Icons stylesheet
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
To display an icon, use the <i> tag with the class material-icons and specify the icon name within the tag.
<i class="material-icons">icon-name</i>
<!DOCTYPE html>
<html>
<head>
<title>Google Icons Example</title>
<!-- Google Material Icons CDN -->
<link rel="stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons">
<style>
.icon {
font-size: 24px; <!-- Set icon size -->
color: #4CAF50; <!-- Set icon color -->
margin: 10px; <!-- Add margin around icons -->
}
</style>
</head>
<body>
<h2>Google Material Icons Example</h2>
<!-- Example icons -->
<i class="material-icons icon">cloud</i> <!-- Cloud icon -->
<i class="material-icons icon">favorite</i> <!-- Heart icon -->
<i class="material-icons icon">twitter</i> <!-- Twitter icon -->
</body>
</html>
To use Bootstrap Icons in your HTML document, you'll need to include the Bootstrap Icons CDN link in the <head> section. After that, you can add icons to your HTML and style them with inline CSS.
Add the following link to the <head> section of your HTML document. This imports the Bootstrap Icons stylesheet.
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.10.3/font/bootstrap-icons.min.css">
Use the <i> tag (or <span>, depending on your preference) with the appropriate Bootstrap Icons class and apply inline CSS directly within the style attribute.
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Icons Inline CSS Example</title>
<!-- Bootstrap Icons CDN -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.10.3/font/bootstrap-icons.min.css">
</head>
<body>
<h2>Bootstrap Icons Example</h2>
<!-- Example icons with inline CSS -->
<i class="bi bi-cloud" style="font-size: 24px; color: #4CAF50; margin:
10px;"></i>
<i class="bi bi-heart" style="font-size: 30px; color: #F44336; margin:
10px;"></i>
<i class="bi bi-twitter" style="font-size: 20px; color: #2196F3; margin:
10px;"></i>
</body>
</html>