Search code examples
htmlplaceholderarea

what is the difference between placeholder and aria-placeholder in html5?


please , I need to know difference between area-placeholder and placeholder ? when area-placeholder will appear in input field

<input  type="search" placeholder="Search"  aria-placeholder="Search2" />

Solution

  • edit (added a deeper explanation)

    ARIA labels are used to express semantics that HTML can't express on its own, i.e bridging areas with accessibility issues that can't be managed with native HTML. It works by allowing you to specify attributes that modify the way an element is translated into the accessibility tree.

    for example, let's use a list item as a custom checkbox (the CSS class 'checkbox' gives the element the required visual characteristics.

    <li tabindex="0" class="checkbox" checked>
      Receive promotional offers
    </li>
    

    for sighted users, this will work fine, but a screen reader won't give an indication that this element is a checkbox, so users with low vision might miss this element.

    using ARIA will give the element the missing information for the screen reader to properly interpret it.

    there are many ARIA attributes, and if you plan on using them (you should!) i recommended reading more here


    Aria-label allows us to specify a string to be used as the accessible label. This overrides any other native labeling mechanism, such as a label element — for example, if a button has both text content and an aria-label, only the aria-label value will be used.

    A placeholder is a text that appears in the form control when it has no value set. The HTML placeholder attribute enables providing a sample value or a brief description of the expected format for several HTML types and .

    If you are creating a textbox using any other element, the placeholder is not supported. That is where aria-placeholder comes into play. The aria-placeholder attribute can be used to define a short hint to help the user understand what type of data is expected when a non-semantic form control has no value.

        <p id="date-of-birth">Birthday</span>
        <div contenteditable role="textbox" aria-labelledby="date-of-birth" 
         aria-placeholder="MM-DD-YYYY">MM-DD-YYYY</div>
    

    The placeholder hint should be shown to the user whenever the control's value is empty, including when a value is deleted.

    The aria-placeholder is used , in addition, to, not instead of, a label. They have different purposes and different functionality. A label explains what kind of information is expected. Placeholder text provides a hint about the expected value.

    ARIA is only modifying the accessibility tree for an element and therefore how assistive technology presents the content to your users. ARIA doesn't change anything about the function or behavior of an element. When not using semantic HTML elements for their intended purpose and default functionality, you must use JavaScript to manage behavior.

    for a more detailed explanation, you can visit the aria-label page on Mozilla