If only you could write every single line of code in your next project, you’re certain it would be the cleanest, most maintainable website on the Internet! But websites are rarely the sole products of front-end developers, and in any project that involves a lot of programmatic heavy-lifting it can be a struggle to instill an appreciation for the benefits of a quality front-end codebase on even the most quality-conscious server-side programmers. Too often, what at first seems a minor instance of HTML semantics actually involves quite a number of implications beyond what’s evident to most people (including management and operations departments) in most projects.
Although practically speaking
div
and span
elements are both intended to be meaningless, there is a subtle difference. This is not only in that the browser’s default styling of these elements is different but also, and arguably more importantly, the implications of logical grouping on a contextual basis.The W3C says:
Thediv
andspan
elements, in conjunction with theid
andclass
attributes, offer a generic mechanism for adding structure to documents. These elements define content to be inline (span
) or block-level (div
) but impose no other presentational idioms on the content. Thus, authors may use these elements in conjunction with style sheets, thelang
attribute, etc., to tailor HTML to their own needs and tastes.
At first blush these may seem to be the same, but take a closer look at the wording:
these elements define content to be inline (.span
) or block-level (div
)
In other words, the content itself suggests the appropriate element. Since the entire help note is logically a single sentence and is only intended to be split up onto multiple lines when styling is applied (and presumably not in, say, a text-only representation of the content since that would be weird for sentence structure), then a
span
element is the only one of these two that’s appropriate.
No comments:
Post a Comment