Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

HTML class global attribute

Theclassglobal attribute is a list of the classes of the element, separated byASCII whitespace.

Try it

<p>Narrator: This is the beginning of the play.</p><p>Above point sounds a bit obvious. Remove/rewrite?</p><p>Narrator: I must warn you now folks that this beginning is very exciting.</p><p>[Lights go up and wind blows; Caspian enters stage right]</p>
.note {  font-style: italic;  font-weight: bold;}.editorial {  background: rgb(255 0 0 / 0.25);  padding: 10px;}.editorial::before {  content: "Editor: ";}

Syntax

Theclass attribute is a list of class values separated byASCII whitespace.

Each class value may contain any Unicode characters (except, of course, ASCII whitespace). However, when used in CSS selectors, either from JavaScript using APIs likeDocument.querySelector() or in CSS stylesheets, class attribute values must be validCSS identifiers. This means that if a class attribute value is not a valid CSS identifier (for example,my?class or1234) then it must be escaped before being used in a selector, either using theCSS.escape() method ormanually.

For this reason, it's recommended that developers choose values for class attributes that are valid CSS identifiers that don't require escaping.

Description

Classes allow CSS and JavaScript to select and access specific elements via theclass selectors or functions like thedocument.getElementsByClassName().

Though the specification doesn't put requirements on the name of classes, web developers are encouraged to use names that describe the semantic purpose of the element, rather than the presentation of the element. For example,attribute to describe an attribute rather thanitalics, although an element of this class may be presented byitalics. Semantic names remain logical even if the presentation of the page changes.

Specifications

Specification
HTML
# global-attributes:classes-2

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp