Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use the same id once for multiple html page?

Tags:

html

I understand the concept of one id in an html page. As a noob, i was just wondering if you can use the same id once for different html pages. Will that be consider sloppy?

For instance, <div id="1"></div> (used only once)in index.html and used <div id="1"></div> again in product.html. Is that consider bad?

I tried to do a search but found no answers. Thank you!

!edit! Thank you for the answer guys. Appreciated!

like image 755
stanley1943 Avatar asked Aug 16 '13 07:08

stanley1943


1 Answers

An id should only be used once on a single document. It is used for elements that only should appear once on the page anyway (think of a "top navigation bar"). Classes are used for elements that can appear more than once (think of a "particularly styled table", a "repeatable block of information" or things that share particular charasteristics such as "on this browser width this block spans 6 columns" in for example bootstrap). It is perfectly normal to use the same id on different pages. Usually you'll make a skeleton/template for your layout, where each element will be styled the same on each page that uses this template. It is then helpful to have the same id for the same element across different pages. (or: It would be considered sloppy to change the layout of the page on every page, using different id's for each element, as it would be hard or impossible to maintain your pages.)

like image 184
Sumurai8 Avatar answered Oct 09 '22 14:10

Sumurai8