Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) Making Changes to the DOM Getting and Setting Text with textContent and innerHTML

A question about HTML

When do we use class, type, id, etc in html. Whats the difference between them and when should i be using them?

Just curious, Thank you

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Liam,

When you're working with HTML, the terms you're asking about are used as attributes to HTML elements. Here's an example.

<p class ="" id="" name=""></p>

<input type="" name="" id="" class="" />

We have 2 elements here. An input element and a paragraph element.

Let's start with the input element because this has the unique (to this code) `type attribute.

Type refers to the type of input element used. Input elements are used with the form element and maker up form controls in a HTML form. So you could have an text box, radio and checkbox form elements, as well as using the submit attribute to make form buttons.

The name attribute allows you to provide a name for your HTML element. For form elements you also use it with the label attribute to link a label with a form element.

Class and ID elements are important attributes. You can use them with JavaScript and CSS to make them selectable so you can do things with them, whether it be changing its location in the DOM tree or changing it's appearance with CSS.

You can use the same class element multiple times but can only use a given ID one time only..

Hope this helps!