Difference between Class & ID
Both are used to style the elements of HTML in CSS but there are some differences between them which are mentioned in the image:
For a better understanding we can have an example let's see:-
here HTML code
<p class="paragraph">This is a paragraph.</p>
<p class="paragraph">This is another paragraph.</p>
<h1 id="header">This is the header.</h1>
<div id="main-content">This is the main content area.</div>
here CSS code
.paragraph {
font-size: 16px;
line-height: 24px;
}
#header {
font-size: 32px;
font-weight: bold;
}
#main-content {
width: 80%;
margin: 0 auto;
}
22 likes