create account

HTML Semantic Elements, or Div? by gibic

View this thread on: hive.blogpeakd.comecency.com
· @gibic ·
$9.57
HTML Semantic Elements, or Div?
I still remember doing some web layout using tables. Life was rough back then. But since CSS framework such as Bootstrap became so popular, div tags were widely used for styling element. Everything was wrapped inside a div. Then HTML 5 made an entrance. Now we have semantic elements, tags that clearly describes its meaning to both the browser and the developer.

I'd put the emphasis on the 'meaning' part.

Sure we can always just use div and it will rendered just fine in the browser. But what about code readability? Can machine read it too as those elements were intended to behave? It's a common thing when developers were to have difference perception on their naming convention. So why wouldn't we use a good standard for web elements?

[We can learn about the basic element here](https://www.w3schools.com/html/html5_semantic_elements.asp). It's really not that hard.

### Practical Use

An example: we write our navigation links using the `<ul><li>` tags, which is correct, since it is a list of links. But for the styling purpose, we wrapped it inside a div tag. Our human eyes can easily perceive these links as a navigation list. But machines are dumb. They wouldn't find the difference of these links with another `<a>` tags on our page.

How about we wrapped the navigation list inside a proper `<nav>` tag? Machine will immediately recognize it. And so does a screen reader. Thus, it will be a great help for the web accessibility too.


![carbon1.png](https://files.peakd.com/file/peakd-hive/gibic/XvoTbiP2-carbon-1.png)

Same story goes to the `<main>` tag, as we could easily guess, this tag will wrapped the most important part of our web page. The main course. A good practice for web page is to provide the 'skip to main' navigation link when a person hit the tab key on their keyboard. Without providing the proper `<main>` tag, this nice accessibility feature would be hard to achieve.

Seeing so many tags and thinking what tag to use for specific meaning could be overwhelming sometimes. What is `<article>`, what is `<section>` ? Should we use section inside article, or vice-versa? (short answer, we can do both). Not to mention, there are roughly 100 semantic elements available.

When you got too tired of these semantic things, try to keep things simple. Don't go overthinking about the tag elements. Just enjoy the process, but make sure to make your works meaningful.
***

Further reads:

- [Semantic HTML5 Elements Explained](https://www.freecodecamp.org/news/semantic-html5-elements/)
- [Let’s Talk about Semantics](http://html5doctor.com/lets-talk-about-semantics/)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 581 others
properties (23)
authorgibic
permlinkhtml-semantic-elements-or-div
categorywebdev
json_metadata"{"app":"peakd/2021.01.3","format":"markdown","description":"Everything was wrapped inside a div. Then HTML 5 made an entrance.","tags":["webdev","frontend","technology","life","code"],"links":["https://www.w3schools.com/html/html5_semantic_elements.asp","https://www.freecodecamp.org/news/semantic-html5-elements/","http://html5doctor.com/lets-talk-about-semantics/"],"image":["https://files.peakd.com/file/peakd-hive/gibic/XvoTbiP2-carbon-1.png"]}"
created2021-02-28 19:26:24
last_update2021-02-28 19:26:24
depth0
children0
last_payout2021-03-07 19:26:24
cashout_time1969-12-31 23:59:59
total_payout_value4.853 HBD
curator_payout_value4.713 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,603
author_reputation15,626,232,883,019
root_title"HTML Semantic Elements, or Div?"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id102,113,971
net_rshares21,637,778,502,216
author_curate_reward""
vote details (645)