title: SVG in HTML5 – when is XML declaration `<?xml version="1.0" encoding="UTF-8"?>` needed?
body: <p>When using SVG within HTML5: Is the XML declaration <code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</code> needed with SVG </p>
  
  <ul>
  <li>as images via <code>&lt;img&gt;</code> or</li>
  <li>as CSS <code>background-image</code>s?</li>
  </ul>
  
  <p>This is slightly related to “<a href="https://stackoverflow.com/questions/18467982/are-svg-parameters-such-as-xmlns-and-version-needed">Are SVG parameters such as 'xmlns' and 'version' needed</a>”. The namespaces issues are clarified <em>as necessary</em> by the two answers and the <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Namespaces_Crash_Course" rel="noreferrer">MDN Namespace crash course</a>.</p>
  
  <p>But SVG 1.1 doesn't include statement on necessity of XML declaration or when it could be left out?</p>
  
  <p>Example without declaration:</p>
  
  <pre><code>&lt;svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200"&gt;
    &lt;circle id="circle--red" cx="30" cy="30" r="30" fill="#f00"/&gt;
  &lt;/svg&gt;
  </code></pre>
  
  <p><em>Update 2016-07-04</em>: Clarified that question is about <em>XML declaration</em>. Thanks @Martin Honnen!
  <em>Update 2017-10-24</em>: Changed to <a href="https://stackoverflow.com/questions/3251954/xml-file-encoding-format-utf-8-vs-utf-8">“UTF-8“ uppercase</a> and SVGO optimized attribute order. </p>