In HTML5, while many new elements are added and abolished, many attributes are also added and abolished.
New attributes
1. Form-related attributes
Specify the autofocus attribute for input (type=text), select, textarea, and button. It allows the element to automatically gain focus when the screen is opened by specifying attributes. Specify the placeholder attribute for input (type=text) and textarea, which will prompt the user for input and what content the user can input. Specify form attributes for input, output, select, textarea, button, and fieldset. It declares which form it belongs to and then places it anywhere on the page without losing sight of the form. Specify the required attribute for input (type=text) and textarea. This attribute indicates that the user will check when submitting, and check that there must be input content in the element. Add several new attributes to the input tag: autocomplete, min, max, multiple, pattern and step. There is also a list attribute used in conjunction with the datalist element; the datalist element is used in conjunction with the autocomplete attribute. The multiple attribute allows multiple files to be uploaded at one time during upload; the pattern attribute is used to verify the pattern of the input field, which is actually a regular expression. The step attribute specifies the legal number interval of the input field (if step="3", the legal numbers should be -3, 0, 3, 6, and so on). The step attribute can be used in conjunction with the max and min attributes to create legal range of values. Add formaction, formenctype, formmethod, formnovalidate and formtarget attributes to input and button elements. The user overrides the action, enctype, method, novalidate and target attributes of the form element. Add the disabled attribute to the fieldset element to set its child elements to the disabled state. Adding the novalidate attribute to input, button, and form can cancel the relevant checks performed during submission, and the form can be submitted unconditionally.2. Link related attributes
Add media attributes to a and area. Specifies the type of media/device the target URL is optimized for. This attribute is used to specify that the target URL is designed for a particular device (such as iPhone), voice or print media. This property can accept multiple values. Can only be used when the href attribute is present. Add herflang and rel attributes to area. The hreflang attribute specifies the language of the text in the linked document. This attribute can only be used when the href attribute is set. Note: This property is purely advisory. The rel attribute specifies the relationship between the current document and the linked document/resource. The rel attribute can only be used when using the href attribute. Add size attribute to link. The sizes attribute specifies the size of the linked resource. This attribute can only be used when the linked resource is an icon (rel="icon"). This property can accept multiple values. Values are separated by spaces. Adding the target attribute to the base element is mainly to maintain consistency with the a element.3. Other attributes
Add the reversed attribute to ol, which specifies that the list is displayed in reverse order. Add the charset attribute to meta and add type and label attributes to menu. label defines a courseware label for the menu, and the type attribute allows it to appear in three forms: context menu, toolbar, and list. Add scoped attribute to style. It allows us to define styles for specified parts of the document instead of the entire document. If the "scoped" attribute is used, the specified style can only be applied to the parent element of the style element and its children. Add or subtract attributes for script, which defines whether the script is executed asynchronously. The async attribute only works with external scripts (only when using the src attribute). There are several ways to execute external scripts: If async="async": the script executes asynchronously with respect to the rest of the page (while the page continues parsing, the script will be executed) If async is not used and defer="defer": the script will be executed when the page has finished parsing. If neither async nor defer is used: the script is read and executed immediately before the browser continues to parse the page as an html element. Add manifest, which is used in conjunction with the API when developing offline web applications to define a URL and describe the cache information of the document on this URL. Add attributes to iframe, sandbox, seamless, srcdoc. Used to improve page security and prevent untrusted web pages from performing certain operations.Abolished attributes
Some attributes in HTML4 are no longer used in HTML5, but are replaced by other attributes or other methods.
Attributes used in HTML 4 | Elements using this attribute | Alternatives in HTML 5 |
rev | link, a | rel |
charset | link, a | Use the HTTP Content-type header element in the linked resource |
shape, coords | a | Use area element instead of a element |
longdesc | img, iframe | Use the a element to link to the principal description |
target | link | Redundant attributes, omitted |
nohref | area | Redundant attributes, omitted |
profile | head | Redundant attributes, omitted |
version | html | Redundant attributes, omitted |
name | img | id |
scheme | meta | Use scheme only for certain form fields |
archive, chlassid, codebose, codetype, declare, standby | object | Use the data and typc attribute classes to call the plug-in. When you need to use these attributes to set parameters, use the param attribute |
valuetype, type | param | Use name and value attributes, do not declare the MIME type |
axis, abbr | td、th | Use a format that begins with clear, concise text, followed by detailed text.You can use the title attribute for more detailed content to make the cell content shorter |
scope | td | Use the HTTP Content-type header element in the linked resource |
align | caption, input, legend, div, h1, h2, h3, h4, h5, h6, p | Use CSS stylesheet instead |
alink, link, text, vlink, background, bgcolor | body | Use CSS stylesheet instead |
align, bgcolor, border, cellpadding, cellspacing, frame, rules, width | table | Use CSS stylesheet instead |
align, char, charoff, height, nowrap, valign | tbody, thead, tfoot | Use CSS stylesheet instead |
align, bgcolor, char, charoff, height, nowrap, valign, width | td、th | Use CSS stylesheet instead |
align, bgcolor, char, charoff, valign | tr | Use CSS stylesheet instead |
align, char, charoff, valign, width | col, colgroup | Use CSS stylesheet instead |
align, border, hspace, vspace | object | Use CSS stylesheet instead |
clear | br | Use CSS stylesheet instead |
compace, type | ol, ul, li | Use CSS stylesheet instead |
compace | dl | Use CSS stylesheet instead |
compace | menu | Use CSS stylesheet instead |
width | pre | Use CSS stylesheet instead |
align, hspace, vspace | img | Use CSS stylesheet instead |
align, noshade, size, width | hr | Use CSS stylesheet instead |
align, frameborder, scrolling, marginheight, marginwidth | iframe | Use CSS stylesheet instead |
autosubmit | menu |