For most website logos and simple illustrations, use SVG through an HTML <img> element, give it meaningful alternative text when it conveys information, and size it with responsive CSS. Use inline SVG only when the page needs to style or interact with internal elements. Keep the file simple, trusted, and tested at its real display sizes.
First confirm that the SVG contains the structure you expect. A PNG2SVG Lossless file embeds a PNG, while True vector output contains traced paths. Both can display in a browser, but only the path-based result provides resolution-independent artwork.
Choose <img> or inline SVG
An external SVG used through <img> behaves much like another image asset:
<img src="/images/company-mark.svg" alt="Company name" width="240" height="80" /> This is usually the simplest choice. The browser can request and cache the file, the HTML alt attribute supplies its text alternative, and the SVG’s internal markup does not become part of the page DOM.
Inline SVG places the <svg> markup directly in the HTML. It is useful when CSS must recolor individual paths, JavaScript must interact with elements, or a complex graphic needs internal accessibility structure. It also increases the amount of markup in the page and requires careful sanitization when the source is not fully controlled.
CSS background images can use SVG for decorative artwork, but they do not provide an HTML alt attribute. Do not use a background image for information that users need to understand.
MDN’s SVG-as-an-image guide documents the contexts where browsers treat SVG as an image and the restrictions those contexts apply.
Keep a useful viewBox
The viewBox defines the SVG’s internal coordinate system. It lets a browser scale the artwork into different displayed sizes while preserving its geometry.
PNG2SVG adds a viewBox and responsive dimensions to its output. If you edit or optimize the file, confirm that those attributes remain correct. A mismatched viewBox can crop artwork, leave excessive empty space, or make a graphic appear missing.
Include intrinsic width and height in the HTML or CSS layout when possible. This helps the browser reserve space before the image loads and reduces layout movement.
Make SVG responsive without distortion
A common pattern is:
.site-logo {
display: block;
width: min(12rem, 100%);
height: auto;
} The browser calculates the height from the aspect ratio. Avoid setting unrelated fixed width and height values that stretch the image. Test narrow containers, high-density screens, zoom, and the largest real display size.
A vector path remains sharp when scaled, but small-size design still matters. Fine lines and tightly spaced details may become visually unclear even when they are technically crisp. Consider a simplified small-size brand variant where appropriate.
Write the correct text alternative
For an informative SVG used with <img>, write an alt value that communicates its purpose in context. A company logo linked to the homepage may use the company name. A diagram needs a short identification plus nearby text or a longer description that conveys its information.
For a purely decorative image, use alt="" so assistive technology can ignore it. Do not repeat adjacent text unnecessarily.
Inline SVG does not use an alt attribute. It can use accessible naming through appropriate SVG and ARIA techniques, such as a title connected to the graphic. Complex interactive or data-rich SVG requires more careful design and testing than a decorative icon. W3C’s image accessibility resources explain how purpose affects alternative text.
Keep performance proportional to the artwork
SVG is not always smaller or faster than raster. A simple icon may contain only a few paths and compress well. A traced photograph can contain thousands of paths that the browser must parse, style, and render.
Measure:
- the transferred file size after server compression;
- path and node complexity;
- rendering behavior on representative devices;
- the cost of repeated inline markup; and
- whether animation touches many elements.
For repeated icons or logos, an external cached asset can be more efficient than duplicating the complete inline markup on every page. For a detailed photograph, an optimized photographic format is usually more appropriate than a trace.
If a conversion produces excessive geometry, use SVG File Too Large After Conversion before deployment.
Understand Lossless output on the web
Lossless mode creates a responsive SVG container but the embedded image still has fixed raster detail. It can preserve exact appearance, yet it may be larger than serving the original PNG directly.
Use it only when the SVG wrapper solves a real compatibility or layout requirement. If the site supports PNG and the content is photographic or textured, compare the original raster asset’s size and quality.
True vector mode is more suitable for a clean logo or icon, provided the trace is accurate and not unnecessarily complex.
Use trusted and sanitized SVG
SVG is XML-based markup and supports more features than a passive bitmap. Do not paste unknown inline SVG into a page without review. When users or external systems can provide SVG, apply the framework or platform’s established sanitization and Content Security Policy controls.
An <img> context restricts some active and external features, but it is not a reason to ignore source trust. Keep dependencies self-contained, remove unneeded editor content carefully, and do not weaken security controls to accommodate an unknown file.
Test the real deployment
Before release:
- load the production URL directly and confirm the server returns the SVG;
- check the image at phone, tablet, and desktop widths;
- test browser zoom and high-contrast backgrounds;
- confirm alternative text with accessibility inspection tools;
- review layout movement and loading performance;
- verify the Content Security Policy and sanitizer behavior; and
- keep a PNG fallback where a required destination lacks SVG support.
If the file appears blank, cropped, or blocked, follow SVG Not Displaying or Uploading?. To create a path-based website asset, open PNG2SVG, choose True vector, and test the downloaded file at the exact sizes used by the site.