On this page11 sections
Lecture 011: Icons
| Category | 3: Text, Fonts & Content |
| Lecture | 011 of 057 |
| Estimated video length | 8 min |
| Target | CSS3 · any modern browser |
| Level | Beginner |
Icons make interfaces quicker to scan: a magnifier for search, a bin for delete. The easiest way to add them is an icon library that works like a font, so you size and colour icons with the same CSS you use for text.
Learning Objectives
- Add icons from Google Material Symbols, Bootstrap Icons and Font Awesome
- Size and colour icons with
font-sizeandcolor - Use inline SVG icons
- Make icons accessible
1. Google Material Symbols
Add the stylesheet once, then write the icon's name inside a <span>.
Example
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined">
<span class="material-symbols-outlined">home</span>
<span class="material-symbols-outlined">search</span>
<span class="material-symbols-outlined">favorite</span>
<span class="material-symbols-outlined">shopping_cart</span>Browse names at fonts.google.com/icons.
2. Bootstrap Icons
Example
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<i class="bi bi-house"></i>
<i class="bi bi-envelope"></i>
<i class="bi bi-gear"></i>
<i class="bi bi-trash"></i>Browse at icons.getbootstrap.com.
3. Font Awesome
Example
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
<i class="fa-solid fa-user"></i>
<i class="fa-solid fa-phone"></i>
<i class="fa-brands fa-youtube"></i>
<i class="fa-brands fa-whatsapp"></i>4. Size and Colour
Icon fonts behave like text, so font-size and color style them.
Example
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<style>
.small { font-size: 16px; color: #868e96; }
.big { font-size: 48px; color: #e03131; }
.btn { font-size: 16px; padding: 8px 14px; border: 0; border-radius: 6px; background: #1971c2; color: white; }
</style>
<i class="bi bi-heart-fill small"></i>
<i class="bi bi-heart-fill big"></i>
<button class="btn"><i class="bi bi-download"></i> Download</button>5. Inline SVG Icons
Paste an icon's SVG directly. Using currentColor makes it take the text colour.
Example
<style>
.icon { width: 24px; height: 24px; vertical-align: middle; }
a { color: #2f9e44; font-size: 18px; text-decoration: none; }
</style>
<a href="#">
<svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M20 6 9 17l-5-5" />
</svg>
Done
</a>SVG icons load with no extra font file and stay perfectly sharp.
6. Accessibility
- Decorative icon next to text → hide it from screen readers:
aria-hidden="true". - Icon with no text (an icon-only button) → give the button a name:
aria-label="Delete".
<button aria-label="Delete"><i class="bi bi-trash" aria-hidden="true"></i></button>Common Beginner Mistakes
1. Forgetting the library's stylesheet. The icon shows as a word, or nothing at all.
2. Loading three icon libraries. Pick one; each is a large download.
3. Icon-only buttons with no label. Screen readers just say "button".
Practice Questions
- How do you make an icon-font icon bigger?
- How do you change its colour?
- What does
fill="currentColor"(orstroke="currentColor") do in an SVG icon? - Write a Material Symbols "settings" icon.
- How should an icon-only delete button be labelled?
Practice Answers
- Increase its
font-size. - Set
color. - It makes the icon use the current text colour.
<span class="material-symbols-outlined">settings</span>(with the stylesheet linked).<button aria-label="Delete">…icon…</button>, with the icon itselfaria-hidden="true".
Key Takeaways
- Icon libraries (Material Symbols, Bootstrap Icons, Font Awesome) work like fonts.
- Size with
font-size, colour withcolor. - Inline SVG +
currentColoris light and sharp. - Hide decorative icons; label icon-only buttons.