Use a <div> when you need to divide (what a div should be used for) sections of your page apart. Header of content, for example, or individual blog posts.
However, you should not use them if another element semantically makes sense.
If the archive in the blog mentioned earlier showed only two lines in each message in the archive, an ordered list may make more sense, because you define a list of elements that are in order. <li> elements are also block elements and can be written in exactly the same way.
Sometimes, it makes sense to have nested <div> tags, and sometimes itβs not necessary.
As a basic test, imagine that your page is being analyzed by a reader for a visually impaired user. He needs to know what is in each node document so that it can declare it correctly. No matter what you need for visual CSS, it just wants to parse it as accurately as possible in speech.
Key points to remember:
- Write your HTML primarily for a non-visual structure.
- The person viewing your site may not use your CSS
- A person browsing your site may not use a normal web browser.
- You can always customize your structure if CSS is not working as it remains the same semantically.
Lex R
source share