<marquee> 是走馬燈/跑馬燈的原始寫法,並不屬於 HTML 3.2 規範,早期只有 IE 內核支援,因此在 Netscape 等非 IE 瀏覽器上可能看不到效果。它是個容器標籤,最基本的語法就是:
<marquee><font size="+3" color="red">Hello, World</font></marquee>
它的特色是不需要寫 CSS,也能做出滾動公告。搭配 table 排版,就是一段最樸素的站內公告:
<table border="1" width="206" cellspacing="0" cellpadding="0" height="90">
<tr>
<td valign="top">
<marquee direction="up" height="99%" scrollAmount="1" scrollDelay="100"
onmouseover="this.stop()" onmouseout="this.start()">
· 歡迎您光臨!<br>
· 本站提供大量範例程式碼<br>
· 如有建議歡迎回饋
</marquee>
</td>
</tr>
</table>
<marquee onmouseover="this.stop()" onmouseout="this.start()">
滑鼠移入暫停,移出繼續滾動
</marquee>
滾動中的文字會干擾閱讀與點擊,因此「移入暫停、移出恢復」幾乎是必寫的組合。
<marquee id="affiche" behavior="scroll" direction="up"
bgcolor="#FF0000" width="200" height="300"
hspace="50" vspace="20" loop="-1"
scrollamount="10" scrolldelay="100"
onmouseover="this.stop()" onmouseout="this.start()">
這是一個完整的例子
</marquee>
bgcolor="red"。舉例來說,loop="2" 只滾兩次就停,scrollamount="10" 到 30 則是明顯的速度階梯。
marquee 已被 HTML 規範標記為 deprecated 並陸續從現代瀏覽器移除,加上它對螢幕閱讀器不友善、也容易違反 WCAG 對自動更新內容的要求。新專案若需要跑馬燈效果,建議改用 CSS @keyframes 搭配 transform:translateX() 實作,並記得加上 prefers-reduced-motion 媒體查詢,尊重使用者關閉動效的偏好。