Home > Web Front-end > HTML Tutorial > What is the class attribute in HTML5

What is the class attribute in HTML5

青灯夜游
Release: 2023-02-17 16:56:29
Original
7786 people have browsed it

In HTML5, the class attribute can define the class name of the element. It is often used to point to the class of the style sheet (class selector). It can also be used in JavaScript to modify the class name of the HTML element and modify the style; syntax Format "<element class="classname">". <element class="classname">

What is the class attribute in HTML5

The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer.

HTML5 class attribute

The class attribute defines the class name of the element. The

class attribute is typically used to point to the class of a style sheet (i.e. the CSS .class selector). However, it can also be used in JavaScript (via the HTML DOM) to modify the class name of an HTML element.

Syntax

<element class="classname">
Copy after login

classname: Specifies the name of the class of the element. To specify multiple classes for an element, separate the class names with spaces. . Multiple classes are allowed for HTML elements.

Name rules:

  • must start with the letters A-Z or a-z

  • can be the following characters: (A-Za- z), numbers (0-9), bars ("-"), and underscores ("_")

  • In HTML, class names are case-sensitive

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style>
.center
{
	text-align:center;
}
</style>
</head>

<body>
<h1 class="center">标题居中</h1>
<p class="center">段落居中。</p> 
</body>
</html>
Copy after login

Rendering:

What is the class attribute in HTML5

##[Recommended tutorial: "

html video tutorial》】

The above is the detailed content of What is the class attribute in HTML5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template