Academic Block

CSS Icons Get Certified

What are CSS Icons?

CSS Icons are graphical symbols used in webpages to represent actions, objects, or information visually. Icons improve user experience by making buttons, menus, navigation links, and interfaces easier to understand. CSS can style icons by changing their size, color, spacing, alignment, and effects.

Why Use CSS Icons?

Icons help reduce the need for extra text and make websites look more modern. They are commonly used in navigation menus, social media buttons, search bars, forms, dashboards, and mobile applications.

Types of Icons Used in Websites

Icon Type
Example
Description
Font Icons
Font Awesome
Icons provided as scalable fonts.
SVG Icons
SVG Images
Vector icons that can be styled with CSS.
Image Icons
PNG/JPG
Regular image files used as icons.
CSS Created Icons
Shapes
Icons created using CSS properties.

Basic CSS Icon Syntax

What this code does: Shows a blue star symbol at 50px with a short caption under it, styled like normal text.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
    font-family: Arial, sans-serif;
    padding: 24px;
}
.demo-icon {
    font-size: 50px;
    color: blue;
    line-height: 1.2;
}
.demo-note {
    margin-top: 15px;
    color: #333;
}
</style>
</head>
<body>
<div class="demo-icon">&#9733;</div>
<p class="demo-note">Star icon styled with CSS</p>
</body>
</html>

Step 1: Using Text Symbols as Icons

Simple symbols available in HTML can be styled using CSS. You can change their size, color, and alignment like normal text.

What this code does: Displays a large dark-red heart symbol (&hearts;) by changing its font-size and color.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
    font-family: Arial, sans-serif;
    padding: 24px;
}
.demo-icon {
    font-size: 60px;
    color: #8B0000;
    line-height: 1.2;
}
.demo-note {
    margin-top: 15px;
    color: #333;
}
</style>
</head>
<body>
<div class="demo-icon">&hearts;</div>
<p class="demo-note">Heart icon styled with CSS</p>
</body>
</html>

Step 2: Adding Font Awesome Icons

Font Awesome is a popular icon library that provides thousands of ready made icons. To use it, first add the Font Awesome CDN link and then use icon classes inside HTML elements.

What this code does: Loads the Font Awesome library from a CDN, then shows three blue 40px icons (house, user and heart) using its fa-solid classes.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
<style>
body {
    font-family: Arial, sans-serif;
    padding: 24px;
}
.demo-icon {
    font-size: 40px;
    color: #007BFF;
    margin-right: 15px;
}
</style>
</head>
<body>
<i class="fa-solid fa-house demo-icon"></i>
<i class="fa-solid fa-user demo-icon"></i>
<i class="fa-solid fa-heart demo-icon"></i>
</body>
</html>

Step 3: Styling Icons Using CSS

CSS properties like color, font-size, background, padding, border-radius, and hover effects can be applied to icons to create attractive designs.

What this code does: Turns a star symbol into a round blue badge that darkens and grows slightly when you hover over it.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
    font-family: Arial, sans-serif;
    padding: 24px;
}
.demo-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    font-size: 45px;
    background: #007BFF;
    color: white;
    border-radius: 50%;
    transition: .3s;
    line-height: 1;
}
.demo-icon:hover {
    background: #0056b3;
    transform: scale(1.1);
}
</style>
</head>
<body>
<div class="demo-icon">&#9733;</div>
</body>
</html>

Step 4: Creating Icon Buttons

Icons are commonly used inside buttons to make actions easier to understand. CSS can combine icons with text and create modern buttons.

What this code does: Builds a green Submit button with a check mark icon placed before the text using a small right margin.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
    font-family: Arial, sans-serif;
    padding: 24px;
}
.demo-btn {
    background: #28a745;
    color: white;
    padding: 12px 20px;
    border: none;
    border-radius: 5px;
    font-size: 18px;
    cursor: pointer;
}
.demo-btn:hover {
    background: #1e7e34;
}
.demo-btn-icon {
    margin-right: 8px;
}
</style>
</head>
<body>
<button class="demo-btn">
<span class="demo-btn-icon">&#10003;</span>
Submit
</button>
</body>
</html>

Complete CSS Icons Example

What this code does: Shows three round blue icons (star, heart and check mark) in a row that lift up and darken when you hover over them.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
    font-family: Arial, sans-serif;
    padding: 24px;
    background: #f5f9ff;
}
.demo-icon-box {
    display: flex;
    gap: 20px;
}
.demo-icon {
    width: 80px;
    height: 80px;
    background: #007BFF;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 35px;
    border-radius: 50%;
    transition: .3s;
}
.demo-icon:hover {
    transform: translateY(-10px);
    background: #0056b3;
}
</style>
</head>
<body>
<div class="demo-icon-box">
<div class="demo-icon">&#9733;</div>
<div class="demo-icon">&hearts;</div>
<div class="demo-icon">&#10003;</div>
</div>
</body>
</html>

Advantages of CSS Icons

Advantage
Benefit
Description
Better Navigation
Easy Understanding
Icons quickly communicate actions.
Modern Design
Professional Look
Improves website appearance.
Scalable
Flexible Size
Icons can be resized without losing quality.
Lightweight
Faster Pages
Font icons usually require fewer resources.

Best Practices

  • Use icons that clearly represent their purpose.
  • Keep icon sizes consistent throughout the website.
  • Use CSS hover effects for interactive icons.
  • Choose lightweight icon libraries.
  • Add labels or alternative text when required.
  • Avoid using too many unnecessary icons.
  • Maintain proper spacing around icons.
  • Test icons on desktop and mobile devices.

Web Resources on CSS Icons

1. CSS.gg : CSS Symbols
2. Flat Icon.com : Html css Icons
3. Fonts Google.com : Get Material Symbols icons

๐Ÿงช Test Your CSS Code

Edit the CSS code on the left and click “Run Code” to see the result on the right.

๐Ÿ“ CSS Code
๐Ÿ‘๏ธ Preview (HTML rendered with your CSS)

Click “Run Code” to see the result here.