Id & Classes in HTML | Sigma Web Development Course - Tutorial #9

CodeWithHarry
4 Oct 202310:57

Summary

TLDRThis video script clarifies the often-confused concepts of ID and Classes in HTML. It explains that an ID is a unique identifier for a single element, akin to an individual's Aadhar number, while a class can be shared among multiple elements, like students in a class. The script uses relatable analogies and practical examples to demonstrate how to apply IDs and classes in HTML and CSS, highlighting their distinct uses and the importance of understanding their roles in web development.

Takeaways

  • πŸ”‘ ID stands for 'Unique Identifier' and is used to give a unique identity to an HTML element.
  • πŸ“š Classes in HTML are used to assign common styles or attributes to multiple elements and can be shared among different elements.
  • πŸ‘• The analogy of 'Aadhar card' is used to explain the uniqueness of an ID, similar to how each person has a unique identification number.
  • πŸ‘« The concept of 'class' is likened to being in the same grade or group, where multiple people can share the same classification.
  • πŸ“ The script provides a practical example of creating a folder and file for a web development project, emphasizing the organization of code.
  • πŸ’» Demonstration of using 'ID' and 'class' in HTML involves creating elements with these attributes and explaining their purpose.
  • 🎨 In CSS, 'ID' is targeted using a hashtag (#), and 'class' is targeted using a period (.), allowing for specific styling of elements.
  • πŸ”„ The script clarifies that one element can have multiple classes but only one ID, reinforcing the uniqueness of the ID attribute.
  • πŸ”— IDs can also be used for navigation purposes, allowing users to jump to specific sections of a webpage using a direct link.
  • πŸ“ The video also covers the use of IDs for creating anchor links, which can focus on a particular element when the page is loaded.
  • πŸ“š The video script concludes with a reminder of the importance of understanding 'ID' and 'class' as fundamental concepts in web development.

Q & A

  • What is the primary purpose of using IDs in HTML?

    -The primary purpose of using IDs in HTML is to provide a unique identifier to an element, ensuring that no other element has the same ID.

  • Can the same ID be used for multiple elements in a webpage?

    -No, the same ID cannot be used for multiple elements. Each ID must be unique to a single element, similar to an Aadhar card number for an individual.

  • What does the term 'class' represent in the context of HTML?

    -In HTML, a 'class' is used to define a set of properties that can be shared among multiple elements, allowing for the application of common styles or attributes.

  • Can multiple classes be assigned to a single HTML element?

    -Yes, multiple classes can be assigned to a single HTML element, separated by spaces, allowing the element to share properties from different class definitions.

  • How can you apply the same class to different elements for styling purposes?

    -You can apply the same class to different elements by assigning the same class name to each element's 'class' attribute, which allows them to inherit the same styles defined in the CSS.

  • What is the difference between an ID and a class in terms of specificity in CSS?

    -In CSS, an ID has a higher specificity than a class. Selectors with IDs will take precedence over selectors with classes when there is a conflict in styling rules.

  • How can you use an ID in a URL to navigate directly to a specific part of a webpage?

    -You can use an ID in a URL by appending a hashtag (#) followed by the ID value to the end of the URL. This will cause the browser to scroll to the element with that ID when the page is loaded.

  • What is the significance of the 'index.html' file mentioned in the script?

    -The 'index.html' file is the main HTML file that is created to demonstrate the concepts of ID and class in the video. It serves as the starting point for the examples provided.

  • How does the video script use the analogy of Aadhar numbers to explain IDs?

    -The script uses the analogy of Aadhar numbers, which are unique identification numbers for individuals in India, to illustrate that each ID in HTML is unique and cannot be shared among elements.

  • What is the role of the 'class' attribute in HTML elements as described in the video?

    -The 'class' attribute in HTML is used to specify one or more class names to an element, allowing it to be styled with CSS or manipulated with JavaScript, and it can be shared among multiple elements.

  • How does the video script differentiate between the use of IDs and classes in HTML?

    -The script differentiates by explaining that IDs are unique identifiers for elements, while classes are used to group elements and apply shared styles or attributes, which can be reused across multiple elements.

Outlines

00:00

πŸ”‘ Understanding ID and Classes in HTML

This paragraph introduces the fundamental concepts of ID and Classes in HTML, highlighting the confusion often faced by beginners. The speaker clarifies that an ID is a unique identifier for an HTML element, ensuring no two elements share the same ID, akin to a person's Aadhar card number in India. In contrast, a class can be assigned to multiple elements to apply shared styles or attributes. The analogy of a classroom with students wearing different colored t-shirts is used to illustrate how multiple elements can share the same class. The paragraph concludes with a demonstration of creating an HTML file and explaining the practical use of IDs and classes in coding.

05:02

🎨 Applying CSS with IDs and Classes

The second paragraph delves into the practical application of IDs and classes in CSS for styling web elements. It emphasizes the uniqueness of an ID, which cannot be duplicated across elements, compared to classes that can be applied to multiple elements. The speaker uses the Aadhar card analogy again to stress the singularity of an ID. The paragraph provides a step-by-step guide on writing CSS to target elements with specific IDs and classes, demonstrating how to change the background and text color using class selectors. It also touches on the use of IDs in creating direct links to specific parts of a webpage, showcasing this functionality with a Wikipedia example.

10:04

πŸ“š Conclusion and Encouragement to Learn

The final paragraph wraps up the video with a light-hearted anecdote about naming a village, followed by a call to action for viewers. The speaker encourages viewers to access the playlist for more web development lessons, to visit the GitHub repository for source code, and to like the video. They also invite viewers to write '#sigmabatchop' in the comments section to engage with the community. The speaker thanks the audience for watching and expresses excitement for the next video, leaving the viewers with a friendly and inviting impression.

Mindmap

Keywords

πŸ’‘ID

An ID (Unique Identifier) in HTML is an attribute used to uniquely identify an element. It can only be assigned to one element per page, ensuring each ID is distinct. For example, in the video, the ID is compared to an Aadhar number, emphasizing its uniqueness like personal identification numbers.

πŸ’‘Class

A class in HTML is an attribute that can be assigned to multiple elements to apply the same style or behavior to all of them. Unlike IDs, classes are not unique and can be shared among elements. In the video, classes are illustrated by assigning the 'red' class to both a div and a span element.

πŸ’‘Unique Identifier

This term refers to a unique label that distinguishes one item from another. In HTML, an ID serves as a unique identifier for an element. The video uses the analogy of an Aadhar number to explain how each ID must be unique to each HTML element.

πŸ’‘Element

An element in HTML is a component of the web page defined by a start tag, content, and an end tag. Examples include div, span, and form. The video explains elements as building blocks to which IDs and classes are applied to control their styling and behavior.

πŸ’‘HTML

HTML (HyperText Markup Language) is the standard language for creating web pages and web applications. The video focuses on explaining how IDs and classes are used within HTML to manage and style web page elements.

πŸ’‘CSS

CSS (Cascading Style Sheets) is a style sheet language used for describing the presentation of a document written in HTML. The video shows how to use CSS to style elements using classes and IDs, such as setting background colors and text colors.

πŸ’‘Aadhar Number

In the video, an Aadhar number is used as an analogy to explain the concept of an ID in HTML. Just as an Aadhar number uniquely identifies an individual, an ID uniquely identifies an HTML element.

πŸ’‘Style

In the context of the video, style refers to the visual presentation of HTML elements, managed through CSS. The video demonstrates how applying different classes and IDs can change an element's appearance, such as its background color or text color.

πŸ’‘Attribute

An attribute in HTML provides additional information about an element. IDs and classes are attributes that specify unique identifiers and shared properties, respectively. The video explains how these attributes are used to style elements uniquely or in groups.

πŸ’‘Selector

In CSS, a selector is a pattern used to select the elements you want to style. The video describes how to use class selectors (denoted by a dot) and ID selectors (denoted by a hash) to apply styles to HTML elements.

Highlights

ID and Classes are fundamental concepts in HTML that are often confused.

ID stands for Unique Identifier, meaning it should be unique to one element.

Class is used to assign the same properties to multiple elements.

An example of class usage is assigning the 'Red' class to both a div and a form.

The video includes a live demonstration on a computer screen.

The source code for the demonstration is available on GitHub.

An analogy is used comparing ID to an Aadhar card number, unique to an individual.

Classes are likened to a school class where multiple students can share the same class name.

Multiple classes can be assigned to a single element, such as 'red' and 'bg-yellow'.

ID attributes are unique and cannot be shared among elements, similar to an Aadhar number.

CSS demonstration shows how to target classes and IDs for styling.

The 'dot' notation is used for classes and the 'hash' for IDs in CSS.

IDs can also be used for navigation, creating links to specific parts of a page.

The video explains how to use IDs for direct navigation to page sections.

ID and classes are attributes of HTML elements used for styling and identification.

The video concludes with a reminder of the practical applications of ID and classes in web development.

The presenter encourages viewers to access the playlist, GitHub, and engage with the content.

Transcripts

play00:00

In this video, I will tell you what are ID and Classes?

play00:03

The concept of ID and Classes is one of the most confused concepts.

play00:07

In fact, when I was learning HTML, I was very confused in my early days.

play00:12

ID means Unique Identifier.

play00:14

That is, if you give an ID to an element, you will not give that ID to the other element.

play00:18

But class means that if you want to give a property to multiple elements,

play00:24

then you will give it multiple classes.

play00:26

For example, you can give a class named Red to a div and a form.

play00:30

Similarly, you can give a class named BGRed to an article tag and a header tag.

play00:35

Do like this video because we will now go to the computer screen

play00:39

and we are going to see these things very closely.

play00:42

Let's roll the intro. Intro

play00:52

Alright guys, I am back.

play00:54

If you haven't accessed the Sigma Web Development course yet,

play00:57

then access the playlist.

play00:59

Click here to bookmark or click here to save.

play01:01

The source code is also being uploaded on GitHub.

play01:04

Now I will come here in the folder and quickly make a folder of video number 9

play01:08

so i will make a folder of video 9 here

play01:11

i will write video 9 and after making the folder of video 9

play01:14

i will right click on shift and open with code

play01:17

and here you can see that it has opened in bs code

play01:20

now i will write index.html here and enter with exclamation mark

play01:24

and along with that i will tell you what is ID and classes

play01:28

you must have an Aadhar card, if not, then you must have some ID

play01:33

now don't write in the comment that I don't have an ID

play01:35

whenever you go somewhere, you have to show your ID

play01:38

in some of the cases to prove your identity

play01:41

that I am this

play01:43

now if you want to understand about ID and classes

play01:46

in html, then ID is the

play01:48

identity of the person

play01:50

what is that? it is your identity

play01:52

so here listen to a story

play01:54

this is john and this is harry

play01:56

these two are very good friends

play01:58

they are very good friends

play02:00

they just don't share their lunch

play02:02

and the rest are good friends

play02:04

in the matter of food he is not and he is they don't share their lunch and they are good friends

play02:05

they are not good in food but they are good in everything

play02:09

and here you can see john and harry have their own id

play02:14

so this is my aadhar number and john's aadhar number looks like this

play02:20

so this is john's aadhar number and this is my aadhar number

play02:24

our aadhar number can never be same

play02:26

or if we assume that

play02:29

our friend is mine

play02:32

Tanya and John's friend is Shruti

play02:35

so their Aadhar numbers will be different

play02:38

and this is Tanya's Aadhar number

play02:41

now

play02:44

this Aadhar number will be different for everyone

play02:46

so John and Harry were friends, John's friend was Shruti

play02:49

this is her Aadhar number, this is Tanya's

play02:52

none of these four numbers are same

play02:55

if I told you any of these Aadhar numbers

play02:58

I would have said 35, 44, 5, you will understand that it is Harry's

play03:01

and if I said 54, 56, 56, 7

play03:04

you will understand that it is Shruti's And if I say 54,56,56,57

play03:06

And if I say

play03:09

34,56,85,68,63

play03:12

Then you will understand that it's about Tanya.

play03:15

So this identifies uniquely

play03:18

Tanya, Harry, Shruti and John.

play03:21

So this is their id.

play03:24

No one else will get this id. so this is their ID

play03:25

no one else will get this ID

play03:27

and also

play03:29

John and Harry spent their childhood together

play03:31

they were in the same class

play03:33

and that class name was

play03:35

class 10th

play03:37

suppose they are in 10th class

play03:39

suppose

play03:41

and

play03:43

Shruti is in class 9th and Tanya is also in class 9th so both is in class 9th

play03:45

and tanya is also in class 9th

play03:47

so both are in class 9th

play03:49

tanya and shruti are in class 9th

play03:52

so what is shruti's class? 9th

play03:55

tanya's class can also be 9th

play03:56

shruti will not study alone in class

play03:58

or harry will not study alone in class 10th

play04:00

there are other kids in class

play04:02

so class means

play04:04

in one class there are

play04:06

harry and john, so can class be

play04:08

multiple of one person?

play04:10

it can be multiple of one person

play04:12

like suppose harry is in class 10

play04:14

and he goes to a tuition

play04:16

where he is in class 10A

play04:18

suppose there are classes in that tuition

play04:20

so there can be more than one class

play04:22

one is class 10A

play04:24

and with that suppose harry wears red t-shirt So there can be more than one class One is class 10A

play04:26

And with that if Harry wears red t-shirt

play04:29

So class means classifying

play04:32

Now come here

play04:35

Leave this john harry shruti

play04:38

Delete it

play04:41

Now come to index.html

play04:44

And understand this.

play04:45

Suppose I made a div here.

play04:47

And I gave it a class as red.

play04:50

And I made a span and gave it a class as red.

play04:53

The classes I have given, I can give them to different elements.

play04:56

But if I want to put an id.

play04:58

In any element.

play05:02

I can put anything in id. I id is not available to any other element

play05:06

Because this is its aadhar card

play05:08

If there is another div, then also I can't put

play05:10

Then also I have to put something else in id

play05:12

I put second div

play05:14

And here I write second

play05:16

And here I will write first

play05:18

So this id and

play05:20

Classes concept, I personally

play05:22

I understood it very late

play05:24

When I was learning web development in my early days

play05:26

no one told me that ID uniquely identifies

play05:29

an element and the class can be

play05:32

multiple classes in one element and

play05:35

can be multiple classes in one element only

play05:38

like if I give it a red class, I can give it a bg yellow class

play05:41

ok bg yellow

play05:43

I can give only one class and if we give a class to a multiple element then we give it bg-yellow class I can give one class

play05:46

and if we give multiple to any element then we can give space

play05:49

like if i want to put multiple classes in this element

play05:52

then what i will do is

play05:55

i will write red here and then space and bg-yellow

play05:58

so like this i can give multiple classes to same element

play06:01

can i give multiple id to same element

play06:04

have you ever heard of 2 Aadhar cards?

play06:06

I don't know but there are no Aadhar cards

play06:09

Aadhar number is same for one person

play06:12

And Aadhar number can't be same for different people

play06:16

One person can't have multiple Aadhar cards

play06:19

Different people can't have same Aadhar cards

play06:21

But the class, if I ask you what color T-shirt you wear

play06:24

Or you can wear red t-shirt,

play06:26

no problem, you will get it if you go on the road.

play06:29

And let's say you get people who like mango, banana, or grapes,

play06:35

multiple people will get it, so assume that in the banana class,

play06:38

or in the grapes class, in the mango class.

play06:41

So we can classify in a class and we can give different elements to one class

play06:46

I hope you understood this. Now i'll write some CSS

play06:49

Don't say that you are not reading CSS

play06:52

What i'm writing in CSS is like alien language

play06:55

Ok

play06:56

Style.css

play06:59

I'm trying to make a point

play07:02

And here's the preview I will show you one thing

play07:06

I will show you how to target the class in CSS

play07:09

Dot it, dot red means red class

play07:12

And hash first div means, hash means id, dot means class

play07:16

Okay, if I say that the first div

play07:20

Make its background color red

play07:22

Okay, so by making the background color of the first div red

play07:24

Its background color will be red, ok

play07:26

these are selectors in CSS

play07:28

and now I don't want to confuse you

play07:30

and I can comment in this way in CSS

play07:32

ok, but we will study all these things later

play07:34

now by making dot red

play07:36

I will write here background color red

play07:38

and along with that in dot bg yellow

play07:40

what I will do

play07:42

dot bg yellow will be mine, I have to put dot

play07:44

dot means class, it means class bg yellow, I will put a dot dot means class, class bg yellow

play07:48

and I will make background color yellow, sorry I will make it color red

play07:52

dot red means color will be red, so see its color is red and background color is yellow

play07:56

so this way you can use id and classes

play08:00

in css, I hope you understood this

play08:04

one thing to note here

play08:06

ID and classes are attributes of element

play08:09

This is ID attribute and this is class attribute

play08:12

So what are ID classes? They are elements

play08:15

Now there is another use of ID

play08:18

I will tell you what is another use of ID

play08:21

If i take you to wikipedia and i write coding

play08:24

So this page of Wikipedia has come, let's say I go to some other page

play08:26

so you see that when you go to any page on Wikipedia

play08:29

so what you can do is

play08:32

you can take the link of that particular place, I will show you how it is

play08:35

I go to some other page, I scroll down

play08:38

and here I will inspect its ID

play08:41

its ID is this, so I will copy its ID

play08:44

and if I put here hashtag I'll copy the ID I'll copy the ID

play08:46

And if I put hashtag and this ID

play08:49

If I hit enter, it will bring me here

play08:52

If I put it in incognito

play08:55

It will scroll and show me the particular ID

play08:58

Instead of showing me this

play09:01

It scrolled and showed me

play09:04

So ID works in linking, okay. Remember this too, very few people will tell you

play09:08

that you can also generate links, if you write hashtag in front of any link

play09:12

and write ID, then when you open that link, it will focus the same ID

play09:16

as it is giving me in this case. You can see that as soon as I am hitting enter,

play09:20

so maybe I have done the wrong ID here, but you got the point, you got the point.

play09:24

Here 29.29 and I will hit enter, so you see I have done wrong id here. But you got the point. 29.29

play09:26

I will enter it.

play09:28

I have come down.

play09:30

If I open the incognito tab or reload it.

play09:32

I will scroll it up.

play09:34

And after that I will open a new tab.

play09:36

And I will do like this.

play09:38

See it is scrolling me to the same page.

play09:40

On the same page this id is.

play09:42

I hope you have understood id and class.

play09:44

Through this video. ID means

play09:46

class means a person's property

play09:48

like he likes red or

play09:50

in which class he is. One element

play09:52

can be given in multiple classes. One element

play09:54

can be of red color and its background can be yellow

play09:56

and the other element can be of red color

play09:58

and its background can be yellow. So red class can be

play10:00

given in multiple elements. Red class

play10:02

can be given in fake element and

play10:04

in one element you can give red class and fake element and you can also add red class on one element

play10:06

and you can also add yellow class on one element

play10:08

I hope you understood

play10:10

So that's it for this video

play10:12

I was reading captions and I laughed

play10:14

I told him to name the village

play10:16

I laughed 5-10 times

play10:18

I told him to access

play10:20

Name your village and my name

play10:22

So on this note

play10:24

Access the playlist Access the github,

play10:26

like the video,

play10:28

and write hashtag sigma batch op in the comment section.

play10:30

Thank you so much guys for watching this video

play10:32

and I will see you next time. Thanks for watching!

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
HTML BasicsCSS SelectorsWeb DevelopmentUnique IdentifierMultiple ClassesID vs ClassAadhar CardCode TutorialWeb AccessibilityClassifying Elements