Web Content Accessibility - Name - html

I'm just starting to learn about Web Content Accessibility and I was reading this document regarding non-text contents.
According to it:
For non-text content that is a control or accepts user input, such as
images used as submit buttons, image maps or complex animations, a
name is provided to describe the purpose of the non-text content so
that the person at least knows what the non-text content is and why it
is there.
So I double checked if what was meant here as name is the same as the HTML name attribute and found out that it isn't.
Near the bottom of the document here's what the definition of name is:
name
text by which software can identify a component within Web content to
the user
Note 1: The name may be hidden and only exposed by assistive
technology, whereas a label is presented to all users. In many (but
not all) cases, the label and the name are the same.
Note 2: This is unrelated to the name attribute in HTML.
So my question is how do I incorporate this name in my website if it's not the HTML attribute?

It depends on the control you are using. Some examples:
Input controls, textarea:
Use the label element with the for attribute, matching the id attribute of the element.
<label for="input1">My label</label><input type="text" id="input1" />
Buttons
If you use the button element include the description inside the content
<button>My label</button>
For input[type=submit], you can use the value attribute:
<input type="submit" value="My label" />
If you want to describe an image, use the alt attribute
Ex:
<img src="..." alt="My label" />

See my answer on If an HTML element has role="button" should it also have the attribute "name". Another person was asking about the "name" of an object and I clarified that the name of an object is not the name= property (that property is used for javascript) but rather is the label of the object that assistive technology will surface to the user. More details in my post.

The "name" attribute you mean is an attribute of the tag you are using in the web page. Example: Tag Button you can specify the name of the tag to facilitate user. Note 2 is telling you that HTML tag is unrelated to this attribute.

Related

Html accessibility - read another element's description

Hello any accessibility gurus,
I want to have this button element, when tabbed on, would trigger the screen read of an input element instead.
I tried pointing the aria-labelledby from the button to the input, to have the input's aria-label being read out. But the button still reads out its own description, when tabbed on.
<fieldset>
<input type="radio" id="inputid" aria-label="read me">
<button aria-labelledby="inputid">don't read me</button>
</fieldset>
Is there a way to read another element's content?
Thank you,
2022-12-06 Edit:
Following Andy's comment, the input element is only visually hidden, so it was moved offscreen with css left: -10000px.
I believe aria-labelledby is not used according to the standards, which might explain undefined behaviour.
The Accessible Name and Description, step C mentions the following:
If the embedded control has role textbox, return its value.
That means that if an <input>, which has implicit role textbox, is used as part of an accessible name, not its label, but its value is used as the name.
Further, the ARIA standard on aria-labelledby reads:
If the interface is such that it is not possible to have a visible label on the screen, authors SHOULD use aria-label […]
The main purpose of aria-labelleby is to refer to part of the visible contents of an element like a <form> to label it. Most commonly, this would be a heading like <h2>.
The use case of this question is currently unclear to me. The example provided does not make sense with a single radio input.
If the <input> is completely hidden, visually and from assistive technology, why is it there in the first place? <input type="hidden"> would be the more correct input to use if the form data is needed
If it’s only hidden visually, both the button and the input can be focussed, which is terribly confusing. Does the input appear on screen once it receives focus?

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" />
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

Accessibility: input with image - use value-, alt- or title-attribute?

I have the following input on a site I'm currently reviewing:
<input type="submit" name="executeSearch" value="" alt="Execute search" title="Execute search" class="iconButton searchBtn">
Through the class attribut the input button is replaced by an search icon.
According to accessibility is this the right way? Or should the value attribute be used? The screenreader I tested this element with (NVDA) was able to read the text ("Execute search button").
An empty value and an icon added via CSS to convey the only important information is a failure according to WCAG 2.0: F3 - Failure (…) due to using CSS to include images that convey important information
Simplest solution: use an input[type="image"], keep that alt="Execute search" ("Search" would be more concise IMHO), add an src="/path/to/img" of course and remove both title and value attributes. Image can be an SVG and can be encoded in base64 (ideal when it's light for performance reasons: that's 1 resource not to be downloaded).
That [type="image"] seems outdated because it was widely used circa IE6, way before RWD but it isn't (proof of concept with an 8x16 viewBox and width*height SVG: it scales®)
Otherwise you can use a button element with type="submit". This element can contain SVG, HTML images, text hidden to screen readers (better known as .visually-hidden, .sr-only or .element-invisible in Bootstrap, WordPress, Drupal, etc). That's what I use when a "submit" has both text and image or icon because no :pseudo with input and text-only through #value
Some notes on your current markup:
#alt should only be used with input[type="image"]
#value shouldn't be used with type image and otherwise should never be empty
#title should only be there (on links and "buttons") if it adds something to the existing information (like Subscribe ⇒ Subscribe to the newsletter or Edit ⇒ Edit something in particular)
According to accessibility is this the right way? Or should the value attribute be used?
An input[type='submit'] button does not accept an alt attribute
Some screenreaders may use the title attribute, but it's still useful for non screenreader users
Using the value attribute is the recommended approach for screenreader users

Difference between title and name in html href element

in an href in html, whats the difference between using
<a href="http://www.somesite.com/" name="The Name">
and
<a href="http://www.somesite.com/" title="The Name">
Is there any advantage to using one over the other?
Thanks
Look it up in the spec, or better yet a resource that condenses the spec a bit. (And, then the spec if that isn't enough.)
title text Specifies extra information about an element
http://www.w3schools.com/tags/tag_a.asp
The name attribute specifies the name
of an anchor.
The name attribute is used to create a
bookmark inside a document.
The href or the name attribute must be
present in the tag
http://www.w3schools.com/tags/att_a_name.asp
So, the name of the anchor is used for links like exampledomain.com/index.php#some_section, which would bring that anchor into focus on the page.
Many modern browsers will display the title attribute in a tooltip when hovering over the link. It's likely also useful for screen readers and such.
markup tag Node
- Name -- is to identify the element and for lookup
- title -- is default toolTip property. like ALT

Difference between id and name attributes in HTML

What is the difference between the id and name attributes? They both seem to serve the same purpose of providing an identifier.
I would like to know (specifically with regards to HTML forms) whether or not using both is necessary or encouraged for any reasons.
The name attribute is used when sending data in a form submission. Different controls respond differently. For example, you may have several radio buttons with different id attributes, but the same name. When submitted, there is just the one value in the response - the radio button you selected.
Of course, there's more to it than that, but it will definitely get you thinking in the right direction.
Use name attributes for form controls (such as <input> and <select>), as that's the identifier used in the POST or GET call that happens on form submission.
Use id attributes whenever you need to address a particular HTML element with CSS, JavaScript or a fragment identifier. It's possible to look up elements by name, too, but it's simpler and more reliable to look them up by ID.
Here is a brief summary:
id is used to identify the HTML element through the Document
Object Model (via JavaScript or styled with CSS). id is expected
to be unique within the page.
name corresponds to the form element and identifies what is posted
back to the server.
The way I think about it and use it is simple:
id is used for CSS and JavaScript/jQuery (it has to be unique on a page).
name is used for form handling on the server when a form is submitted via HTML (it has to be unique in a form - to some extent, see Paul's comment below).
See id= vs name=:
What’s the difference? The short answer is, use both and don’t worry about it. But if you want to understand this goofiness, here’s the skinny:
id= is for use as a target like this: <some-element id="XXX"></some-element> for links like this: <a href="#XXX".
name= is also used to label the fields in the message send to a server with an HTTP (HyperText Transfer Protocol) GET or POST when you hit submit in a form.
id= labels the fields for use by JavaScript and Java DOM (Document Object Model).
The names in name= must be unique within a form. The names in id= must be unique within the entire document.
Sometimes the name= and id= names will differ, because the server is expecting the same name from various forms in the same document or various radio buttons in the same form as in the example above. The id= must be unique; the name= must not be.
JavaScript needed unique names, but there were too many documents already out here without unique name= names, so the W3 people invented the id tag that was required to be unique. Unfortunately older browsers did not understand it. So you need both naming schemes in your forms.
Note: attribute "name" for some tags like <a> is not supported in HTML5.
The ID tag - used by CSS, define a unique instance of a div, span or other elements. Appears within the JavaScript DOM model, allowing you to access them with various function calls.
The Name tag for fields - this is unique per form -- unless you are doing an array which you want to pass to PHP/server-side processing. You can access it via JavaScript by name, but I think that it does not appear as a node in the DOM or some restrictions may apply (you cannot use .innerHTML, for example, if I recall correctly).
Generally, it is assumed that name is always superseded by id. This is true, to some extent, but not for form fields and frame names, practically speaking. For example, with form elements, the name attribute is used to determine the name-value pairs to be sent to a server-side program and should not be eliminated. Browsers do not use id in that manner. To be on the safe side, you could use the name and id attributes on form elements. So, we would write the following:
<form id="myForm" name="myForm">
<input type="text" id="userName" name="userName" />
</form>
To ensure compatibility, having matching name and id attribute values when both are defined is a good idea. However, be careful—some tags, particularly radio buttons, must have nonunique name values, but require unique id values.
Once again, this should reference that id is not simply a replacement for name; they are different in purpose. Furthermore, do not discount the old-style approach, a deep look at modern libraries shows such syntax style used for performance and ease purposes at times. Your goal should always be in favor of compatibility.
Now in most elements, the name attribute has been deprecated in favor of the more ubiquitous id attribute. However, in some cases, particularly form fields (<button>, <input>, <select>, and <textarea>), the name attribute lives on, because it continues to be required to set the name-value pair for form submission. Also, we find that some elements, notably frames and links, may continue to use the name attribute, because it is often useful for retrieving these elements by name.
There is a clear distinction between id and name. Very often when name continues on, we can set the values the same. However, id must be unique, and name in some cases shouldn’t—think radio buttons. Sadly, the uniqueness of id values, while caught by markup validation, is not as consistent as it should be. CSS implementation in browsers will style objects that share an id value; thus, we may not catch markup or style errors that could affect our JavaScript until runtime.
This is taken from the book JavaScript - The Complete Reference by Thomas-Powell.
<form action="demo_form.asp">
<label for="male">Male</label>
<input type="radio" name="sex" id="male" value="male"><br>
<label for="female">Female</label>
<input type="radio" name="sex" id="female" value="female"><br>
<input type="submit" value="Submit">
</form>
The forum thread below has answers to the same basic question, but basically, id is used for scripting identification and name is for server-side.
id vs. name attribute for HTML controls
name is deprecated for link targets, and invalid in HTML5. It no longer works at least in the latest Firefox (v13). Change <a name="hello"> to <a id="hello">.
The target does not need to be an <a> tag. It can be <p id="hello"> or <h2 id="hello">, etc. which is often cleaner code.
As other posts say clearly, name is still used (needed) in forms. It is also still used in META tags.
name vs. id
name
Name of the element. For example used by the server to identify the
fields in form submits.
Supporting elements are <button>, <form>, <fieldset>, <iframe>,
<input>, <keygen>, <object>, <output>, <select>, <textarea>, <map>,
<meta>, and <param>
Name does not have to be unique.
id
Often used with CSS to style a specific element. The value of this
attribute must be unique.
Id is a global attribute. Global attributes can be used on all elements, though the attributes may have no effect on some elements.
Must be unique in the whole document.
This attribute's value must not contain white spaces, in contrast to
the class attribute, which allows space-separated values.
Using characters except ASCII letters and digits, '_', '-' and '.'
may cause compatibility problems, as they weren't allowed in HTML 4.
Though this restriction has been lifted in HTML 5, an ID should start
with a letter for compatibility.
<body>
<form action="">
<label for="username">Username</label>
<input type="text" id="username" name="username">
<button>Submit!</button>
</form>
</body>
As we can see here, "id" and "for" elements are interconnected. If you click on the label (Username) then the input field will be highlighted (this is useful for mobile users and is considered as a good practice).
On the other hand, the "name" element is useful while submitting the form. Whatever you enter in the input field it will be displayed on the URL. Please see the attached image.
The ID of a form input element has nothing to do with the data contained within the element. IDs are for hooking the element with JavaScript and CSS. The name attribute, however, is used in the HTTP request sent by your browser to the server as a variable name associated with the data contained in the value attribute.
For instance:
<form>
<input type="text" name="user" value="bob">
<input type="password" name="password" value="abcd1234">
</form>
When the form is submitted, the form data will be included in the HTTP header like this:
If you add an ID attribute, it will not change anything in the HTTP header. It will just make it easier to hook it with CSS and JavaScript.
ID is used to uniquely identify an element.
Name is used in forms. Although you submit a form, if you don’t give any name, nothing will will be submitted. Hence form elements need a name to get identified by form methods like "get or push".
And only the ones with the name attribute will go out.
If you're not using the form's own submit method to send information to a server (and are instead doing it using JavaScript) you can use the name attribute to attach extra information to an input - rather like pairing it with a hidden input value, but it looks neater because it's incorporated into the input.
This bit does still currently work in Firefox although I suppose in the future it might not get allowed through.
You can have multiple input fields with the same name value, as long as you aren't planning to submit the old fashioned way.
Id:
It is used to identify the HTML element through the Document Object Model (DOM) (via JavaScript or styled with CSS).
Id is expected to be unique within the page.
Name corresponds to the form element and identifies what is posted back to the server.
Example:
<form action="action_page.php" id="Myform">
First name: <input type="text" name="FirstName"><br>
<input type="submit" value="Submit">
</form>
<p>The "Last name" field below is outside the form element, but still part of the form.</p>
Last name: <input type="text" name="LastName" form="Myform">
In all the time this question has been around, I am chagrined (and perhaps a bit saddened) that nobody has thought to mention accessibility which, though always important, has been steadily gaining support amongst both management and software engineers (just from my personal observations; no hard data to back that up).
One statistic I can provide is this (source):
So awareness of accessibility shortcomings show a steadily growing trend. The same reference mentions that, from those numbers, one can observe that at least one lawsuit is filed every hour!
So how does accessibility weigh in on name vs id?
According to the World Wide Web Consortium (W3C):
The for attribute of the label must exactly match the id of the
form control.
Based on personal experiences and according to the W3Schools description for attributes:
ID is a global attribute and applies to virtually all elements in HTML. It is used to uniquely identify elements on the Web page, and its value is mostly accessed from the frontend (typically through JavaScript or jQuery).
name is an attribute that is useful to specific elements (such as form elements, etc.) in HTML. Its value is mostly sent to the backend for processing.
HTML Attribute Reference
Below is an interesting use of the id attribute. It is used within the <form> tag and used to identify the form for <input> elements outside of the </form> boundaries so that they will be included with the other <input> fields within the form.
<form action="action_page.php" id="form1">
First name: <input type="text" name="fname"><br>
<input type="submit" value="Submit">
</form>
<p>The "Last name" field below is outside the form element, but still part of the form.</p>
Last name: <input type="text" name="lname" form="form1">
There is no literal difference between an id and name.
name is an identifier and is used in the HTTP request sent by the browser to serve as a variable name associated with data contained in the value attribute of the element.
The id on the other hand is a unique identifier for browser, client side and JavaScript. Hence the form needs an id while its elements need a name.
id is more specifically used in adding attributes to unique elements. In DOM methods, Id is used in JavaScript for referencing the specific element you want your action to take place on.
For example:
<html>
<body>
<h1 id="demo"></h1>
<script>
document.getElementById("demo").innerHTML = "Hello World!";
</script>
</body>
</html>
Same can be achieved by name attribute, but it's preferred to use id in a form and name for small form elements like the input tag or select tag.
Both name and id is targetable by # so not sure why ID was mentioned for this task exclusively.
I often Inspect those attributes to create specific links to bookmark (where clicking on header with mouse cursor to do the same is not provided for some reason) such as the Option File Inclusions
section of MySQL 5.6 4.2.2.2 Using Option Files documentation:
https://dev.mysql.com/doc/refman/5.6/en/option-files.html#option-file-inclusions
where it's defined as <a name="option-file-inclusions"></a> (with absolutely no forms involved).
I think, the name attribute is also older than id in HTML.
The id will give an element an id, so once you write real code, (like JavaScript) you can use the id to read elements. The name is just a name, so the user can see the name of the element, I guess.
Example:
<h1 id="heading">text</h1>
<script>
document.getElementById("heading"); // Reads the element that has the id "heading".
</script>
// You can also use something like this:
document.getElementById("heading").value; // Reads the value of the selected element.