The Great SVG RetCon
A presentation by
Amelia Bellamy-Royds
(@AmeliasBrain)
at
Exchange.js
(Edmonton, 6 October 2016)
These slides: ameliabr.github.io/great-svg-retcon
Retroactive: Because sometimes you need to fix the past.
Back to the FutureRetCon-ing the Web
Markup
Stand-alone SVG files are XML!
Use your browser's parser to clean up sloppy HTML markup
(Or just use MS Edge's Save Picture As… option)
Don't use XML prefixes for SVG or HTML elements in HTML markup.
For namespaced attributes, only use:
xlink:href
xml:lang
Clean up extra XML bloat before pasting into HTML!
Namespaces always matter when scripting!
(xmlns
attribute doesn't, though)
But, innerHTML
triggers the parser.
Links
href
attribute to create simple links
href
attribute to create Sorry…
from @iAmRyanYu, after SVG 2 publication in SeptemberYes: MS Edge & Internet Explorer (all versions!), Chrome 50+, Firefox 51+ (Nightly / Dev Editions)
No: Safari, Firefox ≤ 50
Test it yourself: codepen.io/AmeliaBR/full/MKRqBE/SVG 2 also makes xml
prefix optional for lang
attribute.
Supported: Chrome, Firefox, & Safari (most versions in common use)
No: MS Edge & Internet Explorer
Test it yourself: codepen.io/AmeliaBR/pen/jrkWZZStyles
Any supported CSS syntax should be supported in SVG.
Geometry
Changing geometry changes the drawing.
Changing styles just adds a little flair…
But… attributes ≠ styles
Same attribute names, on different elements, with different effects:
Same attribute names, on different elements, with different defaults:
Property | Elements with presentation attribute | Elements with ordinary attribute only |
---|---|---|
width | rect, image, foreignObject, svg, symbol, use | pattern, mask, filter, and filter effect (fe*) elements |
height | ||
x | All above, plus text, tspan, hatch, meshgradient, cursor | |
y | ||
cx | circle, ellipse | radialGradient |
cy | ||
r | circle | |
rx | ellipse, rect | (none) |
ry | ||
d | path | hatchpath |
Transforms
transform
attribute
transform
and transform-origin
transform
presentation attribute
SVG layout, & SVG transforms, are based on a coordinate system.
CSS doesn't always have a coordinate system.
For an off-center shape in a centered SVG coordinate system…
You get different transform-box sizes and different box origins:
transform
, transform-origin
and transform-box
transform
presentation attribute
SVG 1.1 | CSS Transforms |
---|---|
translate( 16, 0 ) | translate( 16px, 0 ) |
translate( 12pt, 0 ) | |
translateX( 16px ) | |
rotate( 90 ) | rotate( 90deg ) |
rotate( 0.25turn ) | |
rotateZ( 90deg ) | |
scale( 2 ) | scale( 2 ) |
scale( 1, -1 ) | scaleY( -1 ) |
3D Transforms are fun! (but very buggy)
Fallback layout uses the transform
attribute:
There's much more…
paint-order
(good support) andz-index
(no support)- CSS-crossover graphical effects (filters, masking, clip-paths)
- Blend modes instead of filters
- Wrapping text in a shape!
- SVG-in-OpenType fonts (old SVG Fonts are dead)
- Proper keyboard support
- Better accessibility guidance
- Unified approach to Web Animations, CSS or SMIL-like elements (not completely dead)
- Overhauled SVG DOM. Many features removed. Replacements pending…
- New paint servers: mesh gradients and hatches
- Context paint, to coordinate line markers and multi-shape icons
- Coming soon: SVG paint servers for CSS elements, filled & stroked CSS text, CSS images and multiple layers for SVG fill & stroke