Div vs li when to use them

Hi, I have about six months of experience in web development. I have the following observation, I often use tags <div>, this gives me the opportunity to position elements, archive elements, and it seems that I can use tags <div>to do everything just by playing with my display property.

I have never had to use elements <ul>or <li>in combination, except for navigating the horizontal menu, and I'm not sure why you cannot do this with the elements <div>, but it seems to be an “agreement” to achieve a horizontal menu.

Did I miss something? Are there some properties that have elements <li>that are better or more useful than elements <div>?

Please do not limit this question only to the horizontal menu list; I want to know any scenario in which you would use <li>on something else.

+5
source share
4 answers

Yes, you can do anything (more or less) strictly with div tags (with exceptions such as shapes and inputs and images and what not). But that is not the point.

First, css is used by default for certain tags. For example, you have bullets. You can change them, but in many situations it is simply easier to use a tag that has the style you are looking for.

- , " ", , . li , , , CSS (, ), .

+7

. HTML , .

A <ul> - . , , .

A <div> - , . , , <div> , <ul>, .

<div>, list :

<div role="list">
    <div role="listitem">...content...</div>
    <div role="listitem">...content...</div>
    <div role="listitem">...content...</div>
</div>

WAI-ARIA , :

<ul>
    <li>...content...</li>
    <li>...content...</li>
    <li>...content...</li>
</ul>
+3

HTML- . div , . ul/li , .

HTML5 : , , , . , , , div, .

+1

All Articles