+ 4

What is the use of 'id' and 'class' tag???

Plzzz someone explain me in simple words

17th Nov 2020, 11:40 AM
Mohammad Danish
16 Respuestas
+ 4
If you are creating 12 buttons, and the first 4 should have a red background, other 4 should have a green background, and the remaining four should have a yellow background, you would give a class of your own choice to each button that you wanna style, so i would give the first four buttons a class of "red-button", and inside css, i can grab these 4 buttons with a single class, and give it some styles, which would apply to each button with that class. .red-button { background-color: red; } Now, if i wanna change the styles of a particular red button, i can give that button an id, lets suppose "different-red-button" #different-red-button { /* some styles */ } Keep in mind, we use dots (.) to grab classes, and # to grab ids.
17th Nov 2020, 12:10 PM
maf
maf - avatar
+ 3
Id's and classes are created for the purpose of identification when it comes to applying a style (CSS) and or adding some behavior (JavaScript) to a particular field, section, or what so ever in the HTML document.
18th Nov 2020, 10:35 AM
Muhammad Tijjani Umar
+ 2
- id is unique for every HTML Tag - id is denoted by #idName - class is may or may not be the same for HTML Tag - class is denoted by .className - ID & Class are use to apply CSS on selected tag using id & class
18th Nov 2020, 4:40 PM
ANJAN KORADIA
ANJAN KORADIA - avatar
+ 2
One Id is use only time. Example: <div id="one"> this is content </div> // this is correct <div id="one"> this is 2nd content </div> // this is an error //single Id is use only one time if you use id in the html document then you need to make multiple id for each tag OR single id use single time in tag But class can use multiple times <div class="one"> this is content </div> // this is correct <div class="one"> this is 2nd content </div> //Here "one" is class and we are using single class in multiple tag
19th Nov 2020, 7:55 AM
Shiv The Human Code
Shiv The Human Code - avatar
+ 1
Mohammad Danish Id and class are an attribute not tag! In Html for an element ID name starts with the “#” symbol followed by a unique name assigned to it. On the other hand class assigned to an element has its name starts with “.” followed by class name. Only one ID selector can be attached to an element. Multiple class selectors can be attached to an element. Hope it helps you. I accept any request.
17th Nov 2020, 11:50 AM
Matias
Matias - avatar
+ 1
Mohammad Danish yeah, giving id or class wont make any difference, UNLESS you have applied some styles on that id or class.
17th Nov 2020, 2:06 PM
maf
maf - avatar
+ 1
Id and class are attributes you can use them in css for example when you have lot of tags with same name , like this <h1> and <h1> you use class or id to distinguish between them
18th Nov 2020, 1:46 PM
HAYTHEM JBELI
HAYTHEM JBELI - avatar
+ 1
They are attributes to value of a variable
18th Nov 2020, 8:15 PM
Ighalo Destiny Aka @destinmedian
Ighalo Destiny Aka @destinmedian - avatar
+ 1
Basically id is used for javascript and the class is used in css .But you can also use it alternatively as your wish but it is convenient to use the first one.
19th Nov 2020, 7:06 AM
Ronak Paul
Ronak Paul - avatar
0
So, basically 'id' & 'class' attributes will not make any change to your HTML file (only html file)???
17th Nov 2020, 12:51 PM
Mohammad Danish
0
Id work as unique but class can use multiple if u want group a set of element class is better Use id in paticular element
18th Nov 2020, 8:07 AM
Ali Zarifi
Ali Zarifi - avatar
0
In html 'id' is for only one tag from which we can style the innerhtml of tag and class can be common for many tags
19th Nov 2020, 5:26 AM
Niteesh
0
Using of id is to make that as unique it will help you to select while doing style and class is similar to id but it is more than that a class may contain many id To define "id" in css we use '#id_name' where as for "class" in css we use '.classname'
19th Nov 2020, 10:01 AM
Life Snatcher
Life Snatcher - avatar
0
id is a unique identifier to the html element, no more than one element can have the same id, whereas class is mainly used for css to apply styles (rules) to multiple elements which are sharing the same class name, both id and class names can be used to trigger events on those elemnts using javascript and so on ...
28th Nov 2020, 11:02 PM
Mustafa