Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML - Container id or class

Tags:

html

standards

When writing HTML, what is the industry standard regarding a Container div?
Is it more popular to have a Container id, or use a container class which I add to the divs I wish to inherit the features?

For example:

<body>
    <div id="container">
       ...etc
    </div>
</body>

or

<body>
    <div id="main" class="container">
        ...etc
    </div>
</body>
like image 203
SmokingKipper Avatar asked Jan 16 '26 22:01

SmokingKipper


2 Answers

I don't know that there is an industry standard. If it's a container, you should have only one so an ID makes sense. You can use classes and IDs however you see fit, the bigger challenge is having cleanly-written, well-stacking rules that apply to the design you're working with.

Edit: Your question just updated -- it'd be better to have id="container" and then class="home", class="about", etc. as needed. This would make for a neater stylesheet and would give you the option of simply overwriting #container rules if you need to.

like image 177
Matt Stein Avatar answered Jan 19 '26 17:01

Matt Stein


Setting an id of container would be most appropriate because you should only have one container. Setting the class = container would imply that more than one container existed. Since a container is designed to wrap all of your page content you should only have 1.

like image 23
Kevin Bowersox Avatar answered Jan 19 '26 15:01

Kevin Bowersox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!