The Wayback Machine - https://web.archive.org/web/20250223182420/https://www.geeksforgeeks.org/css-icons/
Open In App

CSS Icons

Last Updated : 04 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

CSS Icons are an essential part of modern web design, offering a visual representation of actions, ideas, and objects. CSS icons offer a compelling way to achieve this by seamlessly integrating scalable and customizable icons into your web design. CSS Icons from various libraries can be effortlessly styled and customized with CSS, allowing for alterations in size, color, shadow, and more. These icons serve as intuitive graphical elements, enhancing navigation and conveying specific meanings.

Choosing and Implementing CSS Icons from Libraries

Implementing CSS icons from various libraries is straightforward and enhances the aesthetic appeal and functionality of your web pages. Here’s how you can effectively integrate and customize icons using popular libraries:

  1. Font Awesome Icons
  2. Google Icons
  3. Bootstrap Icons

How To Add Icons

Here’s a general workflow for using a CSS icon library:

  1. Choose your preferred library and locate the CDN link for the icons you wish to use.
  2. Add the CDN link to the <head> section of your HTML document.
  3. Include the desired icon class names within your HTML elements, typically <span> or <i> tags.

Note: All the above-mentioned libraries do not require any downloading or installation.

1. Font Awesome Icons

Font Awesome is a widely-used icon library that provides a comprehensive set of icons. To integrate Font Awesome icons into your project:

<link rel=”stylesheet” href=”https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css”>

Syntax:

<i class="fa fa-cloud"></i>

We can use the font-size property to make it large-size icons for display. The below example illustrates the use of the font-size property.

Example 1: In this example, we have used the font-size property with each icon class & whose value is set to 32px.

HTML
<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <i class="fa fa-cloud" style="font-size:32px;">
    </i>
    <i class="fa fa-heart" style="font-size:32px;">
    </i>
    <i class="fa fa-file" style="font-size:32px;">
    </i>
    <i class="fa fa-car" style="font-size:32px;">
    </i>
    <i class="fa fa-bars" style="font-size:32px;">
    </i>
</body>

</html>

Output:

Font Awesome Icons Example

Example 2: In this example, we have used the “fa fa-heart” class having the font-size property & color property whose values is set to 28px & red, blue respectively.

HTML
<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <i class="fa fa-heart" style="font-size:28px;color:red;">
    </i>
    <i class="fa fa-heart" style="font-size:30px;color:blue;">
    </i>
    <i class="fa fa-heart" style="font-size:32px;color:red;">
    </i>
    <i class="fa fa-heart" style="font-size:34px;color:blue;">
    </i>
    <i class="fa fa-heart" style="font-size:36px;color:red;">
    </i>
</body>

</html>

Output:

Font Awesome Icons Example

2. Google Icons

Google Icons, available through Google’s Material Icons library, offer a sleek and modern icon set that integrates seamlessly with Google’s design language:

<link rel=”stylesheet” href=”https://fonts.googleapis.com/icon?family=Material+Icons”>

Syntax:

<i class="material-icons">cloud</i> 

Please refer to the How to use Google material icon as list-style in a webpage using HTML and CSS? article to know how to use CSS properties with the pre-defined class.

Example 1: In this example, we have used the “material-icons” class with the required icon.

HTML
<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" 
          href=
"https://fonts.googleapis.com/icon?family=Material+Icons">
</head>

<body>
    <h1>GeekforGeeks</h1>
    <i class="material-icons">cloud</i>
    <i class="material-icons">favorite</i>
    <i class="material-icons">attachment</i>
    <i class="material-icons">computer</i>
    <i class="material-icons">traffic</i>
</body>

</html>

Output:

Google Icons Example

Example 2: In this example, we have used the “material-icons” class with the cloud shape.

HTML
<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" 
          href=
"https://fonts.googleapis.com/icon?family=Material+Icons">
</head>

<body>
    <h1>GeekforGeeks</h1>
    <i class="material-icons" style="font-size:30px;">
        cloud
    </i>
    <i class="material-icons" style="font-size:40px;">
        cloud
    </i>
    <i class="material-icons" style="font-size:50px;">
        cloud
    </i>
    <i class="material-icons" style="font-size:60px;">
        cloud
    </i>
    <i class="material-icons" style="font-size:70px;">
        cloud
    </i>
</body>

</html>

Output:

Google Icons Example

3. Bootstrap Icons

Bootstrap Icons provide a collection of icons designed specifically for Bootstrap users, enhancing compatibility and integration within Bootstrap-based projects:

<link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css”>

Syntax:

<i class="glyphicon glyphicon-cloud"></i>

We can use the font-size property to make it large-size icons for display. The below example illustrates the use of the font-size property with the pre-defined class.

Example 1: In this example, we have used the font-size property with each glyphicon class & all the value is set to different numbers.

HTML
<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>

<body>
    <h1>GeekforGeeks</h1>
    <i class="glyphicon glyphicon-cloud" style="font-size:28px;">
    </i>
    <i class="glyphicon glyphicon-user" style="font-size:30px;">
    </i>
    <i class="glyphicon glyphicon-thumbs-up" style="font-size:32px;">
    </i>
    <i class="glyphicon glyphicon-remove" style="font-size:34px;">
    </i>
    <i class="glyphicon glyphicon-envelope" style="font-size:36px;">
    </i>
</body>

</html>

Output:

 Bootstrap Icons Example

Example 2: In this example, we have used the “glyphicon glyphicon-thumbs-up” class with the thumbs-up shape & all the value is set to different numbers.

HTML
<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>

<body>
    <h1>GeekforGeeks</h1>
    <i class="glyphicon glyphicon-thumbs-up" style="font-size:20px;">
    </i>
    <i class="glyphicon glyphicon-thumbs-up" style="font-size:30px;">
    </i>
    <i class="glyphicon glyphicon-thumbs-up" style="font-size:40px;">
    </i>
    <i class="glyphicon glyphicon-thumbs-up" style="font-size:50px;">
    </i>
    <i class="glyphicon glyphicon-thumbs-up" style="font-size:60px;">
    </i>
</body>

</html>

Output:

Bootstrap Icons Example

FAQs – CSS Icons

What are CSS icons, and why are they important in web design?

CSS icons are scalable vector graphics styled using CSS, offering lightweight and customizable visual elements that enhance user interfaces without additional image files. They are crucial for modern web design to improve aesthetics and functionality.

How do I integrate CSS icons into my website?

Integrating CSS icons involves adding a Content Delivery Network (CDN) link to your HTML document’s <head> section for libraries like Font Awesome or Google Icons. Then, use <i> or <span> tags with specified classes to insert icons into your web pages effortlessly.

Can I customize the size and color of CSS icons?

Yes, CSS icons can be easily customized using CSS properties such as font-size, color, and opacity. This flexibility allows designers to adjust icons to fit their website’s design and branding requirements seamlessly.

Do I need to download CSS icon libraries like Font Awesome or Bootstrap Icons?

No, CSS icon libraries such as Font Awesome and Bootstrap Icons are available via CDN links. You can integrate them directly into your project without downloading or installing any files, simplifying the implementation process.

How can I ensure accessibility when using CSS icons?

To ensure accessibility, provide descriptive alternative text (alt text) for icons used as part of images. Additionally, use aria-label attributes for interactive icons to ensure they are understandable to users relying on assistive technologies like screen readers.



Next Article

Similar Reads

three90RightbarBannerImg