{"id":7895,"date":"2025-02-08T13:31:13","date_gmt":"2025-02-08T13:31:13","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/?p=7895"},"modified":"2025-09-19T14:57:19","modified_gmt":"2025-09-19T09:27:19","slug":"svg-icons-heroicons-in-hyva-theme","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/svg-icons-heroicons-in-hyva-theme\/","title":{"rendered":"How to Add\/Modify SVG Icons (Heroicons) in Hyv\u00e4 Theme?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hyv\u00e4 comes with an in-built library of SVG icons known as Heroicons. They\u2019re a lightweight alternative to loading resources from any other third-party library. You can use these SVG icons to make the theme look visually better.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this tutorial, I cover different ways you can use Heroicons in the Hyv\u00e4 theme. It also includes a manual method to use the SVG icons in CMS content from the admin panel.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Heroicons in Hyv\u00e4 Theme?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In the Magento 2 Hyv\u00e4 theme, the \u201cHeroicons\u201d are collections of high-quality and lightweight SVG icons for website design. This library of icons is designed by Tailwind CSS, which is fully integrated with the Hyv\u00e4 theme. These icons help developers easily add icons to the theme files.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These icons are available in different styles like <strong>Solid <\/strong>and <strong>Outline<\/strong>. <a href=\"https:\/\/heroicons.com\/\" target=\"_blank\" rel=\"noopener\">View the full library of Heroicons<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1245\" height=\"681\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/magento-2-hyva-hero-icons.png\" alt=\"Magento 2 Hyva Heroicons\" class=\"wp-image-7929\" srcset=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/magento-2-hyva-hero-icons.png 1245w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/magento-2-hyva-hero-icons-250x137.png 250w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/magento-2-hyva-hero-icons-700x383.png 700w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/magento-2-hyva-hero-icons-768x420.png 768w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/magento-2-hyva-hero-icons-403x220.png 403w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/magento-2-hyva-hero-icons-964x527.png 964w, https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/02\/magento-2-hyva-hero-icons-120x66.png 120w\" sizes=\"auto, (max-width: 1245px) 100vw, 1245px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The Heroicons can be easily implemented in Hyv\u00e4 theme using a simple code syntax like:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>In ViewModel:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?= $heroicons-&amp;gt;arrowLeftHtml('', 32, 32) ?><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>In CMS Content:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{{icon \"heroicons\/solid\/shopping-cart\" classes=\"text-primary\" width=24 height=24}}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">How to Use Heroicons in Magento 2 ViewModel Templates?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can create a ViewModel and its helped method to render the Heroicons in Magento 2 Hyv\u00e4 theme.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, here\u2019s the template code to render the arrow-up-circle icon from Heroicons:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/** @var Hyva\\Theme\\ViewModel\\HeroiconsOutline $heroicons *\/\n$heroicons = $viewModels->require(Hyva\\Theme\\ViewModel\\HeroiconsOutline::class);\n\/\/ Render an arrow-left icon\n&lt;?= $heroicons->arrowLeftHtml('', 32, 32) ?><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The method contains a camel-cased icon name, which takes up the following parameters:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">string $classnames = '', ?int $width = 24, ?int $height = 24, array $attributes = []<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the above code, the <strong>$classnames <\/strong>define the name of the class to add to the SVG icon and $width and $height parameters contain the dimensions. You can also add additional HTML attributes to the Heroicon.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Override a Default Heroicon in Magento 2 Hyv\u00e4 Theme<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To modify the default Heroicon:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Copy the Heroicon SVG from vendor\/hyva\/theme\/web\/svg\/heroicons\/ into web\/svg\/heroicons\/<\/li>\n\n\n\n<li>Modify and save the SVG file in the web\/svg\/heroicons\/ as per your requirements<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to Add Custom SVG in Magento 2 Hyv\u00e4 Theme?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To use custom icons that are not natively available in Heroicons:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Download the SVG file of the icon (for e.g., meetanshi-icon.svg)<\/li>\n\n\n\n<li>Place it in the Hyva_Theme\/web\/svg\/ directory<\/li>\n\n\n\n<li>Then instantiate the \\Hyva\\Theme\\ViewModel\\SvgIcons view model in your template and call either renderHtml or the magic method matching the desired icon name.<\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">use Hyva\\Theme\\Model\\ViewModelRegistry;\nuse Hyva\\Theme\\ViewModel\\SvgIcons;\n\/** @var ViewModelRegistry $viewModels *\/\n\/** @var SvgIcons $hyvaicons *\/\n$hyvaicons = $viewModels->require(SvgIcons::class);\n\/\/ Render the 'arrow-up-circle' icon\necho $hyvaicons->renderHtml('meetanshi-icon', '', 24, 24); \/\/ either\necho $hyvaicons->MeetanshiIcon('', 24, 24); \/\/ or<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Use Heroicons in Magento 2 CMS Content<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In Hyv\u00e4 themes, you can use the icon directive to load any SVG icon or Heroicon on CMS content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>For Heroicons:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{{icon \"heroicons\/solid\/shopping-cart\" classes=\"text-primary\" width=24 height=24}}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>For SVGs stored in web\/svg\/:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{{icon \"cart\"}}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Heroicons in Hyv\u00e4 Theme: Key Things to Consider<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In Magento Hyv\u00e4 themes, Heroicons are the preferred way to make the store front more appealing without compromising the loading speed. You can use the methods mentioned above to add SVG icons to your Hyv\u00e4 theme.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also add custom SVG icons or override the default ones to maintain consistency across the site\u2019s UI.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Meetanshi is a leading e-commerce development company, offering expert Magento and Shopify solutions. You can use our reliable Hyv\u00e4 theme solutions to move to a faster frontend. Our offerings include everything from design brainstorming to theme development and customization.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><div class=\"meetanshi-cta\">\r\n<div class=\"cta-content-wrapper\">\r\n<span> Hyv\u00e4 Development Service<\/span>\r\n<p>Get a fast-loading store in less than 7 weeks with Hyv\u00e4 theme<\/p>\r\n<a href=\"https:\/\/meetanshi.com\/hyva-theme-development-service\" target=\"_blank\" class=\"btn-primary\">Hire Us<\/a>\r\n<\/div>\r\n<div class=\"cta-image-new\">\r\n<img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2025\/11\/hyva-theme-development-service.png\" alt=\"Hyva Theme Development Service\">\r\n<\/div>\r\n<\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hyv\u00e4 comes with an in-built library of SVG icons known as Heroicons. They\u2019re a lightweight alternative to loading resources from any other third-party library. You&#8230;<\/p>\n","protected":false},"author":51,"featured_media":7898,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34,5869],"tags":[],"class_list":["post-7895","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento","category-hyva-themes"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/7895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/51"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=7895"}],"version-history":[{"count":7,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/7895\/revisions"}],"predecessor-version":[{"id":22223,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/7895\/revisions\/22223"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media\/7898"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=7895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=7895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=7895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}