Skip to content

Instantly share code, notes, and snippets.

@acidtone
Last active April 14, 2024 12:43
Show Gist options
  • Save acidtone/ea248e3207b06cfdf861bdec06816fb9 to your computer and use it in GitHub Desktop.
Save acidtone/ea248e3207b06cfdf861bdec06816fb9 to your computer and use it in GitHub Desktop.
SVG: Getting started

SVG - Getting started

Background

Key Takeaways

  • Vector logos look sharp at all zoom levels.
  • SVG files (the open vector file format) are generally smaller in file size compared to raster images.
  • Inline SVGs can be styled and animated with CSS.
  • SVGs are part of the DOM, which can be accessed and controlled using Javascript.
  • Complex SVGs may impact performance due to processor load.

Tips and Tricks

  • When in doubt, remove the width and height attributes to make your SVG responsive. This will make the SVG 100% of the width of its container.
  • The xmlns attribute is not needed for inline SVGs but should be included in case you want to link externally as an img element or background-image.
  • The version="1.1" attribute should always be removed.
  • CSS styles and effects such as stroke cannot leave the boundaries of an svg element.If this happens it's usually easier to expand your viewBox in your vector editor.
  • Optimize your inline SVGs with SVG OMG to make sure it's web-ready.
    • Most of the defaults are fine.
    • Prettify the code, if desired. It won’t add a lot to file size.
    • width and height attributes will be removed by default (this is good).
    • A lower precision will result in a smaller file size but very low values might affect the detail of your designs.
    • See Understanding and Manually Improving SVG Optimization for more information than you probably need.

Tools

Attributions

Related Gists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment