Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML semantics and styling

Tags:

html

css

My question is this – is it still best practice to use certain HTML tags even if you would then need to style them differently to how a browser interprets and displays those tags?

For example – the HTML5 <blockquote> tag will start on its own line, with default margin and padding, and with an indent.

However – if you do not wish there to be an indent, should you still use the <blockquote> tags in order to convey meaning to the browser and search engine, and then apply CSS to reduce/rid the indent, or should you just use a <p> tag for example?

It’s not much effort to restyle the blockquote element, and I assume that it is important to use the tags that most accurately convey the meaning of their contents, but at the same time I do not want to get into a habit of writing extra code if it is considered best practice not to do so.

like image 416
DJC Avatar asked Apr 23 '14 11:04

DJC


3 Answers

I assume that it is important to use the tags that most accurately convey the meaning of their contents

You assume correctly.

I would say yes, absolutely always try to use the appropriate element for the type of content/purpose you intend. Elements have names/designations for a reason, so your code can be structured in a way that makes semantic sense. Why is this important? Well ignoring SEO for which it plays an important part, or ease of access regarding your code, this is the intended design of HTML.

Not using a specific element because it has default styling applied is not a sensible or really logical course of action in this context. This is especially in light of the fact that when you compare browser-specific styling, most elements may have default styles applied.

I do not want to get into a habit of writing extra code if it is considered best practice not to do so

Bad practice to some degree is subjective, otherwise it is simply right or wrong- in this case it wont be game breaking to not use the correct tags, however you will be going against their intended use according to specification, so it would most certainly be bad practice.

See:

  1. Semantic HTML (Wikipedia)
  2. Semantic Web (Wikipedia)
like image 183
SW4 Avatar answered Nov 08 '22 04:11

SW4


Yes, use the tags which are most aligned with the semantics of your content. Don't concern yourself with styling when constructing your HTML doc, as you could have different styles for different resolutions (smartphone, tablet, desktop) or even different mediums (web browser, screen reader, braille display, whatever device come out in the future...)

The following talks about class names specifically, but it does drive home the importance of semantic correctness:

ref: http://www.w3.org/QA/Tips/goodclassnames

like image 1
Mister Epic Avatar answered Nov 08 '22 06:11

Mister Epic


HTML5 gives us many new elements to describe parts of a Web page, such as header, footer, nav, section, article, aside and so on. These exist because we Web developers actually wanted such semantics. How did the authors of the HTML5 specification know this? Because in 2005 Google analyzed 1 billion pages to see what authors were using as class names on divs and other elements. More recently, in 2008, Opera MAMA analyzed 3 million URLs to see the top class names and top IDs used in the wild. These analyses revealed that authors wanted to mark up these areas of the page but had no elements to do so, other than the humble and generic div, to which they then added descriptive classes and IDs. (HTML5 Doctor has many articles about HTML5 semantics.)

Read

like image 1
4dgaurav Avatar answered Nov 08 '22 05:11

4dgaurav