HTML Best Practices: Classes & IDs

Austin Songer
1 min readJan 23, 2017

In order to create more maintainable projects, developers should use classes for CSS and IDs for JavaScript. Separating concerns allows markup to be more flexible without risking breaking both styles and any JavaScript that may be attached to the element on which someone is working.

When using JavaScript to target specific elements in your markup, prefix the ID of the element that is being targeted with js-. This indicates the element is being targeted by JavaScript for your future self as well as other developers that may work on the project.

Example:

<nav id="js-primary-menu" class="primary-menu"></nav>

Avoid using inline styles or JavaScript

--

--

Austin Songer

Trusted Veteran | Compassionate. Aspiring. Resourceful.