HTML is a markup language used to create web pages. In HTML, attributes are characteristics of an element that define its behavior. Attributes can set the color, size, link target, etc. of the element. In this article, we will introduce some commonly used attributes in HTML.
The class attribute is used to specify the category to which the element belongs. Categories can be one or more words, separated by spaces. Categories can provide identifiers for CSS style settings so that the style of elements can be uniformly controlled globally.
For example:
<div class="container"> <p class="paragraph">这是一个段落。</p> </div>
In the above example, both the div element and the p element have a class attribute. The class attribute of the div element is "container", and the class attribute of the p element is "paragraph".
The id attribute is used to specify the unique identifier of the element. The id attribute can be used as a hyperlink anchor within the document or as a positioned element in JavaScript code.
For example:
<div id="header"> <h1>网站标题</h1> </div>
In the above example, the id attribute of the div element is "header".
The style attribute is used to define CSS styles for elements. The value of the style attribute is a CSS style and can contain multiple CSS properties and values.
For example:
<p style="color:red;font-size:20px;">这是一个段落。</p>
In the above example, the style attribute of the p element is "color:red;font-size:20px;".
The href attribute is used to specify the target address of the hyperlink. The href attribute can be an absolute path or a relative path.
For example:
<a href="http://www.example.com">这是一个链接</a>
In the above example, the href attribute of the a element is "http://www.example.com".
The src attribute is used to specify the address of media files such as images, audio, or videos.
For example:
<img src="image.jpg">
In the above example, the src attribute of the img element is "image.jpg".
The alt attribute is used to provide alternative text for image elements. When the image fails to load, the value of the alt attribute will be displayed on the page.
For example:
<img src="image.jpg" alt="这是一张图片">
In the above example, the alt attribute of the img element is "This is a picture".
The title attribute is used to provide additional information for the element. The value of the title attribute will be displayed in the browser when the mouse is hovered over the element.
For example:
<a href="http://www.example.com" title="这是一个链接">这是一个链接</a>
In the above example, the title attribute of the a element is "This is a link".
The target attribute is used to specify how a hyperlink opens a page. The target attribute can be _blank (open in a new window), _self (open in the current window), etc.
For example:
<a href="http://www.example.com" target="_blank">这是一个链接</a>
In the above example, the target attribute of the a element is "_blank".
Summary
In HTML, attributes are characteristics of an element that define its behavior. Commonly used HTML attributes include class, id, style, href, src, alt, title, target, etc. Mastering these properties allows us to better create Web pages.
The above is the detailed content of What are the html attributes?. For more information, please follow other related articles on the PHP Chinese website!