Why are dashes preferred for CSS selectors / HTML attributes?

后端 未结 6 1773
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 00:07

In the past I\'ve always used underscores for defining class and id attributes in HTML. Over the last few years I changed over to dashes, mostly to align m

6条回答
  •  误落风尘
    2020-11-28 01:11

    There's been a clear uptick in hyphen-separated, whole-word segments of URLs over recent years. This is encouraged by SEO best practices. Google explicitly "recommend that you use hyphens (-) instead of underscores (_) in your URLs": http://www.google.com/support/webmasters/bin/answer.py?answer=76329.

    As noted, different conventions have prevailed at different times in different contexts, but they typically are not a formal part of any protocol or framework.

    My hypothesis, then, is that Google's position anchors this pattern within one key context (SEO), and the trend to use this pattern in class, id, and attribute names is simply the herd moving slowly in this general direction.

提交回复
热议问题