Class properties in HTML

In HTML, class properties are used to identify one or more class names for HTML elements.

In HTML, class properties are used to identify one or more class names for HTML elements. Class names can be used in CSS or JavaScript to perform certain tasks for elements named that class. In CSS, to select an element with a special class, add a dot (.) And then enter the class name.

Examples use CSS to style all elements with the class name 'city'



Hanoi


Hanoi is the capital of Vietnam.



Paris


Paris is the capital of France.



Tokyo


Tokyo is the capital of Japan.

The results displayed will look like the following.

Class properties in HTML Picture 1Class properties in HTML Picture 1
The class attribute applies to many elements

Note:

  1. class properties can be used with any HTML element.
  2. The class name distinguishes between uppercase and lowercase letters.

Use class properties in JavaScript

JavaScript can access certain class-named elements with getElementsByClassName()

For example, when a user clicks a button, hiding all elements with the class name is 'city'.

 

Use multiple layers in HTML

HTML elements can use multiple class names, each with a space separated by a space. For example, you can style elements with the 'city' and 'big' layers.

London


Paris


Tokyo

Same class but different cards

Different cards like

 

good

can use the same class name (and have the same style).

Hanoi


Hanoi is the capital of Vietnam.

Previous lesson: Block and inline elements in HTML

The following article: id attribute in HTML

3.5 ★ | 2 Vote