0% found this document useful (0 votes)
22 views2 pages

HTML Attributes Reference Guide

This document is a cheat sheet for HTML attributes, categorized into core, global, event, form, media, anchor, and boolean attributes. Each category lists specific attributes along with their functions, such as 'id' for unique identification and 'onclick' for click events. It serves as a quick reference for developers to understand and utilize various HTML attributes effectively.

Uploaded by

anandanjaligas
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

HTML Attributes Reference Guide

This document is a cheat sheet for HTML attributes, categorized into core, global, event, form, media, anchor, and boolean attributes. Each category lists specific attributes along with their functions, such as 'id' for unique identification and 'onclick' for click events. It serves as a quick reference for developers to understand and utilize various HTML attributes effectively.

Uploaded by

anandanjaligas
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

HTML Attributes Cheat Sheet

1. Core Attributes

- id: Specifies a unique ID for the element

- class: Specifies one or more class names for styling or scripting

- style: Specifies inline CSS styles

- title: Specifies extra information (tooltip)

2. Global Attributes

- accesskey: Specifies a keyboard shortcut

- contenteditable: Specifies if the content is editable

- data-*: Used to store custom data

- dir: Direction of the text ('ltr' or 'rtl')

- draggable: Specifies whether the element is draggable

- hidden: Hides the element

- lang: Specifies the language of the element

- spellcheck: Specifies if spell checking is allowed

- tabindex: Specifies the tab order of an element

- translate: Indicates whether the content should be translated

3. Event Attributes

- onclick: Triggered when element is clicked

- onmouseover: Triggered on mouse hover

- onchange: Triggered when form element value changes

- onkeydown: Triggered when a key is pressed

- onload: Triggered when the page or image loads

4. Form Attributes

- action: Defines where to send form-data

- method: HTTP method to use (GET or POST)

- type: Specifies type of input (text, email, etc.)

- name: Specifies the name of a form control


HTML Attributes Cheat Sheet

- value: Default value for the form control

- placeholder: Provides placeholder text

- required: Specifies that input must be filled out

- readonly: Makes the input field non-editable

- disabled: Disables the input element

5. Media Attributes

- src: Source file URL

- alt: Alternative text for image

- width/height: Specifies the size of media

- controls: Displays media controls

- autoplay: Media starts playing automatically

- loop: Plays media in a loop

- muted: Mutes the media

6. Anchor Attributes

- href: Specifies the URL

- target: Specifies where to open the link

- rel: Specifies the relationship between linked docs

- download: Forces download of linked resource

7. Boolean Attributes

- checked: Specifies that an element is pre-selected

- disabled: Specifies that an element is disabled

- readonly: Specifies that an element is read-only

- autofocus: Specifies that an element should get focus on page load

- required: Specifies that an element must be filled out

Common questions

Powered by AI

The 'draggable' attribute allows elements to be moved around using mouse or touch interactions. By setting this attribute, developers can enable a more interactive user experience where users can drag and drop items like files, images, or other elements to new locations or to upload areas within the webpage, thus enhancing the website's functionality and interactivity .

The 'readonly' attribute allows for data to be displayed while ensuring that users cannot alter the field's content, making it useful for displaying calculations or static data that should remain visible. On the other hand, the 'disabled' attribute prevents any interaction with the form element entirely, disabling any ability for user input or participation. This differentiation is crucial for ensuring correct data input workflows and preserving user experience consistency across forms .

The 'onchange' attribute triggers an event when a form element loses focus and its value has been changed, allowing for actions like validation or live updating of related fields. Conversely, 'onclick' is triggered immediately when an element is clicked, offering immediate feedback or actions, often used for buttons or links. The two attributes serve different user interaction contexts: 'onchange' is more suitable for data input fields, while 'onclick' is typical for discrete user actions .

Improper use of the 'hidden' attribute can lead to content being inaccessible to users who rely on screen readers, as these elements are completely ignored in the accessibility tree. This could prevent users from accessing critical information necessary for interacting with the webpage. Careful consideration must be given when using 'hidden' to ensure that no accessible content or navigation is inadvertently removed or made unavailable to assistive technologies .

The 'class' attribute allows an element to be styled using CSS by linking it to one or more stylesheets through class selectors. It is useful for applying the same style to multiple elements. Conversely, the 'id' attribute provides a unique identifier to an element, enabling both precise style application and element-specific scripting with JavaScript. Unlike 'class', the 'id' attribute must be unique within a document .

The 'autoplay' attribute makes a media file play automatically as soon as enough of it has been loaded, without any user interaction. In contrast, the 'loop' attribute plays the media file repeatedly in a continuous cycle. While 'autoplay' impacts the start of media upon loading, 'loop' affects its end, leading to unlimited repetition unless interrupted .

Using 'lang' alongside 'spellcheck' attributes, provides an enhanced text entry experience by setting the correct linguistic context and enabling spell check only when appropriate. This combination ensures that the input is evaluated using the correct language rules, thus avoiding unnecessary corrections in multilingual contexts and optimizing the efficiency of content creation features such as typing in different languages on a single page .

The 'accesskey' attribute provides shortcuts that improve accessibility by allowing users to navigate more quickly through web content using keyboard keys, significantly aiding users who cannot use a mouse. The 'tabindex' attribute orders the focus of elements via keyboard navigation, enhancing accessibility by determining the logical flow of focus, which optimizes navigation for keyboard users and screen readers .

Global attributes like 'lang' and 'dir' allow developers to specify the language of an HTML element and the direction of text, respectively. This facilitates internationalization by making sure text is properly displayed and read by screen readers and other tools in different languages. The 'translate' attribute lets the browser know whether content should be translated, enhancing usability for non-native speakers by providing instant contextual translation feedback .

The 'download' attribute is useful when the intention is to have users save a file from a webpage, such as downloading software, images, or documents. It forces the browser to download the linked resource rather than navigating to it, ensuring that the file is saved to the user's device for offline access or later use .

You might also like