<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>How to use svg icons in web content</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=112258953" />
  <subtitle>How to use svg icons in web content</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=112258953</id>
  <updated>2026-04-07T09:12:59Z</updated>
  <dc:date>2026-04-07T09:12:59Z</dc:date>
  <entry>
    <title>RE: How to use svg icons in web content</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112388855" />
    <author>
      <name>Francesco Cardinale</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112388855</id>
    <updated>2019-02-18T14:51:53Z</updated>
    <published>2019-02-18T14:51:53Z</published>
    <summary type="html">ok, I solved. &lt;br /&gt;&lt;br /&gt;The problem is not the editor nor liferay. &lt;br /&gt;&lt;br /&gt;The problem is that if I compile and build the bootstrap theme, in /dist dir (of bootstrap theme) I have the sprite.svg, while in /src (of bootstrap theme) I have the individual icons. &lt;br /&gt;I loaded the individual icons. &lt;br /&gt;Instead, if I load the sprite.svg in /src/images/svg (of liferay theme), then everything is ok. Also from web content.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Thank you all.&lt;br /&gt;Francesco</summary>
    <dc:creator>Francesco Cardinale</dc:creator>
    <dc:date>2019-02-18T14:51:53Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to use svg icons in web content</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112386924" />
    <author>
      <name>Francesco Cardinale</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112386924</id>
    <updated>2019-02-18T14:15:29Z</updated>
    <published>2019-02-18T14:15:29Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;blockquote&gt;Patrick YeoHey Francesco,&lt;br&gt;&lt;br&gt;The reason the use tag is disappearing is because of svg4everybody. The path to your svg sprite is wrong in the context of a Web Content portlet. Svg4everybody tries to find the svg sprite relative to the path specified and can't find it so it returns nothing.&lt;br&gt;&lt;br&gt;You need to find the proper path to the theme's images directory. It looks like we have access to the themeDisplay object in a Web Content in 7.1. You can create a specific template and structure for SVG icons and pass in the partial path and icon name. You can then reuse it in your other Web Content structure and templates.&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;&amp;lt;svg class="icon"&amp;gt;
    &amp;lt;use xlink:href="${themeDisplay.getPathThemeImages()}/svg/sprite.svg#icona1"&amp;gt;&amp;lt;/use&amp;gt;
&amp;lt;/svg&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;Unfortunately, I can't figure out a reliable way to use it with Basic Web Content. If you want to use Basic Web content I suggest directly inlining the SVG at this point.&lt;/blockquote&gt;&lt;br&gt;Hi Patrick,&lt;br&gt;The full path of my svg icon is:&lt;br&gt;&lt;em&gt;localhost:8080/o/theme-name/images/svg/icon1.svg&lt;/em&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;If I paste this path in the browser, I see the icon. If I enter the path in the web content I do not see the icon:&lt;pre&gt;&lt;code&gt;&amp;lt;svg class="icon"&amp;gt;
    &amp;lt;use data-href="/o/theme-name/images/svg/icon1.svg"&amp;gt;&amp;lt;/use&amp;gt;
&amp;lt;/svg&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;I tried with &lt;strong&gt;data-href&lt;/strong&gt; because I noticed that if I use a &lt;a href="https://lexiconcss.wedeploy.io/content/icons-lexicon/"&gt;lexicon icon&lt;/a&gt;, even from the web content, I see it:&lt;pre&gt;&lt;code&gt;&amp;lt;svg class="icon"&amp;gt;
   &amp;lt;use data-href="/o/theme-name/images/lexicon/icons.svg#times"&amp;gt;&amp;lt;/use&amp;gt;
&amp;lt;/svg&amp;gt; &lt;/code&gt;&lt;/pre&gt;&lt;br&gt;Why?&lt;br&gt;&lt;br&gt;Thanks.&lt;br&gt;Francesco&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Francesco Cardinale</dc:creator>
    <dc:date>2019-02-18T14:15:29Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to use svg icons in web content</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112297196" />
    <author>
      <name>Patrick Yeo</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112297196</id>
    <updated>2019-02-11T20:55:21Z</updated>
    <published>2019-02-11T20:55:21Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hey Francesco,&lt;br&gt;&lt;br&gt;The reason the use tag is disappearing is because of svg4everybody. The path to your svg sprite is wrong in the context of a Web Content portlet. Svg4everybody tries to find the svg sprite relative to the path specified and can't find it so it returns nothing.&lt;br&gt;&lt;br&gt;You need to find the proper path to the theme's images directory. It looks like we have access to the themeDisplay object in a Web Content in 7.1. You can create a specific template and structure for SVG icons and pass in the partial path and icon name. You can then reuse it in your other Web Content structure and templates.&lt;br&gt;​​​​​​​&lt;br&gt;&lt;pre&gt;&lt;code&gt;&amp;lt;svg class="icon"&amp;gt;
    &amp;lt;use xlink:href="${themeDisplay.getPathThemeImages()}/svg/sprite.svg#icona1"&amp;gt;&amp;lt;/use&amp;gt;
&amp;lt;/svg&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;Unfortunately, I can't figure out a reliable way to use it with Basic Web Content. If you want to use Basic Web content I suggest directly inlining the SVG at this point.&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Patrick Yeo</dc:creator>
    <dc:date>2019-02-11T20:55:21Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to use svg icons in web content</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112295009" />
    <author>
      <name>Byran Zaugg</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112295009</id>
    <updated>2019-02-11T19:23:21Z</updated>
    <published>2019-02-11T19:23:21Z</published>
    <summary type="html">Answered on &lt;a href="https://stackoverflow.com/a/54632779/218161"&gt;Stackoverflow&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I&amp;#39;ll also add, These are WYSIWYG Editors, not HTML editors. Source really shouldn&amp;#39;t be edited manually. Source View is only there for convenience.&lt;br /&gt;&lt;br /&gt;If you want explicit markup, use a &lt;a href="https://dev.liferay.com/en/discover/portal/-/knowledge_base/7-0/web-content-structures-and-templates"&gt;Web Content Structure&lt;/a&gt;.</summary>
    <dc:creator>Byran Zaugg</dc:creator>
    <dc:date>2019-02-11T19:23:21Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to use svg icons in web content</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112280155" />
    <author>
      <name>Francesco Cardinale</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112280155</id>
    <updated>2019-02-08T14:42:23Z</updated>
    <published>2019-02-08T14:42:23Z</published>
    <summary type="html">&lt;blockquote&gt;Olaf Kock&lt;blockquote&gt;Francesco Cardinale&lt;br /&gt;&lt;br /&gt;I use liferay 7.1 (ga2) and I&amp;#39;m developing a theme (with &lt;em&gt;theme generator&lt;/em&gt;).&lt;br /&gt;&lt;/blockquote&gt;&lt;a href="https://stackoverflow.com/questions/54570682/how-to-use-svg-icons-in-a-web-content-of-liferay"&gt;crossposted.&lt;/a&gt; Don&amp;#39;t &lt;a href="http://meta.stackexchange.com/questions/141823/why-is-cross-posting-wrong-on-an-external-site"&gt;do that&lt;/a&gt;, please&lt;/blockquote&gt;Ok, sorry.&lt;br /&gt;But why does the &amp;#39;use&amp;#39; tag disappear when I save?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;How can I solve the problem?&lt;br /&gt;​​​​​​​Thanks</summary>
    <dc:creator>Francesco Cardinale</dc:creator>
    <dc:date>2019-02-08T14:42:23Z</dc:date>
  </entry>
  <entry>
    <title>RE: How to use svg icons in web content</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112270720" />
    <author>
      <name>Olaf Kock</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112270720</id>
    <updated>2019-02-08T06:00:07Z</updated>
    <published>2019-02-08T06:00:07Z</published>
    <summary type="html">&lt;blockquote&gt;Francesco Cardinale&lt;br /&gt;&lt;br /&gt;I use liferay 7.1 (ga2) and I&amp;#39;m developing a theme (with &lt;em&gt;theme generator&lt;/em&gt;).&lt;br /&gt;&lt;/blockquote&gt;&lt;a href="https://stackoverflow.com/questions/54570682/how-to-use-svg-icons-in-a-web-content-of-liferay"&gt;crossposted.&lt;/a&gt; Don&amp;#39;t &lt;a href="http://meta.stackexchange.com/questions/141823/why-is-cross-posting-wrong-on-an-external-site"&gt;do that&lt;/a&gt;, please</summary>
    <dc:creator>Olaf Kock</dc:creator>
    <dc:date>2019-02-08T06:00:07Z</dc:date>
  </entry>
  <entry>
    <title>How to use svg icons in web content</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112258952" />
    <author>
      <name>Francesco Cardinale</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=112258952</id>
    <updated>2019-02-07T09:40:59Z</updated>
    <published>2019-02-07T09:40:59Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hello,&lt;br&gt;&lt;br&gt;I use liferay 7.1 (ga2) and I'm developing a theme (with &lt;em&gt;theme generator&lt;/em&gt;).&lt;br&gt;&lt;br&gt;I added a directory images (in / src), containing a &lt;strong&gt;svg &lt;/strong&gt;directory which in turn contains (a sprite) svg icons.&lt;br&gt;&lt;br&gt;In a web content, I would like to invoke these svg icons, for example with the HTML statement:&lt;pre&gt;&lt;code&gt;&amp;lt;svg class="icon"&amp;gt;
   &amp;lt;use xlink:href="./images/svg/sprite.svg#icona1"&amp;gt;&amp;lt;/use&amp;gt;
&amp;lt;/svg&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;I tried different path (&lt;em&gt;href&lt;/em&gt;). The main problem is that as soon as I save the web content, Liferay automatically translates the previous code into:&lt;pre&gt;&lt;code&gt;&amp;lt;svg class="icon"&amp;gt;
&amp;lt;/svg&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;Therefore, the part relative to the path ('use' tag) is deleted.&lt;br&gt;&lt;br&gt;Why?&lt;br&gt;What should I do to include svg icons in a web content?&lt;br&gt;&lt;br&gt;Thank you&lt;br&gt;​​​​​​​Francesco&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Francesco Cardinale</dc:creator>
    <dc:date>2019-02-07T09:40:59Z</dc:date>
  </entry>
</feed>
