使用语义HTML有什么好处? [英] What are the benefits of using semantic HTML?

查看:103
本文介绍了使用语义HTML有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在性能或其他方面跟随语义HTML有一些明显的结果吗? 感谢

解决方案

与性能无关



语义标记不是关于性能,而是关于性能。



让我们想象两个平行的宇宙。


  • 在Dumb HTML World 中,只有一个标签:< thing> 。你将如何指定应用样式的位置?浏览器如何知道如何渲染页面?盲人屏幕阅读器如何区分标题,文本和脚注以及菜单项?您必须添加各种尴尬的属性。

  • 与此同时,在详细HTML世界中,有大量名称。您有< header> < footer> <文章> 和< caption> < menu> < paragraph> < footnote> 等。现在,您可以智能应用样式,以及任何读取您的内容的程序 - 浏览器,读者,无论 - 可以有适合内容的规则。例如:


    • 我的用户是盲人的,所以我应该宣布有图片,提供阅读相关的标题,并且不打扰下载实际图片数据。

    • 我的用户有一个小屏幕和良好的视力,并要求我将小段落放在一个页面上,以便大量适合页面。

    • 我的用户不关心脚注,也不想看到它们。




真实世界介于这两种情况之间。

语义HTML的某些方面有点理想化,但原则是合理的。例如,使用< strong> 而不是< b> 表示此文本很重要,而不一定这段文字应该是大胆的。也许你的用户希望重要的文字以橙色突出显示。这是由他们决定的。



关键是,HTML是标记,它是关于有用地标记事物。语义HTML是所有HTML应该是的:有用的,有意义的标签。



快速加载网站完全是一个不同的问题。



(另请参阅:我的答案此处)。

我认为随着时间的推移,HTML会变得更加语义化是自然的。

回到愚蠢的HTML世界,他们可能会结束像< thing type ='list'> < thing render ='image'> 。网页编码人员会抱怨,嘿,我们一直这样做,为什么不只是有一个< image> 标签?这会让我们的生活更轻松。



在现实世界中,人们不断编码诸如< div id ='nav'> < div class ='article'> 。因此,创建新元素很有意义,如< nav> <文章> <节> 。这就是草稿HTML5规范会做的事


Are there some noticeable outcomes in terms of performance or other aspects to follow semantic HTML?

Thanks

解决方案

Not about performance

Semantic markup isn't about performance, it's about meaning.

Let's imagine two parallel universes.

  • In Dumb HTML World, there is only one tag: <thing>. How would you specify where styles should be applied? How would browsers know how to render the page? How would screen readers for the blind differentiate between headlines and text and footnotes and menu items? You'd have to add all kinds of awkward attributes.
  • Meanwhile, in Detailed HTML World, there are loads of names. You've got <header> and <footer> and <article> and <caption> and <menu> and <paragraph> and <footnote>, etc. Now you can apply styles intelligently, and any program that reads your content - browsers, screen readers, whatever - can have content-appropriate rules. For example:
    • "My user is blind, so I should announce that there are images, offer to read the associated captions, and not bother downloading the actual image data."
    • "My user has a small screen and good eyesight, and has asked me to make paragraphs small so that lots of them fit on a page."
    • "My user doesn't care about footnotes and never wants to see them."

The real world is somewhere between these two scenarios.

Some aspects of semantic HTML are a bit idealistic, but the principle is sound. For example, using <strong> instead of <b> conveys "this text is important" and not necessarily "this text should be bold." Maybe your user wants important text to be highlighted orange. That's up to them.

The point is, HTML is markup, which is about labeling things usefully. Semantic HTML is what all HTML should be: useful, meaningful labels.

Making your site load quickly is a different question altogether.

(See also: my answer here.)


Addendum - evolving towards semantic HTML

I think it's natural for HTML to become more semantic over time.

Back in Dumb HTML world, they'd probably end up with crazy markup, like <thing type='list'>, and <thing render='image'>. Web coders would complain, "hey, we do this all the time. Why not just have an <image> tag? It would make our lives easier."

In the real world, people are constantly coding things like <div id='nav'> and <div class='article'>. So it makes sense to create new elements, like <nav> and <article> and <section>. Which is what the draft HTML5 specs would do.

这篇关于使用语义HTML有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆