What are the global attributes of html?

WBOY
Release: 2024-02-22 20:48:04
Original
1078 people have browsed it

What are the global attributes of html?

HTML Global Attributes are attributes that apply to all HTML elements, and they can be used in any HTML tag. These global properties are intended to provide common attributes that enhance the functionality and style of HTML elements. Below we will introduce some commonly used HTML global attributes and attach corresponding code examples.

  1. class (Class)
    class attribute is used to specify one or more class names to define styles for elements. Multiple class names can be separated by spaces. Style sheets and JavaScript code can select specific elements based on class names.

Code example:

<div class="container">
    <p class="red">这是一个红色的段落。</p>
</div>
Copy after login

In the above example, class="container" defines a class with the class name container The div element, and class="red" defines a p element with the class name red.

  1. id (Identification) The
    id attribute is used to define a unique identifier for an element so that a specific element can be selected via JavaScript or CSS. Element id must be unique on each page.

Code example:

<h1 id="title">这是页面的标题</h1>
Copy after login

In the above example, id="title" defines a unique identifier as title The h1 element.

  1. style (style)
    style attribute is used to directly define the inline style for the element. You can set the color, font, background and other styles of the element. .

Code Example:

<p style="color: red; font-size: 16px;">这是一个红色的段落,字体大小为16像素。</p>
Copy after login

In the above example, the style attribute defines a red font and a p## with a font size of 16 pixels #element.

  1. title (title)
    title attribute is used to provide additional information to the element when the mouse is hovered over the element. will be displayed as a tool tip. Typically used to provide additional description of an element.
Code Example:

<a href="https://www.example.com" title="点击跳转到示例网站">示例网站</a>
Copy after login
In the above example, when the mouse is hovered over the

element, it will be in the form of a tooltip "Click to jump to sample website" is displayed.

The above are only some common uses and examples of HTML global attributes. There are also other global attributes, such as

lang, hidden, draggable etc., they all have their own specific uses. Global attributes provide us with more flexibility and functionality in developing and customizing web pages. By using these attributes appropriately, we can better control and present the content of the page.

The above is the detailed content of What are the global attributes of html?. For more information, please follow other related articles on the PHP Chinese website!

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