What is the difference between classes and IDs in CSS?

Classes and IDs are both used to identify elements in HTML documents. The main difference between them is that a class can be used to identify multiple elements, while an ID can only be used to identify one element.

Classes:

Classes are used to identify a group of elements that share the same characteristics. For example, if you wanted to style all

elements on a page, you could create a class called “title” and assign it to each

element.

IDs:

IDs are used to identify a single element on a page. For example, if you wanted to style a specific

element on a page, you could create an ID called “main-title” and assign it to that specific

element.

What are the advantages of using CSS?

1. CSS is more efficient than using HTML for styling as it separates the content from the presentation. For example, instead of using HTML to create a paragraph with a bold font, you can use CSS to style the paragraph with the font-weight property:

This text is bold.

2. CSS is easier to maintain than HTML, as it allows you to make changes to a single file instead of making changes to multiple HTML files. For example, if you want to change the font of your website, you can do it in one place by changing the font-family property in your CSS file.

3. CSS is more responsive than HTML, as it allows you to create different styles for different devices. For example, you can create a different style for mobile devices and desktop devices by using media queries.

4. CSS is more compatible with different browsers than HTML, as it allows you to create styles that are compatible with different browsers. For example, you can use vendor prefixes to create styles that are compatible with different versions of a browser.

What are the different ways to apply CSS to a web page?

1. Inline CSS: This is the simplest way to apply CSS to a web page. With inline CSS, you apply the style directly to the HTML element using the style attribute and CSS declarations. For example:

This is a heading

2. Internal or Embedded CSS: Internal CSS is used when you want to apply a unique style to a single HTML page. You can define internal CSS in the section of an HTML page, by using the tag. For example:

h1 {
color: blue;
font-size: 24px;
}

3. External CSS: External CSS is used when you want to apply the same style to multiple HTML pages. You can link to an external CSS file using the tag. For example: