1. Accept
The accept attribute in HTML forms is a powerful tool to refine the user experience when allowing file uploads. It is specifically designed for use with the <input> tag when its type attribute is set to "file".
When a user interacts with a file input field (often a button or clickable area that invokes the file selection dialog), the browser will typically display all files. However, if the developer knows in advance the type of files they want or need (for instance, only images or only documents), they can use the accept attribute to provide guidance to the browser.
<input type="file" name="pic" accept="image/png, image/jpeg">
This only allows users to choose .png or .jpeg files.
2. Autofocus
The autofocus attribute in HTML is an incredibly handy feature for enhancing user experience on web forms.
By incorporating this attribute, developers can guide users by automatically setting the focus on a specific input field, allowing users to start interacting with the form without needing to click on the desired input field manually.
<input type="text" name="username" autofocus>
When the page loads, the cursor will be automatically placed in this input field.
3. Input mode
The inputmode attribute in HTML plays a pivotal role in enhancing user experience, especially on mobile devices and touchscreens. When users engage with web forms on such devices, the type of on-screen keyboard that pops up can significantly impact the ease and speed of data entry.
By judiciously using the inputmode attribute, developers can present users with the most appropriate virtual keyboard for the expected input, streamlining and simplifying the data entry process.
<input type="text" inputmode="numeric">
On software keyboards (like those on mobile devices), this will prioritize showing a numeric keypad.
4. Download
The download attribute in HTML can greatly enhance user experience and offer clearer intentions on web pages where downloading resources is a key action.
When an <a> tag, which generally serves as a hyperlink, contains the download attribute, it signals to the browser that the linked resource should be downloaded upon clicking, rather than merely navigated to or displayed.
<a href="/path/to/file.jpg" download="picture.jpg">Download this picture</a>
Clicking the link will download the file and suggest "picture.jpg" as the default name.
5. Contenteditable
The contenteditable attribute in HTML introduces a unique and interactive aspect to web content by allowing users to make edits directly within the browser view.
This attribute transforms standard, static content into an editable region, akin to a text editor environment, without the need for additional input elements like text areas or input fields.
<div contenteditable="true">This is an editable div. Click here to edit.</div>
Users can click on the content inside the <div> and edit it directly.
6. Translate
In today's global digital landscape, websites often cater to diverse audiences from multiple regions and linguistic backgrounds. As a result, automated translation tools, such as browser plugins or integrated browser features, are frequently employed to translate web content on-the-fly. The translate attribute aids in ensuring that specific content is either translated appropriately or deliberately excluded from translation, providing a more accurate and context-aware translation experience.
<p translate="no">Do not translate this text.</p>
Translation tools should ideally skip this paragraph.