Home Web Front-end H5 Tutorial What are the attributes of HTML5 forms?

What are the attributes of HTML5 forms?

Aug 13, 2018 pm 07:23 PM

If you want to see a detailed explanation of the elements of the form, please see the detailed explanation of the HTML5 form elements here

The above mentioned elements of the form, now let us take a look at some new attributes

Click the link you haven’t seen yet: Detailed explanation of HTML5 form elements

The new form attributes of HTML5 are mainly in two aspects: the new attributes of the

element.

HTML5 form attributes

New form attributes:

  • autocomplete

  • novalidate

New input attribute:

  • autocomplete

  • autofocus

  • ##form

  • form overrides (formaction, formenctype, formmethod, formnovalidate, formtarget)

  • height and width

  • list

  • min,max and step

  • multiple

  • pattern(regexp)

  • placeholder

  • required

autocomplete attribute

The autocomplete attribute specifies that the form or input field should have auto-complete functionality.

Note: autocomplete applies to tags, and the following types of tags: text, search, url, telephone, email, password, datepickers, range and color.

When the user starts typing in the autocomplete field, the browser should display the options to complete in that field:

<form action="demo_form.asp" method="get" autocomplete="on">
First name: <input type="text" name="fname" /><br />
Last name: <input type="text" name="lname" /><br />
E-mail: <input type="email" name="email" autocomplete="off" /><br />
<input type="submit" />
</form>
Copy after login

Note: In some browsers, you may need to enable autocomplete Complete the function to enable this property.

autofocus attribute

The autofocus attribute specifies that the field automatically gains focus when the page loads.

Note: The autofocus attribute applies to all tag types.

User name: <input type="text" name="user_name"  autofocus="autofocus" />
Copy after login

form attribute

The form attribute specifies one or more forms to which the input field belongs.

Note: The form attribute applies to all tag types.

The form attribute must reference the id of the form it belongs to:

<form action="demo_form.asp" method="get" id="user_form">
First name:<input type="text" name="fname" />
<input type="submit" />
</form>
Last name: <input type="text" name="lname" form="user_form" />
Copy after login

Note: If you need to reference more than one form, please use a space-separated list.

Form override attributes

Form override attributes allow you to override certain attribute settings of the form element.

The form rewrite attributes are:

formaction - rewrite the action attribute of the form

formenctype - rewrite the enctype attribute of the form

formmethod - rewrite The method attribute of the form

formnovalidate - Rewrite the novalidate attribute of the form

formtarget -Rewrite the target attribute of the form

Note: The form rewrite attribute is applicable to the following types of< ;input> Tags: submit and image.

<form action="demo_form.asp" method="get" id="user_form">
E-mail: <input type="email" name="userid" /><br />
<input type="submit" value="Submit" />
<br />
<input type="submit" formaction="demo_admin.asp" value="Submit as admin" />
<br />
<input type="submit" formnovalidate="true" value="Submit without validation" />
<br />
</form>
Copy after login

Note: These properties are helpful for creating different submit buttons.

height and width attributes

The height and width attributes specify the image height and width used for input tags of type image.

Note: The height and width attributes are only applicable to tags of image type.

<input type="image" src="img_submit.gif" width="99" height="99" />
Copy after login

list attribute

list attribute specifies the datalist of the input field. datalist is a list of options for the input field.

Note: The list attribute is applicable to the following types of tags: text, search, url, telephone, email, date pickers, number, range and color.

Webpage: <input type="url" list="url_list" name="link" />
<datalist id="url_list">
<option label="W3Schools" value="http://www.w3school.com.cn" />
<option label="Google" value="http://www.google.com" />
<option label="Microsoft" value="http://www.microsoft.com" />
</datalist>
Copy after login

min, max, and step attributes

The min, max, and step attributes are used to specify limits (constraints) for input types that contain numbers or dates.

The max attribute specifies the maximum value allowed for the input field.

The min attribute specifies the minimum value allowed for the input field.

The step attribute specifies the legal number intervals for the input field (if step="3", the legal numbers are -3,0,3,6, etc.).

Note: The min, max, and step attributes apply to the following types of tags: date pickers, number, and range.

The following example shows a numeric field that accepts values ​​between 0 and 10 in steps of 3 (that is, legal values ​​are 0, 3, 6, and 9):

Points: <input type="number" name="points" min="0" max="10" step="3" />
Copy after login

multiple attribute

The multiple attribute specifies that multiple values ​​can be selected in the input field.

Note: The multiple attribute applies to the following types of tags: email and file.

Select images: <input type="file" name="img" multiple="multiple" />
Copy after login

novalidate attribute

The novalidate attribute specifies that form or input fields should not be validated when submitting the form.

Note: The novalidate attribute is applicable to and the following types of tags: text, search, url, telephone, email, password, date pickers, range and color.

<form action="demo_form.asp" method="get" novalidate="true">
E-mail: <input type="email" name="user_email" />
<input type="submit" />
</form>
Copy after login

pattern attribute

The pattern attribute specifies the pattern (pattern) used to verify the input field.

Pattern is a regular expression. You can learn about regular expressions in our JavaScript tutorial.

Note: The pattern attribute applies to the following types of tags: text, search, url, telephone, email and password.

The following example shows a text field that can only contain three letters (excluding numbers and special characters):

Country code: <input type="text" name="country_code"
pattern="[A-z]{3}" title="Three letter country code" />
Copy after login

placeholder attribute

placeholder 属性提供一种提示(hint),描述输入域所期待的值。

注:placeholder 属性适用于以下类型的 标签:text, search, url, telephone, email 以及 password。

提示(hint)会在输入域为空时显示出现,会在输入域获得焦点时消失:

<input type="search" name="user_search"  placeholder="Search php" />
Copy after login

required 属性

required 属性规定必须在提交之前填写输入域(不能为空)。

注:required 属性适用于以下类型的 标签:text, search, url, telephone, email, password, date pickers, number, checkbox, radio 以及 file。

Name: <input type="text" name="usr_name" required="required" />
Copy after login

【相关推荐】

html的基础元素,让你零基础学习HTML

HTML和HTML5的发展历史


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

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run the h5 project How to run the h5 project Apr 06, 2025 pm 12:21 PM

Running the H5 project requires the following steps: installing necessary tools such as web server, Node.js, development tools, etc. Build a development environment, create project folders, initialize projects, and write code. Start the development server and run the command using the command line. Preview the project in your browser and enter the development server URL. Publish projects, optimize code, deploy projects, and set up web server configuration.

What exactly does H5 page production mean? What exactly does H5 page production mean? Apr 06, 2025 am 07:18 AM

H5 page production refers to the creation of cross-platform compatible web pages using technologies such as HTML5, CSS3 and JavaScript. Its core lies in the browser's parsing code, rendering structure, style and interactive functions. Common technologies include animation effects, responsive design, and data interaction. To avoid errors, developers should be debugged; performance optimization and best practices include image format optimization, request reduction and code specifications, etc. to improve loading speed and code quality.

How to make h5 click icon How to make h5 click icon Apr 06, 2025 pm 12:15 PM

The steps to create an H5 click icon include: preparing a square source image in the image editing software. Add interactivity in the H5 editor and set the click event. Create a hotspot that covers the entire icon. Set the action of click events, such as jumping to the page or triggering animation. Export H5 documents as HTML, CSS, and JavaScript files. Deploy the exported files to a website or other platform.

What application scenarios are suitable for H5 page production What application scenarios are suitable for H5 page production Apr 05, 2025 pm 11:36 PM

H5 (HTML5) is suitable for lightweight applications, such as marketing campaign pages, product display pages and corporate promotion micro-websites. Its advantages lie in cross-platformity and rich interactivity, but its limitations lie in complex interactions and animations, local resource access and offline capabilities.

Is H5 page production a front-end development? Is H5 page production a front-end development? Apr 05, 2025 pm 11:42 PM

Yes, H5 page production is an important implementation method for front-end development, involving core technologies such as HTML, CSS and JavaScript. Developers build dynamic and powerful H5 pages by cleverly combining these technologies, such as using the &lt;canvas&gt; tag to draw graphics or using JavaScript to control interaction behavior.

What is the H5 programming language? What is the H5 programming language? Apr 03, 2025 am 12:16 AM

H5 is not a standalone programming language, but a collection of HTML5, CSS3 and JavaScript for building modern web applications. 1. HTML5 defines the web page structure and content, and provides new tags and APIs. 2. CSS3 controls style and layout, and introduces new features such as animation. 3. JavaScript implements dynamic interaction and enhances functions through DOM operations and asynchronous requests.

What Does H5 Refer To? Exploring the Context What Does H5 Refer To? Exploring the Context Apr 12, 2025 am 12:03 AM

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

How to make pop-up windows with h5 How to make pop-up windows with h5 Apr 06, 2025 pm 12:12 PM

H5 pop-up window creation steps: 1. Determine the triggering method (click, time, exit, scroll); 2. Design content (title, text, action button); 3. Set style (size, color, font, background); 4. Implement code (HTML, CSS, JavaScript); 5. Test and deployment.

See all articles