Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Classes and Ids | Getting Acquainted with HTML
Web Scraping with Python

book
Classes and Ids

HTML has a limited number of tags, but sometimes you need to differentiate between specific elements. For example, if you want to apply different styles to various paragraphs (<p> elements), you can use the class and id attributes.

The class attribute assigns a class to a specific HTML element. Multiple elements can share the same class. This allows you to apply the same styles to multiple elements.

html

index.html

css

styles.css

copy
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="styles.css" />
</head>

<body>
<p class="highlight">This text is highlighted.</p>
<p class="highlight">This paragraph is also highlighted.</p>
<p class="normal">This paragraph is not highlighted.</p>
</body>
</html>

In this example, two paragraphs share the same highlight class, allowing you to apply the same styles to both.

The id attribute assigns a unique identifier to a specific HTML element. Unlike the class attribute, each element can only have one unique id. This is useful for applying styles or manipulating a specific element using JavaScript.

html

index.html

css

styles.css

copy
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="styles.css" />
</head>

<body>
<p id="first-paragraph">This paragraph has a unique identifier.</p>
<p id="second-paragraph">This paragraph also has a unique identifier.</p>
</body>
</html>

It's important to remember that the id must be unique on the page. You cannot use the same id value for multiple elements.

question mark

Choose the correct statements.

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 6
some-alt