{"id":9325,"date":"2022-10-06T04:53:14","date_gmt":"2022-10-06T04:53:14","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=9325"},"modified":"2022-10-06T04:53:14","modified_gmt":"2022-10-06T04:53:14","slug":"html-class-attribute","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/10\/06\/html-class-attribute\/","title":{"rendered":"HTML Class Attribute"},"content":{"rendered":"\n<p>The HTML&nbsp;class&nbsp;attribute is used to specify one or more class names for an element. Commonly, the&nbsp;class&nbsp;attribute points to a class in a style sheet. The class name is case sensitive.<\/p>\n\n\n\n<p>This attribute can also be used by\u00a0JavaScript\u00a0via the HTML DOM to make certain changes to HTML elements with a specified class name.<\/p>\n\n\n\n<p>In\u00a0HTML5, you can use the\u00a0class\u00a0attribute for any HTML element.<\/p>\n\n\n\n<p>In HTML 4.01, the\u00a0class\u00a0attribute cannot be used with the following elements:\u00a0&lt;head>,\u00a0&lt;html>,\u00a0&lt;base>,\u00a0&lt;basefont>,\u00a0&lt;param>,\u00a0&lt;style>,\u00a0&lt;meta>,\u00a0&lt;script>, and\u00a0&lt;title>.<\/p>\n\n\n\n<p>Although there aren\u2019t specific requirements for the name of classes, it\u2019s better to use names describing the semantic purpose of the element, and not its presentation. The name should begin with a letter a-z or A-Z, and it can be followed by letters, digits (0-9), underscores (&#8220;_&#8221;), and hyphens (&#8220;-&#8220;).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"syntax-2\">Syntax<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;tag class=\"classname\"&gt;&lt;\/tag&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-of-the-html-span-class-attribute-class-span-attribute-4\">Example of the HTML&nbsp;class&nbsp;attribute:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;title&gt;Title of the document&lt;\/title&gt;\n    &lt;style&gt;\n      .red {\n        color: red;\n      }\n      .orange {\n        color: orange;\n      }\n    &lt;\/style&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;h1&gt;Example of the HTML class attribute&lt;\/h1&gt;\n    &lt;p class=\"red\"&gt;It is a some red paragraph.&lt;\/p&gt;\n    &lt;p&gt;This is a some text.&lt;\/p&gt;\n    &lt;p class=\"orange\"&gt;It is a some yellow paragraph.&lt;\/p&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p>In\u00a0CSS, if you want to select elements with a specific class, use a period (.) character followed by the class name.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-of-the-html-span-class-attribute-class-span-attribute-used-with-css-7\">Example of the HTML&nbsp;class&nbsp;attribute used with CSS:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;title&gt;Title of the document&lt;\/title&gt;\n    &lt;style&gt;\n      .title {\n        background-color: #1c87c9;\n        color: #ffffff;\n        padding: 20px;\n      }\n    &lt;\/style&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;h1&gt;Example of the class attribute&lt;\/h1&gt;\n    &lt;h2 class=\"title\"&gt;Heading&lt;\/h2&gt;\n    &lt;p&gt;Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.&lt;\/p&gt;\n    &lt;h2 class=\"title\"&gt;Heading&lt;\/h2&gt;\n    &lt;p&gt;Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.&lt;\/p&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p>HTML elements can also have more than one class name. Each of them must be separated by a space.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-of-the-html-span-class-attribute-class-span-attribute-with-multiple-class-names-10\">Example of the HTML&nbsp;class&nbsp;attribute with multiple class names:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;title&gt;Title of the document&lt;\/title&gt;\n    &lt;style&gt;\n      .title {\n        background-color: #202131;\n        color: #dddddd;\n        padding: 15px 25px;\n      }\n      .text-right {\n        text-align: right;\n      }\n    &lt;\/style&gt;\n    &lt;body&gt;\n      &lt;h1&gt;Example of multiple classes&lt;\/h1&gt;\n      &lt;p&gt;\n        Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.\n      &lt;\/p&gt;\n      &lt;h2 class=\"title\"&gt;London&lt;\/h2&gt;\n      &lt;p&gt;\n        Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.\n      &lt;\/p&gt;\n      &lt;h2 class=\"title text-right\"&gt;Paris&lt;\/h2&gt;\n      &lt;p&gt;\n        Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.\n      &lt;\/p&gt;\n      &lt;h2 class=\"title\"&gt;Tokyo&lt;\/h2&gt;\n    &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p>Different tags, such as\u00a0&lt;h2>\u00a0and\u00a0&lt;p>\u00a0can have the same class name and the same style.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-of-the-html-span-class-attribute-class-span-attribute-with-the-lt-h2-gt-and-lt-p-gt-elements-13\">Example of the HTML&nbsp;class&nbsp;attribute with the &lt;h2&gt; and &lt;p&gt; elements:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;title&gt;Title of the document&lt;\/title&gt;\n    &lt;style&gt;\n      .grey-text {\n        color: #808080;\n      }\n    &lt;\/style&gt;\n    &lt;body&gt;\n      &lt;h1&gt;Example of the class attribute &lt;\/h1&gt;\n      &lt;h2 class=\"grey-text\"&gt;Heading&lt;\/h2&gt;\n      &lt;p class=\"grey-text\"&gt;\n        Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.\n      &lt;\/p&gt;\n    &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The HTML&nbsp;class&nbsp;attribute is used to specify one or more class names for an element. Commonly, the&nbsp;class&nbsp;attribute points to a class in a style sheet. The class name is case sensitive. This attribute can also be used by\u00a0JavaScript\u00a0via the HTML DOM to make certain changes to HTML elements with a specified class name. In\u00a0HTML5, you can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[582],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/9325"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=9325"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/9325\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=9325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=9325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=9325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}