Html 简明教程

HTML - Attribute Reference

HTML 属性是 HTML 的特殊关键词,属性在开始标签中使用。HTML 元素类型可以通过 HTML 属性修改。属性要么改变元素类型的默认功能,要么向某种元素类型添加某种功能,没有这种功能,该元素类型将无法正常工作。

HTML attributes are the special keywords of HTML, attributes are used inside the opening tag. An HTML element type can be modified via HTML attributes. An attribute either changes an element type default functionality or adds functionality to some element type that wouldn’t work properly without it.

attribute example

Types of HTML Attributes

在本文中,我们收集了所有属性并将其分类为两部分。

In this article we have collected all the attributes in one place and we have categorize them into two parts.

Local Attributes

本地属性按元素划分,这些属性可用于某些特定的 * HTML elements* 。以下是本地属性。

Local attributes are element specific, these attributes can be used on some specific HTML elements. Following are the local attributes.

Attribute

Description

Example

accept

The HTML accept attribute is used to describe what file type the user should be allowed to select from a file input dialog box.

Try It

accept-charset

The HTML accept-charset attribute is used to specify the character encodings that are to be used for the form submission.

Try It

action

The HTML action attribute is used to specify a URL that processes the form submission.

Try It

align

The alignment of content within an HTML element, such as images or tables, was specified by the HTML align attribute.

Try It

alt

The alt attribute is essential for supplying alternative text for images, facilitating accessibility, and improving user experience.

Try It

async

The HTML async attribute is a Boolean attribute that is used to specify the script to execute/run as soon as it’s loaded.

Try It

autofocus

The HTML autofocus attribute is a boolean attribute that is used to specify that an element should be autofocused after the page has loaded.

Try It

bgcolor

The HTML bgcolor attribute or property is used to represent the background color of elements.

Try It

border

The border of an HTML element, such as tables and images, can be specified using the HTML border attribute.

Try It

charset

The HTML charset attribute is used for the character encoding in the HTML document.

Try It

checked

The HTML checked attribute is a boolean attribute that indicates whether a checkbox is checked by default (when the page loads).

Try It

class

One or more classes can be specified for an HTML element using the class attribute, which is a fundamental element.

Try It

color

The HTML color attribute is used to set the text color of the font element.

Try It

cols

The HTML cols attribute is used to set or specify the visible width of a text area element.

Try It

colspan

The HTML colspan attribute is used to define how many table columns a cell should span or extend.

Try It

content

The HTML content attribute is used to display/contain the value for the name or HTTP-equiv attribute, depending on which is used.

Try It

coords

The HTML coords attribute is used to specify/set the coordinates of an area in an image map.

Try It

data

The HTML data attribute is used to specify the URL for the resource.

Try It

datetime

The HTML datetime attribute is used to indicate the date and time associated with the element.

Try It

default

The HTML default attribute is a boolean attribute that is used to indicate that a track should be enabled unless the user’s preferences indicate that another track is more appropriate.

Try It

defer

The HTML defer attribute is a boolean attribute that specifies that the script is downloaded parallel to parsing the page, and is executed after parsing the page.

Try It

dirname

The HTML dirname attribute is used to enable the submission of the directionality of the element.

Try It

disabled

The HTML disabled attribute is used to specify that the element is disabled.

Try It

download

The HTML download attribute is used to specify that the resource( the file or resource specified in the href attribute) will be downloaded when a user clicks on the hyperlink.

Try It

enctype

The HTML enctype attribute is used to specify how the form input data should be encoded before sending it to the server.

Try It

formaction

The HTML formaction attribute is used to specify an URL of the file that will process the input controls and redirect to a different page when the form is submitted.

Try It

headers

The HTML header attribute is used to specify a table cell that contains the header information for the current data cell.

Try It

height

In HTML, the height attribute is frequently used to specify the vertical dimension in pixels of an element, such as an image or an iframe.

Try It

high

The HTML high attribute is used to specify the lower bound of an upper range.

Try It

href

The HTML href attribute is used to specify the URL that a hyperlink points to.

Try It

hreflang

The HTML hreflang attribute is used to specify the language of the linked document or URL.

Try It

httpequiv

The HTML http-equiv attribute is used to define the pragma directive.

Try It

id

An HTML element that is used to identify an HTML element on a webpage is the id attribute.

Try It

ismap

The HTML ismap attribute is a Boolean attribute that is used to specify that the image is part of a server-side image map.

Try It

kind

The HTML kind attribute is used to specify the kind of text track for the audio/video.

Try It

list

The HTML list attribute refers to the datalist element that contains the predefined options for an input element.

Try It

low

The HTML low attribute indicates the upper limit of the lower range.

Try It

max

The HTML max attribute is used to define the maximum value that is acceptable and valid for an input field.

Try It

maxlength

The HTML maxlength attribute is used to define the maximum number of characters the user can enter into an ‘input’ and ‘textarea’ field.

Try It

media

The HTML media attribute is used to specify a hint of the media for which the linked resource was designed.

Try It

method

The HTML method attribute is used to define which HTTP method to use when submitting the form.

Try It

minlength

The HTML minlength attribute is used to define the minimum number of characters that a user can enter into an 'input' or 'textarea' field.

Try It

min

For input elements such as <input type="number">, <input type="date">, or <input type="time">, the min attribute in HTML is used to define the minimal value.

Try It

multiple

The HTML multiple attribute is a Boolean attribute, and if present, it allows form controls to accept more than one value.

Try It

name

The HTML name attribute is used to specify the name of an element.

Try It

open

The open attribute is an HTML attribute that indicates or specifies whether the details, that is, the contents of the <details> element, are currently visible.

Try It

optimum

The optimum is an HTML attribute that specifies the range where the gauge’s (to determine the capacity of contents or estimate a judge’s) value is considered to be an optimal value.

Try It

pattern

The HTML pattern attribute is usually used with input elements, particularly text fields like input and textarea.

Try It

placeholder

The HTML placeholder attribute is used to define a short hint that helps the user with data entry.

Try It

poster

The HTML poster attribute is used to specify an image/poster for the video.

Try It

readonly

The HTML readonly attribute is used to specify that an input, or textarea field, is read-only.

Try It

rel

The rel is an HTML attribute that specifies the relationship between the current document and the linked document or resource.

Try It

required

The HTML required attribute is a boolean attribute. It is used to specify that an input field must be filled by users before submitting the form.

Try It

reversed

This attribute can be helpful when you want to show a countdown or sort items by decreasing value.

Try It

rows

The rows is an HTML attribute that is used to specify the height of the textarea in lines.

Try It

rowspan

The rowspan is an HTML attribute that specifies the number of rows spanned by a cell or grid cell within a table or grid.

Try It

sandbox

The sandbox is an HTML attribute that stops a document loaded in an iframe from using certain features (such as submitting forms or opening new windows).

Try It

scope

The scope is an HTML attribute that is used to define the header cell.

Try It

selected

In HTML, to choose element’s options from a dropdown menu are utilized using the selected attribute.

Try It

shape

The shape is an HTML attribute used to specify an area’s shape.

Try It

size

The size is an HTML attribute that is used to specify the initial width of the input field and the number of visible rows for the selected element.

Try It

sizes

The sizes is an HTML attribute that specifies the sizes of the linked resources. It is used to provide the sizes of icons for visual media.

Try It

src

The HTML src attribute is used to represent external resources such as images, videos, audio, and URLs in the page from the external or device resource.

**

span

The span attribute is an HTML attribute that specifies the number of columns a <col> or <colgroup> element should span.

Try It

srcdoc

The srcdoc is an HTML attribute that specifies the HTML content on the page to show in the inline frame.

Try It

srclang

The srclang attribute is an HTML attribute that is used to specify the language of the track text.

Try It

srcset

The srcset is an HTML attribute that is used to specify the URL of an image to use in different situations.

Try It

start

The start attribute is an HTML attribute that specifies the initial value of the ordered list in numeric form.

Try It

step

It is used to set the interval between legal numbers or the distinct step size of the <input> tag.

Try It

style

The HTML style attribute contains a CSS styling declaration and is used to apply it to an element.

Try It

target

The target is an HTML attribute that is used to specify where to open the linked document.

Try It

type

The type is an HTML attribute that specifies the type of element.

Try It

usemap

The usemap is an HTML attribute that creates relationships between <img> and <map> by specifying an image or an object with clickable areas.

Try It

value

For various form elements like input fields, checkboxes, radio buttons, and select options, the initial or default value is specified using the HTML value attribute.

Try It

width

The width of an element can be specified in pixels or as a percentage of its parent container using the HTML width attribute.

Try It

wrap

The wrap attribute of HTML ref is used to wrap the text in a text area when submitted in a HTML form.

Try It

Global Attributes

全局属性对于所有 HTML 元素都是通用的,并且可以普遍使用。其中一些最重要的全局属性包括以下内容。

Global attributes are common to all HTML elements and can be used universally. Some of the most important global attributes include.

Attribute

Description

Example

accesskey

The accesskey is a global attribute that provides a hint for generating a keyboard shortcut for the current element.

Try It

class

The class is a global attribute that is used to specify the class name for the current element or tag.

Try It

contenteditable

The contenteditable attribute is an HTML global attribute that specifies or indicates whether or not the content present in the browser is editable by the user.

Try It

data-*

Used to store custom data associated with the element.

Try It

dir

The dir attribute is used to control the text direction in websites.

Try It

draggable

The draggable is an HTML global attribute that is used to specify whether an element is draggable or not.

Try It

hidden

The Hidden HTML Global attribute indicates that the content of an element should not be displayed to the user.

Try It

id

The id is an HTML global attribute that defines an identifier (id) that must be unique in the whole HTML document.

Try It

lang

The lang attribute is an HTML Global attribute that is used to define the language of an element’s content.

Try It

spellcheck

Several elements, including text input fields and contenteditable elements, can have the spellcheck global attribute applied to them in HTML.

Try It

style

A global attribute in HTML called style enables programmers to apply inline CSS styles to HTML elements.

Try It

tabindex

Specifies the tab order of an element.

Try It

title

A text to display in a tool tip.

Try It

translate

A global attribute called translate was created to facilitate the translation and internationalization of web content.

Try It