HTML5 帶來了不少有趣的新能力,以下幾項最為常用:
除了 Canvas,SVG 也是 HTML5 生態中相當強大的向量繪圖方案。SVG 以 XML 描述圖形,最大的優點是無論放大到多倍都不會失真。下面就用 SVG 來手繪一個微信風格的雙對話泡泡 Logo。

先用一個容器包住 SVG,並透過 object 標籤把外部的 logo.svg 嵌進來。這段是 HTML 文件的內容:
<style>
* { padding: 0; margin: 0; }
body { background-color: #ddd; }
.container {
width: 300px;
height: 300px;
position: relative;
top: 50px;
left: 50%;
transform: translate(-50%, 0);
background-color: #c4e9c8;
border-radius: 30px;
box-shadow: 5px 5px #cbfbf;
}
.container object {
position: relative;
top: 30px;
left: 30px;
}
</style>
<body>
<div class="container">
<object data="logo.svg" width="240" height="240" type="image/svg+xml" />
</div>
</body>
這個 logo.svg 是獨立於 HTML 之外的 XML 檔,用橢圓、圓、多邊形等基本圖形拼出兩個對話泡泡與裡面的兩個小圓點:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"https://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" version="1.1" xmlns="https://www.w3.org/2000/svg">
<ellipse cx="120" cy="90" rx="90" ry="70"
style="fill:rgb(149,222,150);stroke:rgb(149,222,150);stroke-width:2;"/>
<circle cx="90" cy="85" r="8" style="fill:#c4e9c8;stroke:#c4e9c8;stroke-width:1;"/>
<circle cx="130" cy="85" r="8" style="fill:#c4e9c8;stroke:#c4e9c8;stroke-width:1;"/>
<polygon points="90,150 110,150 100,170" style="fill:#c4e9c8;stroke:#c4e9c8;stroke-width:1;"/>
<ellipse cx="170" cy="170" rx="70" ry="55"
style="fill:#c4e9c8;stroke:#c4e9c8;stroke-width:2;"/>
<ellipse cx="170" cy="170" rx="70" ry="55"
style="fill:rgb(149,222,150);stroke:rgb(149,222,150);stroke-width:2;"/>
<circle cx="145" cy="165" r="7" style="fill:#c4e9c8;stroke:#c4e9c8;stroke-width:1;"/>
<circle cx="180" cy="165" r="7" style="fill:#c4e9c8;stroke:#c4e9c8;stroke-width:1;"/>
<polygon points="150,215 185,215 168,235" style="fill:#fff;stroke:#fff;stroke-width:1;"/>
</svg>
把這兩個檔案放在同一個目錄下,用瀏覽器打開 HTML,就能看到用純向量繪製、可任意縮放都不失真的微信風格 Logo 了。這個範例也示範了 HTML5 時代「結構(HTML)、樣式(CSS)、圖形(SVG)」各司其職、彼此分離的良好實務。