HTML attributes

HTML tags can have attributes. Attributes provide more information about HTML elements.

Attributes always appear in the form of name/value pairs, such as: name="value".

Attributes are always specified in the opening tag of an HTML element.


Example

HTML links are defined by the <a> tag. The link's address is specified in the href attribute:

<a href="http://www.php.cn">This is a link</a>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>php.cn</title>
</head>
<body>
    <a href="http://www.php.cn">This is a link</a>
</body>
</html>

Code running result:

1.png

Example explanation: By clicking "This is a link" above, you will jump to http:// www.w3school.com.cn This website



##Attribute example 1:

<h1> Defines the beginning of the title.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>php.cn</title>
</head>
<body>
<h1 align="center">标题</h1>
</body>
</html>

Explanation: Center the <h1> title title


##Attribute example 2:< body> defines the body of the HTML document.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>php.cn</title>
</head>
<body bgcolor="yellow">
</body>
</html>

Explanation: The above code means to set the background color of the web page to yellow


Tips

:Attributes and attribute values ​​are not case sensitive sensitive. Newer versions of (X)HTML require lowercase attributes.


Always enclose attribute values ​​in quotes Attribute values ​​should always be enclosed in quotes. Double quotes are the most commonly used, but there is no problem using single quotes.

In some individual cases, such as the attribute value itself contains double quotes, you must use single quotes, for example:

name='Bill "HelloWorld " Gates'


HTML Properties Reference Manual
Our complete HTML Reference Manual A complete list of legal attributes available for each HTML element is provided:

Complete HTML Reference Manual

Attributes that apply to most HTML elements are listed below:

## class classnameSpecifies the class name of the element id idSpecifies the unique id of the element style style_definition Specifies the inline style of the element title text Specifies additional information for the element (can be found in the tooltip Display)
Attribute Value Description
For more information about standard properties, please visit:

HTML Standard Properties Reference Manual


Continuing Learning
||
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>php.cn</title> </head> <body> <a href="http://www.php.cn">这是一个链接</a> </body> </html>
submitReset Code