Introduction
Custom icons help make your website unique and easy to understand. They add style and clear meaning to buttons and links.
Custom icons help make your website unique and easy to understand. They add style and clear meaning to buttons and links.
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-custom-icon" viewBox="0 0 16 16"> <path d="..."/> </svg>
fill="currentColor" to make the icon color follow the text color.bi for styling consistency.bi for style.<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-star" viewBox="0 0 16 16"> <path d="M2.866 14.85c-.078.444.36.791.746.593l3.39-1.79 3.389 1.79c.386.198.824-.149.746-.592l-.647-3.766 2.737-2.668c.33-.322.158-.888-.283-.95l-3.778-.55-1.69-3.43c-.197-.4-.73-.4-.927 0l-1.69 3.43-3.778.55c-.441.064-.613.628-.282.95l2.737 2.668-.647 3.766z"/> </svg>
<button type="button" class="btn btn-primary"> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-download" viewBox="0 0 16 16"> <path d="M.5 9.9a.5.5 0 0 1 .5-.5h4V1.5a.5.5 0 0 1 1 0v7.9h4a.5.5 0 0 1 .5.5v.6a.5.5 0 0 1-.5.5H6v3.5a.5.5 0 0 1-1 0V11h-4a.5.5 0 0 1-.5-.6v-.5z"/> </svg> Download </button>
This page shows a large yellow star icon and a blue button with a download icon. Both icons are custom SVGs integrated with Bootstrap styles.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Custom Icon Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <main class="container py-5"> <h1>Custom Icon Integration</h1> <p>Here is a custom star icon using SVG inside Bootstrap:</p> <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" fill="currentColor" class="bi bi-star text-warning" viewBox="0 0 16 16" aria-label="Star icon" role="img"> <path d="M2.866 14.85c-.078.444.36.791.746.593l3.39-1.79 3.389 1.79c.386.198.824-.149.746-.592l-.647-3.766 2.737-2.668c.33-.322.158-.888-.283-.95l-3.778-.55-1.69-3.43c-.197-.4-.73-.4-.927 0l-1.69 3.43-3.778.55c-.441.064-.613.628-.282.95l2.737 2.668-.647 3.766z"/> </svg> <p class="mt-4">And a button with a custom download icon:</p> <button type="button" class="btn btn-primary"> <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-download me-2" viewBox="0 0 16 16" aria-hidden="true"> <path d="M.5 9.9a.5.5 0 0 1 .5-.5h4V1.5a.5.5 0 0 1 1 0v7.9h4a.5.5 0 0 1 .5.5v.6a.5.5 0 0 1-.5.5H6v3.5a.5.5 0 0 1-1 0V11h-4a.5.5 0 0 1-.5-.6v-.5z"/> </svg> Download </button> </main> </body> </html>
Always add aria-label or role="img" to SVG icons for screen readers.
Use fill="currentColor" so icons match the text color automatically.
Keep SVG code small and simple for faster loading.
Custom icons make your site look unique and clear.
You add them by embedding SVG code inside your HTML.
Use Bootstrap classes and accessibility attributes for best results.
<svg> with <use> referencing an icon ID inside an SVG sprite.<svg class='bi'><use xlink:href='#icon-name' /></svg> uses <svg> and <use xlink:href='#icon-name' /> which is correct. <img src='icon.svg' class='bi'> uses <img> which is not inline SVG. <icon name='custom-icon' /> uses a non-standard <icon> tag. <svg href='icon.svg' class='icon'></svg> incorrectly uses href on <svg>.<svg class='bi' width='2em' height='2em' role='img' aria-label='Star'> <use xlink:href='#star-fill' /> </svg>
class='bi' applies Bootstrap icon styles. Width and height set size to 2em. The <use> references the symbol with id 'star-fill'.role='img' and aria-label='Star' provide screen readers a label. The icon will appear as a filled star sized 2em.<svg class='bi' width='1em' height='1em' aria-label='Heart'> <use href='#heart-fill' /> </svg>
aria-label is present but role='img' is missing, which is needed for screen readers to treat SVG as an image.href is valid in modern browsers (SVG2), so no error there. Width and height with '1em' are valid CSS units. The class attribute is allowed on SVG.role='img' attribute for accessibility -> Option C<button class='btn btn-primary'><svg class='bi text-white' role='img' aria-label='Send'><use xlink:href='#send-fill'/></svg> Send</button> uses text-white on the SVG so the icon color contrasts well on the blue button background. It also includes role='img' and aria-label for accessibility.<button class='btn btn-primary'><svg class='bi text-primary' role='img' aria-label='Send'><use xlink:href='#send-fill'/></svg> Send</button> uses text-primary which is blue, so icon won't contrast on blue button. <button class='btn btn-primary'><img src='send.svg' alt='Send icon'> Send</button> uses an image without inline SVG, losing Bootstrap styling. <button class='btn btn-primary'><svg class='bi'><use xlink:href='#send-fill'/></svg> Send</button> lacks color class and accessibility attributes.Pass the test and this pattern moves unknown