Can we place `<img>` inside `<h1>` according to web standards?

有些话、适合烂在心里 提交于 2019-11-27 19:35:00

Yes, you can - the DTD says:

<!ELEMENT h1  %Inline;>
<!ENTITY % Inline "(#PCDATA | %inline; | %misc.inline;)*">
<!ENTITY % inline "a | %special; | %fontstyle; | %phrase; | %inline.forms;">
<!ENTITY % special "%special.pre; | object | img ">

That basically means h1 can contain %Inline, which is made of various things, including img

Look who is using it: http://www.w3.org/

<h1 class="logo"><a tabindex="2" accesskey="1" href="/"><img src="/2008/site/images/logo-w3c-mobile-lg" width="90" height="53" alt="W3C" /></a> <span class="alt-logo">W3C</span></h1>

Yes, this is allowed. But don’t forget to set the alt attribute on the img!

Yes and no.

You can place an image inside an h1 element, but not quite like that … the alt attribute is mandatory.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!